Skip to content

Instantly share code, notes, and snippets.

@helfer
Last active September 26, 2017 05:58
Show Gist options
  • Save helfer/fa8a5788845366d5052f8677d6338bae to your computer and use it in GitHub Desktop.
Save helfer/fa8a5788845366d5052f8677d6338bae to your computer and use it in GitHub Desktop.
// customize mocking per type (i.e. Integer, Float, String)
mockServer(schema, {
Int: () => 6,
Float: () => 22.1,
String: () => 'Hello',
});
// customize mocking per field in the schema (i.e. for Person.name and Person.age)
mockServer(schema, {
Person: () => ({
name: casual.name,
age: () => casual.integer(0,120),
})
});
// mock lists of specific or random length( and lists of lists of lists …)
mockServer(schema, {
Person: () => {
// a list of length between 2 and 6
friends: () => new MockList([2,6]),
// a list of three lists of two items: [[1, 1], [2, 2], [3, 3]]
listOfLists: () => new MockList(3, () => new MockList(2)),
},
});
// customize mocking of a field or type based on the query arguments
mockServer(schema, {
Person: () => {
// the number of friends in the list now depends on numPages
paginatedFriends: (o, { numPages }) => new MockList(numPages * PAGE_SIZE),
},
});
// You can also disable mocking for specific fields, pass through to the backend, etc.
@xgqfrms-GitHub
Copy link

not too bad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment