drupal-graphql / graphql

GraphQL integration for Drupal 9/10
286 stars 202 forks source link

Type not found in document when loading Extension for composable schema #1343

Open atlowl opened 1 year ago

atlowl commented 1 year ago

I've split out my more common types into the atimintestschema.graphqls file, my thought was these get resolved in AtiSchema.php, but it doesn't seem to find them. When the Test Event extension is enabled, those types are then not found, and i get the following error:

The website encountered an unexpected error. Please try again later.
GraphQL\Error\Error: Type "Language" not found in document. in GraphQL\Utils\BuildSchema::GraphQL\Utils\{closure}() (line 149 of /opt/vendor/webonyx/graphql-php/src/Utils/BuildSchema.php).
GraphQL\Utils\ASTDefinitionBuilder->internalBuildType('Language', Object) (Line: 194)
GraphQL\Utils\ASTDefinitionBuilder->buildType(Object) (Line: 182)
GraphQL\Utils\ASTDefinitionBuilder->buildWrappedType(Object) (Line: 155)
....

I have attached my module thats more or less a min reproduction hopefully it provides some clues.

Kingdutch commented 1 year ago

Thanks for creating a support request! I'm very hesitant of downloading zip files from the internet, so to make it easier to help you, try reducing the scope of what you're doing to as few lines as possible which still reproduce the error and paste those in code blocks here. Or create a gist to share if you feel like you still have too much code put in an issue :D As an upside of reducing the amount of code you're reporting on, you may find what code is causing the problem and solve the issue yourself.

atlowl commented 1 year ago

No worries, i didn't know about Gists's, so i've created one for this instead of the zip file. https://gist.github.com/atlowl/1072ad0acd7623ff09d739c66a42361b

Kingdutch commented 11 months ago

Thanks for posting the Gist! That makes it easy to find the cause :)

Your issue is using the ComposableSchema class which overrides getSchemaDefinition to

  /**
   * {@inheritdoc}
   */
  protected function getSchemaDefinition() {
    return <<<GQL
      type Schema {
        query: Query
      }

      type Query
GQL;

  }

It does this instead of the base schema plugin class which will load the schema file with the <id>.graphqls name that you're expecting.

The ComposableSchema is really for situations where you don't want to define any base schema yourself but just select extensions to load. In your case (where your extensions are also specifying which schema they're extending) you want to use SdlSchemaPluginBase :)