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

Add validation rule for disabling introspection #2597

Closed
danielrearden opened this issue May 31, 2020 · 0 comments
Closed

Add validation rule for disabling introspection #2597

danielrearden opened this issue May 31, 2020 · 0 comments
Assignees
Labels
PR: feature 🚀 requires increase of "minor" version number

Comments

@danielrearden
Copy link
Contributor

It would be helpful if the library included a validation rule that would throw when an introspection field is requested. Something like what Apollo Server already uses:

const NoIntrospection = (context: ValidationContext) => ({
  Field(node: FieldDefinitionNode) {
    if (node.name.value === '__schema' || node.name.value === '__type') {
      context.reportError(
        new GraphQLError(
          'GraphQL introspection is not allowed by Apollo Server, but the query contained __schema or __type. To enable introspection, pass introspection: true to ApolloServer in production',
          [node],
        ),
      );
    }
  },
});

The validation rule could then be optionally added when using libraries like express-graphql to effectively disable introspection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature 🚀 requires increase of "minor" version number
Projects
None yet
Development

No branches or pull requests

2 participants