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
// define the graphql query | |
const UserQueryDefs = gql` | |
extend type Query { | |
user(id: ID): User | |
} | |
`; | |
// graphql resolver | |
async user(_, args, context): Promise<any> { | |
// return the requested user |
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
const server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
context: graphQLContext | |
}); | |
const graphQLContext = (context) => { | |
const { req, res } = context; | |
// use a express middleware to auth user |
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
const server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
context: graphQLContext, | |
formatError: (error: any) => { | |
// filter whatever errors your don't want to log | |
logger.error(`[GraphQL.error] ${error.message}`, error); | |
return error; | |
}, | |
formatResponse: (response: any) => { |
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
### Keybase proof | |
I hereby claim: | |
* I am timjbray on github. | |
* I am timjbray (https://keybase.io/timjbray) on keybase. | |
* I have a public key ASCcehdRyHuWsfY3BCZLtORi2gsDSs9O8S48Ffbc_ehnPAo | |
To claim this, I am signing this object: |