Skip to content

Allow to validate a full schema #4415

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

Open
martinbonnin opened this issue May 28, 2025 · 0 comments
Open

Allow to validate a full schema #4415

martinbonnin opened this issue May 28, 2025 · 0 comments

Comments

@martinbonnin
Copy link

GraphQL JS has a function to validate a user schema, validateSchema().

This works well if the schema is a user schema not containing any of the builtin types.

In some cases though, we might want to validate a schema coming from introspection. This is typically the case in GraphiQL but other clients might also want to do this as a sanity check before running code generation or anything else.

In the case of a remote service, there is a high chance that the results of introspection do not match the version of GraphQL JS being used (because the tools haven't been updated).

In those cases, validation may fail for otherwise valid schemas.

Reproducer:

// This is valid SDL returned from an hypothetical newer version of GraphQL
const typeDefs = `
    type Query {
      hello: String
    }
    
    enum __ErrorBehaviour {
      NULL
      PROPAGATE
      HALT
    }

    directive @behavior(onError: __ErrorBehaviour) on SCHEMA
`
let schema = buildSchema(typeDefs)
let errors = validateSchema(schema)

Output:

  GraphQLError: Name "__ErrorBehaviour" must not begin with "__", which is reserved by GraphQL introspection.
      at SchemaValidationContext.reportError (/Users/martinbonnin/git/graphql-js-playground/node_modules/graphql/type/validate.js:73:7)
      at validateName (/Users/martinbonnin/git/graphql-js-playground/node_modules/graphql/type/validate.js:216:13)
      at validateTypes (/Users/martinbonnin/git/graphql-js-playground/node_modules/graphql/type/validate.js:239:7)
      at validateSchema (/Users/martinbonnin/git/graphql-js-playground/node_modules/graphql/type/validate.js:43:3)
      at Object.<anonymous> (/Users/martinbonnin/git/graphql-js-playground/dist/index.js:18:43)
      at Module._compile (node:internal/modules/cjs/loader:1723:14)
      at Object..js (node:internal/modules/cjs/loader:1888:10)
      at Module.load (node:internal/modules/cjs/loader:1458:32)
      at Function._load (node:internal/modules/cjs/loader:1275:12)
      at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
    path: undefined,
    locations: [ [Object] ],
    extensions: [Object: null prototype] {}
  }

It would be nice to have a validateFullSchema() that is able to deal with Full Schemas, including built in types.

Context: graphql/graphiql#3968

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant