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
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
Comment #3
kingdutchComment #4
kingdutchAdded example output
Comment #5
kingdutchComment #6
dan2k3k4 commentedTaking a look
Comment #7
dan2k3k4 commentedCouple 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
Comment #8
kingdutchComment #9
dan2k3k4 commentedCool, 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()
```
Comment #10
dan2k3k4 commentedComment #11
kingdutchAddressed the feedback by Dan:
The breaking changes command now expects SDL unless you pass the
--jsonflag, similar to the dump command.Both commands are now symmetric (optional --json flag with "file" being an optional positional argument) .
This has been resolved
Feedback has been improved and now contains the entire file path so that it can more easily be understood what the command is doing.
Comment #12
kingdutchDid 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!