Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcoedo/c55805706e925e4170aa2d03c190726b to your computer and use it in GitHub Desktop.
Save rcoedo/c55805706e925e4170aa2d03c190726b to your computer and use it in GitHub Desktop.
This gist contains the examples for the article "Mocking your GraphQL Server is Easier with gql-mock-server".
- https://medium.com/trabe/mocking-your-graphql-server-is-easier-with-gql-mock-server-9d72ce07a657
- https://rcoedo.com/blog/2018/01/22/mocking-your-graphql-server-is-easier-with-gql-mock-server
import gql from "gql-mock-server";
// const types = ...
// const resolvers = ...
gql(
{ types, resolvers },
{
context: req => ({
user: req.headers.authorization === "Bearer VALID_TOKEN"
? { username: "john@doe.com" }
: null
}),
port: 5000,
endpoint: "/gql"
}
);
import gql from "gql-mock-server";
gql({
types: `
type User {
id: ID
name: String
}
type Query {
users: [User]
}
`,
resolvers: {
Query: {
users: () => [{ id: "1", name: "Peter" }, { id: "2", name: "Frank" }]
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment