Created
August 13, 2022 15:31
-
-
Save rcoedo/c55805706e925e4170aa2d03c190726b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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