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

As part of the change in SdlSchemaPluginBase to cache the AST instead of raw strings \Drupal\graphql\Event\AlterSchemaDataEvent and \Drupal\graphql\Event\AlterSchemaExtensionDataEvent have been changed to work with ASTs rather than SDL string representations. This requires any event listeners to be updated and use the \GraphQL\Language\Visitor class to traverse the tree and make changes.

Before

    $schemaData = $event->getSchemaExtensionData();
    $schemaData['graphql_alterable_schema_test'] = str_replace('position: Int', 'position: Int!', $schemaData['graphql_alterable_schema_test'] ?? '');
    $event->setSchemaExtensionData($schemaData);

After

      $schemaData = $event->getSchemaExtensionData();
      Visitor::visit($schemaData['graphql_alterable_schema_test'], [
        NodeKind::FIELD_DEFINITION => [
          'enter' => function (Node $node) {
            assert($node instanceof FieldDefinitionNode);
            if ($node->name->value !== 'position') {
              // Do nothing.
              return NULL;
            }
            // Make the type non-nullable.
            $node->type = new NonNullTypeNode(['type' => $node->type]);

            return $node;
          },
          'leave' => function (Node $node) {
            assert($node instanceof FieldDefinitionNode);
            // Once we've visited the position field node we can stop.
            if ($node->name->value === 'position') {
              return Visitor::stop();
            }
            // Do nothing.
            return NULL;
          },
        ],
      ]);
      $event->setSchemaExtensionData($schemaData);
Impacts: 
Module developers
Site templates, recipes and distribution developers