Problem/Motivation

The GraphQL schema is often needed in other applications and can be fetched through introspection. However, to do this there are additional tools needed along with the installed Drupal site. Similarly this result across multiple versions may be used to detect breaking changes.

The GraphQL library that we use has everything we need to dump the GraphQL schema as SDL or JSON to disk and to detect breaking changes against a previous schema version.

By wrapping these in Drush commands we can make them easily available in the CI without requiring external tooling.

Steps to reproduce

Proposed resolution

Introduce two new Drush commands: graphql:dump to dump the current schema to STDOUT or disk and graphql:breaking which can be provided a previously dumped schema and output the breaking changes (if any).

# drush graphql:breaking open_social_graphql graphql.json  
 ------------------------------- ------------------------------------------------------- 
  Type                            Description                                            
 ------------------------------- ------------------------------------------------------- 
  FIELD_CHANGED_KIND              Topic.id changed type from ID! to ID.                  
  FIELD_REMOVED                   Topic.title was removed.                               
  FIELD_REMOVED                   Topic.author was removed.                              
  IMPLEMENTED_INTERFACE_REMOVED   Topic no longer implements interface ContentTaggable.  
 ------------------------------- ------------------------------------------------------- 

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork graphql-3575840

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kingdutch created an issue. See original summary.

kingdutch’s picture

Assigned: kingdutch » Unassigned
Status: Active » Needs review
kingdutch’s picture

Issue summary: View changes

Added example output

kingdutch’s picture

Issue tags: +DevDaysAthens2026
dan2k3k4’s picture

Assigned: Unassigned » dan2k3k4

Taking a look

dan2k3k4’s picture

Status: Needs review » Needs work

Couple things:

- It dumps SDL by default, so it should also check breaking SDL by default instead of JSON
- SDL breaking seems to be missing
- If file cannot be found, feedback should be clearer, right now it just throws a syntax error

kingdutch’s picture

Status: Needs work » Needs review
dan2k3k4’s picture

Cool, thanks

JSON works

SDL - testing breaking changes seems to not work yet:

```
dan@test-graphql-module-web:/var/www/html$ drush graphql:breaking testone test.sdl

[error] TypeError: GraphQL\Utils\BuildClientSchema::build(): Argument #1 ($introspectionQuery) must be of type array, GraphQL\Language\AST\DocumentNode given, called in /var/www/html/web/modules/contrib/graphql/src/Drush/Commands/DetectBreakingChangesCommand.php on line 106 in GraphQL\Utils\BuildClientSchema::build() (line 95 of /var/www/html/vendor/webonyx/graphql-php/src/Utils/BuildClientSchema.php) #0 /var/www/html/web/modules/contrib/graphql/src/Drush/Commands/DetectBreakingChangesCommand.php(106): GraphQL\Utils\BuildClientSchema::build()
```

dan2k3k4’s picture

Assigned: dan2k3k4 » Unassigned
Status: Needs review » Needs work
kingdutch’s picture

Status: Needs work » Needs review

Addressed the feedback by Dan:

- It dumps SDL by default, so it should also check breaking SDL by default instead of JSON

The breaking changes command now expects SDL unless you pass the --json flag, similar to the dump command.

Both commands are now symmetric (optional --json flag with "file" being an optional positional argument) .

- SDL breaking seems to be missing

This has been resolved

$ drush graphql:breaking example foo.sdl 
 -------------------- ----------------------------------------------------- 
  Type                 Description                                          
 -------------------- ----------------------------------------------------- 
  FIELD_CHANGED_KIND   Article.author changed type from String! to String.  
 -------------------- ----------------------------------------------------- 
Failed to run drush graphql:breaking example foo.sdl: exit status 1
- If file cannot be found, feedback should be clearer, right now it just throws a syntax error

Feedback has been improved and now contains the entire file path so that it can more easily be understood what the command is doing.

$ drush graphql:breaking --json example foobar.json

In DetectBreakingChangesCommand.php line 94:
                                                    
  File '/var/www/html/foobar.json' does not exist.  
                                                    

Failed to run drush graphql:breaking --json example foobar.json: exit status 1
kingdutch’s picture

Status: Needs review » Fixed

Did another review and a round of testing. PHPStan and PHPCS say everything is a-okay and good to go, so merging this :)

Thanks for your help Dan!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • kingdutch committed 2db2fed6 on 5.x
    feat: #3575840 Add Drush commands for schema dump and breaking changes...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.