Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: fix bug when exporting metadata to remote_schemas.yaml #8921

Closed
wants to merge 5 commits into from

Conversation

kmtym1998
Copy link
Contributor

@kmtym1998 kmtym1998 commented Sep 4, 2022

Description

  • Use FormatSchemaDocument to format remote schema permission instead of FormatSchema because FormatSchema drops schema {} clause
  • This change may affect users when exporting metadata to remote_schemas.yaml

FYI : formatter library code useing on hasura-cli: https://github.com/vektah/gqlparser/blob/v2.4.3/formatter/formatter.go

Changelog

Component : cli

Type: bugfix

Product: community-edition

Short Changelog

fix bug when exporting metadata to remote_schemas.yaml (#8579)

Long Changelog

Related Issues

#8579

Solution and Design

When I click the save permissions button on hasura console, schema string containing schema clause is sent to the endpoint /apis/migrate, so I have determined that it is not a bug in console, but in cli that exports metadata.

I found cli format GraphQL schema using vektah/gqlparser/v2/formatter before exporting metadata to remote_schemas.yaml.

vektah/gqlparser/v2/formatter has two methods to format gql schema (FormatSchema, FormatSchemaDocument). FormatSchema misses schema clause if schema.query is Query. I confirmed the same behavior in case of Mutation and Subscription (related issue). Since this does not happen with FormatSchemaDocument, I decided to use the method.
Differences in two methods behavior can be seen on my fork. Code is here.

Steps to test and verify

  1. Connect remote schema
  2. Edit and save permissions for a role on hasura console
  3. Open remote_schemas.yaml and check if schema {} clause exists on the role
  4. Call query / mutation with the role

Server checklist

Catalog upgrade

Does this PR change Hasura Catalog version?

  • No
  • Yes
    • Updated docs with SQL for downgrading the catalog

Metadata

Does this PR add a new Metadata feature?

  • No
  • Yes
    • Does run_sql auto manages the new metadata through schema diffing?
      • Yes
      • Not required
    • Does run_sql auto manages the definitions of metadata on renaming?
      • Yes
      • Not required
    • Does export_metadata/replace_metadata supports the new metadata added?
      • Yes
      • Not required

GraphQL

  • No new GraphQL schema is generated
  • New GraphQL schema is being generated:
    • New types and typenames are correlated

Breaking changes

  • No Breaking changes

  • There are breaking changes:

    1. Metadata API

      Existing query types:

      • Modify args payload which is not backward compatible
      • Behavioural change of the API
      • Change in response JSON schema
      • Change in error code
    2. GraphQL API

      Schema Generation:

      • Change in any NamedType
      • Change in table field names

      Schema Resolve:-

      • Change in treatment of null value for any input fields
    3. Logging

      • Log JSON schema has changed
      • Log type names have changed

@hasura-bot
Copy link
Contributor

Beep boop! 🤖

Hey @kmtym1998, thanks for your PR!

One of my human friends will review this PR and get back to you as soon as possible.

Stay awesome! 😎

@kmtym1998 kmtym1998 marked this pull request as ready for review September 4, 2022 10:33
@kmtym1998 kmtym1998 requested a review from a team as a code owner September 4, 2022 10:33
@kmtym1998 kmtym1998 requested a review from m-Bilal September 4, 2022 10:33
@kmtym1998 kmtym1998 changed the title fix: issue fix bug when exporting metadata to remote_schemas.yaml (#8579) Sep 4, 2022
@kmtym1998 kmtym1998 changed the title fix bug when exporting metadata to remote_schemas.yaml (#8579) fix bug when exporting metadata to remote_schemas.yaml Sep 4, 2022
@m-Bilal
Copy link
Member

m-Bilal commented Sep 13, 2022

Hi @kmtym1998, thanks for your PR! Sorry for not reviewing this last week, I was a bit busy. I'll take a look at this sometime this week.

@rikinsk rikinsk changed the title fix bug when exporting metadata to remote_schemas.yaml cli: fix bug when exporting metadata to remote_schemas.yaml Sep 13, 2022
@CLAassistant
Copy link

CLAassistant commented Sep 15, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@m-Bilal m-Bilal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kmtym1998 thank you for taking the time to submit this PR! ❤️ It looks good to me!

@scriptonist I have gone through the changes, can you please glance through this as well and then we can merge this.

@scriptonist
Copy link
Contributor

LGTM @m-Bilal

hasura-bot added a commit that referenced this pull request Sep 19, 2022
GITHUB_PR_NUMBER: 8921
GITHUB_PR_URL: #8921

PR-URL: hasura/graphql-engine-mono#5744
Co-authored-by: Ryohei KOMATSUYAMA <[email protected]>
GitOrigin-RevId: cc0948b62c3caccfb2c814433bb1a84508e3c37e
@hasura-bot hasura-bot closed this Sep 19, 2022
@hasura-bot
Copy link
Contributor

Beep boop! 🤖

GIF

Awesome work @kmtym1998!

Your changes were merged successfully. All of us at Hasura ❤️ what you did.

Thanks again 🤗

@kmtym1998 kmtym1998 deleted the fix/issue-8579 branch September 19, 2022 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants