Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // customize mocking per type (i.e. Integer, Float, String)
  2. mockServer(schema, {
  3. Int: () => 6,
  4. Float: () => 22.1,
  5. String: () => 'Hello',
  6. });
  7.  
  8. // customize mocking per field in the schema (i.e. for Person.name and Person.age)
  9. mockServer(schema, {
  10. Person: () => ({
  11. name: casual.name,
  12. age: () => casual.integer(0,120),
  13. })
  14. });
  15.  
  16. // mock lists of specific or random length( and lists of lists of lists …)
  17. mockServer(schema, {
  18. Person: () => {
  19. // a list of length between 2 and 6
  20. friends: () => new MockList([2,6]),
  21. // a list of three lists of two items: [[1, 1], [2, 2], [3, 3]]
  22. listOfLists: () => new MockList(3, () => new MockList(2)),
  23. },
  24. });
  25.  
  26. // customize mocking of a field or type based on the query arguments
  27. mockServer(schema, {
  28. Person: () => {
  29. // the number of friends in the list now depends on numPages
  30. paginatedFriends: (o, { numPages }) => new MockList(numPages * PAGE_SIZE),
  31. },
  32. });
  33.  
  34. // You can also disable mocking for specific fields, pass through to the backend, etc.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement