Open roman-vanesyan opened 3 years ago
I think this seems like a reasonable thing to add.
Basically you want to change the signature to onAfterBuild(schema): GraphQLSchema | void
, where if a new schema is returned, it's used?
So:
onAfterBuildFns.forEach((fn) => fn(schema))
return { schema, missingTypes, finalConfig }
becomes:
let finalSchema = schema
onAfterBuildFns.forEach((fn) => {
finalSchema = fn(finalSchema) ?? finalSchema
})
return { schema: finalSchema, missingTypes, finalConfig }
Want to open a PR?
As far as I understand it isn't possible to update/apply middlewares to generate schema right in the plugin.
To better cover the requested feature I'd like to provide a small example: I'd like to use
graphql-shield
package to add authorization logic to my GraphQL layer and I'd like to definegraphql-shield
rules right in themutationField
andqueryField
calls under theshield
field, for instance:The primary use of
graphql-shield
as middleware applied bygraphql-middleware
package (to better understand howgraphql-shield
is working please checkout official doc page: https://www.graphql-shield.com/docs). So normally to applygraphql-shield
to schema we need to do:So as it can be seen because
graphql-shield
applies middleware to the schema I need to somehow to apply it to the generated schema bynexus
and taking into the account that I'd like to defineshield
permissions right on the nexus schema definition I need a way to apply modifications in the plugin to the final schema. So imagineonAfterBuild
plugin hook would allow us to provide a custom schema, then something like this would be possible:As it already been said, I propose to add ability to
onAfterBuild
plugin hook to return a new modified schema.