Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Created June 14, 2018 14:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dhavaln/dbfc97a85cc00aab411f877d2cd41cb5 to your computer and use it in GitHub Desktop.
// Resolver to match the GraphQL query and return data
const resolvers = {
Query: {
blogs(root, args, context, info) {
context.requestCount++;
console.log(`Request Time ${context.requestTime}, Total Requests: ${context.requestCount}`);
return blogsData
},
blog(root, {_id}, context, info){
context.requestCount++;
console.log(`Request Time ${context.requestTime}, Total Requests: ${context.requestCount}`);
return blogsData.find((b) => b._id == _id);
}
}
};
// Build the schema with Type Definitions and Resolvers
const schema = graphqlTools.makeExecutableSchema({typeDefs, resolvers});
app.use('/graphiql', graphql({
graphiql: true,
schema,
context: {
requestTime: Date.now(),
requestCount: 0
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment