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

feat: allow after build hook to modify the schema #1072

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hemache
Copy link

@hemache hemache commented Apr 8, 2022

related to #959

usage example:

import { applyMiddleware } from 'graphql-middleware'
import { yupMiddleware as YupMiddleware } from 'graphql-yup-middleware'
...

const yupMiddleware = YupMiddleware()

export const middlewarePlugin = (): NexusPlugin => {
  return plugin({
    name: "MiddlewaresPlugin",
    onAfterBuild(schema) {
      const { schema: ret } = applyMiddleware(schema, yupMiddleware)
      return ret
    },
  })
}

const schema = makeSchema({
  ...
  plugins: [middlewarePlugin()],
})

@tgriesser
Copy link
Member

Interesting change, seems reasonable, mind adding a test to cover it?

@tgriesser
Copy link
Member

Actually, I think we want to add a new hook here, onBeforeSchemaBuild which takes the config that will be passed to new GraphQLSchema, and can modify that, which is better than needing to build a whole new schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants