Created
June 14, 2018 14:49
-
-
Save dhavaln/dbfc97a85cc00aab411f877d2cd41cb5 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
// 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