Client side mocking library for GraphQL.
Using the Rick and Morty GraphQL API for example purposes.
npx apollo client:download-schema schema.json --endpoint=https://rickandmortyapi.com/graphql
Combine information from the GraphQL schema introspection query result and a provided GraphQL AST (a graphql-tag query) to automatically generate response mocks. i.e.
import * as schema from "./schema.json";
const QUERY = gql`
query {
characters {
results {
id
name
}
}
}
`;
Mimic.config({ schema });
const mock = Mimic.mock(QUERY);
// {
// data: {
// characters: {
// results: [
// {
// id: "1",
// name: "lorem ipsum"
// },
// {
// id: "2",
// name: "lorem ipsum"
// }
// ];
// }
// }
// }
GraphQL-Mimic will generate a mock where each field is assigned a default value. Default values are assigned according to the field scalar type as follows:
- Int: 1
- Float: 1.0
- String: "lorem ipsum"
- Boolean: false
- ID: "1" or "2"
Notice that the ID scalar type could be assigned with a value of "1" or "2" because by default every list in the mocked response will contain 2 items.
graphql-mimic is intended to be client agnostic, but we plan to provide "adapters" to make it easy to work with common GraphQL clients like Apollo Client.