Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure the rootValue #30

Closed
ggrossetie opened this issue Dec 6, 2022 · 2 comments
Closed

Allow to configure the rootValue #30

ggrossetie opened this issue Dec 6, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request released Has been released and published

Comments

@ggrossetie
Copy link

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 whole ExecutionContext with onSubscribe
  • 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
  }
`)
@enisdenjo
Copy link
Member

This makes sense! Thank you for opening an issue, I will tackle this rather soon.

@enisdenjo enisdenjo self-assigned this Dec 16, 2022
@enisdenjo enisdenjo added the enhancement New feature or request label Dec 16, 2022
enisdenjo pushed a commit that referenced this issue Dec 24, 2022
# [1.10.0](v1.9.0...v1.10.0) (2022-12-24)

### Features

* **handler:** Accept a GraphQL execution rootValue ([0f04fa2](0f04fa2)), closes [#30](#30)
@enisdenjo
Copy link
Member

🎉 This issue has been resolved in version 1.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@enisdenjo enisdenjo added the released Has been released and published label Dec 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released Has been released and published
Projects
None yet
Development

No branches or pull requests

2 participants