zhouzi / docusaurus-graphql-plugin

Docusaurus plugin generating Markdown documentation from a GraphQL schema.
https://gabinaureche.com/docusaurus-graphql-plugin/
23 stars 9 forks source link

Error: Unknown directive "@scalar" #15

Closed Braunson closed 1 year ago

Braunson commented 1 year ago

When running npx docusaurus docs:generate:graphql I'm getting the error:

[ERROR] Error: Unknown directive "@scalar".

Unknown directive "@scalar".
    at assertValidSDL (/home/project/docs/node_modules/graphql/validation/validate.js:135:11)
    at buildASTSchema (/home/project/docs/node_modules/graphql/utilities/buildASTSchema.js:44:34)
    at makeExecutableSchema (/home/project/docs/node_modules/@graphql-tools/schema/cjs/makeExecutableSchema.js:73:47)
    at mergeSchemas (/home/project/docs/node_modules/@graphql-tools/schema/cjs/merge-schemas.js:32:63)
    at getSchemaFromSources (/home/project/docs/node_modules/@graphql-tools/load/cjs/schema.js:56:46)
    at Object.loadSchema (/home/project/docs/node_modules/@graphql-tools/load/cjs/schema.js:19:12)
Docusaurus version: 2.3.1
Node version: v19.8.1

I'm using lighthouse-php and the graphql directory has each type in a different file, i.e. enums.graphql, inputs.graphql, queries.graphql, directives.graphql, etc.

Braunson commented 1 year ago

I regenerated the schema and it seems to work now.

zhouzi commented 1 year ago

Glad to know everything is working @Braunson. I double checked the library to make sure there's no holes around directives and everything is ok.

The error message you shared appears when using a directive that has not been declared in the schema, for example:

type ExampleType {
  newField: String
  oldField: String @rename(reason: "newField")
}

Here it would throw Error: Unknown directive "@rename". The fix is to declare the directive as part of the schema:

directive @rename(to: String = "") on FIELD_DEFINITION | ENUM_VALUE

type ExampleType {
  newField: String
  oldField: String @rename(reason: "newField")
}