strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
4.01k stars 533 forks source link

Feature: find breaking changes in schema #3161

Open brunodantas opened 1 year ago

brunodantas commented 1 year ago

Feature Request Type

Description

It would be nice to have builtin strawberry utilities that perform schema check functionality like graphql-core's find_breaking_changes and find_dangerous_changes.

Note: this functionality is currently achievable by using the Strawberry export tool into GraphQL SDL and then running the graph-ql core function.

Upvote & Fund

Fund with Polar

patrick91 commented 1 year ago

oh that's a cool suggestion! how would this work? would you pass the old SDL and figure the breaking changes from there?

brunodantas commented 1 year ago

Yes, that sounds great for a CLI command. The same command could also have two SDLs as input and call the graphql-core function from there.

patrick91 commented 1 year ago

So something like this:

strawberry find-breaking-changes old-schema.graphql
strawberry find-breaking-changes old-schema.graphql current-schema.graphql

we could do the same for find dangerous changes 🤔 or combine the two commands into one, I need to think about the naming

patrick91 commented 1 year ago

maybe strawberry audit could be a good one, I was thinking about strawberry lint but that wouldn't make a lot of sense when passing an old schema

happy to take any suggestion :)

brunodantas commented 1 year ago

There's this tool that does this kind of stuff... kamilkisiela/graphql-inspector: 🕵️‍♀️ Validate schema, get schema change notifications, validate operations, find breaking changes, look for similar types, schema coverage

We can maybe take inspiration from them and call it strawberry inspect.

In their CLI they call the specific command diff: Diff and Validate GraphQL Schemas – GraphQL Inspector

patrick91 commented 1 year ago

Yet another option: Apollo also has a schema check feature: https://www.apollographql.com/docs/rover/commands/graphs/#graph-check

brunodantas commented 1 year ago

Oh and I was gonna call it something like schema_check in my project 🙃

patrick91 commented 1 year ago

Oh and I was gonna call it something like schema_check in my project 🙃

ah!

to add more ideas, we could allow using pyproject.toml to specify the options, but that could come later, for now we could allow this:

strawberry check path.to.schema
strawberry check --previous-schema something.graphql path.to.schema # breaking maybe enabled by default
strawberry check --breaking --dangerous --previous-schema something.graphql path.to.schema

what do you think?

brunodantas commented 1 year ago

Looking at the command strawberry export-schema, I feel like this needs to be called strawberry check-schema haha

Other than that, LGTM

brunodantas commented 1 year ago

Is the input SDL or a Strawberry schema? Or both?

path.to.schema makes it look like it's module only

patrick91 commented 1 year ago

module, would you prefer to pass the sdl? why? 😊

brunodantas commented 1 year ago

I'm planning to compare the current schema (module) with the old SDL schema that's in a file being version-controlled (for clarity in schema changes). So it's a use case with mixed representation kinds.

But I would prefer both module and SDL inputs for flexibility, if possible 😁