Change record status: 
Project: 
Introduced in branch: 
5.x
Introduced in version: 
5.0.0-beta3
Description: 

In previous versions of GraphQL it was possible for a .graphqls file for a schema extension to be empty.

To enable source location information, loaded files are now parsed to be \GraphQL\Language\Source instances. These classes require a non-empty source string that contains at least one type definition.

As such, the SdlSchemaExtensionPluginBase::loadDefinitionFile (and by usage both SdlSchemaExtensionPluginBase::getBaseDefinition and SdlSchemaExtensionPluginBase::getExtensionDefinition) will now throw an error if the loaded .graphqls file is empty to prevent obscure parsing errors from the Source class.

An error was already thrown if the file did not exist to help with forgotten implementations and filename typos.

If you do not use one of the files for an SdlSchemaExtension plugin, overwrite the method and have it return NULL explicitly to indicate that this is intentional and not an oversight.

  /**
   * {@inheritdoc}
   */
  public function getBaseDefinition(): null {
    return NULL;
  }

or

  /**
   * {@inheritdoc}
   */
  public function getExtensionDefinition(): null {
    return NULL;
  }

Note that to maintain Drupal 10 support and not raise the minimum PHP to 8.2 the updates should be:

  /**
   * {@inheritdoc}
   */
  public function getBaseDefinition(): ?GraphQL\Language\Source {
    return NULL;
  }

or

  /**
   * {@inheritdoc}
   */
  public function getExtensionDefinition(): ?GraphQL\Language\Source {
    return NULL;
  }

This is because NULL on it's own is not a valid PHP 8.1 return type and while the GraphQL module 4.4 expects these methods to return a string or a NULL this is not enforced on the interface.

Impacts: 
Site builders, administrators, editors
Module developers
Site templates, recipes and distribution developers