We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Progress of the issue based on the Contributor Workflow
Make sure to fork this template and run yarn generate in the terminal. Please make sure the GraphQL Tools package versions under package.json matches yours.
Make sure to fork this template and run yarn generate in the terminal.
yarn generate
Please make sure the GraphQL Tools package versions under package.json matches yours.
package.json
Describe the bug
I'm using this tool to filter queries/mutations based on the existence of a custom directive. The code is simply
const { readFileSync, writeFileSync } = require("fs"); const { buildSchema, printSchema } = require("graphql"); const { mapSchema, getDirective, MapperKind } = require("@graphql-tools/utils"); const config = require("./config.json"); const toFilter = new Set(["Query", "Mutation"]); function filterSchemaByDirective(schema, directiveName) { return mapSchema(schema, { [MapperKind.OBJECT_FIELD]: (fieldConfig, _fieldName, typeName, schema) => { if (!toFilter.has(typeName)) { return fieldConfig; } const directive = getDirective(schema, fieldConfig, directiveName); if (directive) { console.log(JSON.stringify(fieldConfig)); return fieldConfig; } return null; }, }); } function filterFile(input, output, directive) { const schemaFileContent = readFileSync(input, "utf-8"); const newSchema = filterSchemaByDirective(buildSchema(schemaFileContent), directive); writeFileSync(output, printSchema(newSchema)); } if (require.main === module) { filterFile("transform/hello.graphql", "transform/out.graphql", "expose"); }
And if I feed this in to that code
directive @expose( reason: String = "hello" ) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION input SpectaQLOption { key: String!, value: String! } directive @spectaql(options: [SpectaQLOption]) on QUERY | MUTATION | FIELD | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION schema { query: Query } type Query { ping: Status! getList: [String!] @expose @spectaql(options: [{ key: "some", value: "value" }]) getListError: [String!] @expose @deprecated introspection: String error: String withExtensions: String @spectaql(options: [{ key: "undocumented", value: "true" }]) iBlowUp: String } type Status { pong: String! }
The custom directives expose and spectaql are just dropped:
directive @expose(reason: String = "hello") on FIELD_DEFINITION | INPUT_FIELD_DEFINITION directive @spectaql(options: [SpectaQLOption]) on QUERY | MUTATION | FIELD | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION input SpectaQLOption { key: String! value: String! } type Query { getList: [String!] getListError: [String!] @deprecated } type Status { pong: String! }
I can see these directives are still in fieldConfig before I return it so I really don't get why they are dropped.
fieldConfig
Expected behavior
I should still see the custom directives.
Environment:
@graphql-tools/utils:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Issue workflow progress
Progress of the issue based on the
Contributor Workflow
Describe the bug
I'm using this tool to filter queries/mutations based on the existence of a custom directive.
The code is simply
And if I feed this in to that code
The custom directives expose and spectaql are just dropped:
I can see these directives are still in
fieldConfig
before I return it so I really don't get why they are dropped.Expected behavior
I should still see the custom directives.
Environment:
@graphql-tools/utils:
^10.0.0"The text was updated successfully, but these errors were encountered: