Closed
Description
Story
As a user migrating from express-graphql
, I want to pass a rootValue
resolver. With express-graphql
, I was able to do the following:
app.get('/graphql', graphqlHTTP((req, res) => ({
schema,
rootValue: resolvers
})))
Ideally, I would like to set rootValue
as an option of createHandler
app.use(
'/graphql',
createHandler({ schema, rootValue }),
)
Acceptance criteria
- user is able to configure a
rootValue
without overriding the wholeExecutionContext
withonSubscribe
- user can find documentation on how to configure a
rootValue
Note
Maybe using a rootValue
is not recommended anymore? Maybe there's an alternative? For reference, here's how I declare my schema/resolvers:
module.exports = {
/**
* Create an article.
*/
articles: async (args, { req }) => {
// ...
}
/**
* Delete an article.
*/
deleteArticle: async (args, { req }) => {
// ...
},
}
const gql = require('graphql-tag')
const { buildASTSchema } = require('graphql')
module.exports = buildASTSchema(gql`
type Article {
_id: ID!
title: String
content: String
createdAt: String
updatedAt: String
}
type RootQuery {
articles (user: ID): [Article!]!
}
type RootMutation {
deleteArticle(article: ID!): Article!
}
schema {
query: RootQuery
mutation: RootMutation
}
`)