You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 define graphql-shield rules right in the mutationField and queryField calls under the shield field, for instance:
The primary use of graphql-shield as middleware applied by graphql-middleware package (to better understand how graphql-shield is working please checkout official doc page: https://www.graphql-shield.com/docs). So normally to apply graphql-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 by nexus and taking into the account that I'd like to define shield permissions right on the nexus schema definition I need a way to apply modifications in the plugin to the final schema. So imagine onAfterBuild plugin hook would allow us to provide a custom schema, then something like this would be possible:
exportconstshieldPlugin=(): NexusPlugin=>{letrules;returnplugin({name: "ShieldPlugin",description: "Add support for graphql-shield.",
fieldDefTypes,onBeforeBuild(){rules=Object.create(null);},onAddOutputField(field){if(!(field.parentTypeinrules)){rules[field.parentType]={};}if(!isNil(field.shield)){rules[field.parentType][field.name]=field.shield;}},onAfterBuild(schema){const{schema: ret}=applyMiddleware(schema,shield(rules));returnret;},});};
As it already been said, I propose to add ability to onAfterBuild plugin hook to return a new modified schema.
The text was updated successfully, but these errors were encountered:
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.The text was updated successfully, but these errors were encountered: