-
I am using graphql-codegen package to generate mongo-db models from my graphql schema. For the codegen tool to make its work I need to add db specific directives to my schema(like @entity and @column). After the codgen tool is done with its task I don't need the db-related directive to be present in the schema. So I need to delete them before starting my graphql service. I have figured out how to remove the directives on type fields using schemaWrap function and FilterObjectFieldDirectives transformer. But this, as one could expect, removes only field directives. But In addition to fields, codegen tool also requires me to add @entity directive on the types themselves. Can someone please |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You don’t want to wrap the schema, as this creates an unnecessary layer of delegation. You want to modify all ast nodes to no longer have the directives. You could do this with mapSchema and write your own mapping functions with MapperKind.XXX mapping functions to modify the node.astNode and node.extensionASTNode. Another, perhaps simpler option is to take advantage of the fact that graphql-js printSchema function does not emit directives... so you can just print the schema and recreate it sans directives. |
Beta Was this translation helpful? Give feedback.
You don’t want to wrap the schema, as this creates an unnecessary layer of delegation. You want to modify all ast nodes to no longer have the directives. You could do this with mapSchema and write your own mapping functions with MapperKind.XXX mapping functions to modify the node.astNode and node.extensionASTNode. Another, perhaps simpler option is to take advantage of the fact that graphql-js printSchema function does not emit directives... so you can just print the schema and recreate it sans directives.