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

Implement visual diff #1746

Conversation

FluorescentHallucinogen

This pull request adds a visual diff between two GraphQL schemas.

It should significantly improve the developer experience (DX) as compared to plaintext JSON diff.

Added fields are marked in green color, deleted in red and modified in yellow. Every change is explained in tooltip on affected field hover.

graphql-visual-diff

@@ -33,6 +33,9 @@
"@graphql-inspector/core": "0.0.0-PLACEHOLDER",
"@graphql-inspector/commands": "0.0.0-PLACEHOLDER",
"@graphql-inspector/logger": "0.0.0-PLACEHOLDER",
"express": "4.17.1",
"express-graphql": "0.11.0",
"graphql-tools": "6.2.4-alpha-34c1194a.0",

Choose a reason for hiding this comment

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

@kamilkisiela This line could be removed when this bug is fixed.

@ardatan cc.

Copy link
Owner

Choose a reason for hiding this comment

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

@FluorescentHallucinogen looks good but let's wait for the fix @ardatan

@@ -0,0 +1,128 @@
<!DOCTYPE html>

Choose a reason for hiding this comment

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

@kamilkisiela Need your help. How to include (copy) this file into build?

Copy link
Owner

Choose a reason for hiding this comment

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

We would have to adjust bob-the-bundler but I'll do it after merging this PR.

packages/commands/diff/src/index.ts Outdated Show resolved Hide resolved
packages/commands/diff/src/index.ts Outdated Show resolved Hide resolved
@FluorescentHallucinogen
Copy link
Author

@kamilkisiela @dotansimha @ardatan @Urigo

Also visual diff from this pull request could be a very useful addition to GraphQL Hive:

graphql-hive

All that is needed is to execute the next GraphQL query to https://app.graphql-hive.com/api/proxy endpoint

query compare($organization: ID!, $project: ID!, $target: ID!, $version: ID!) {
  schemaCompareToPrevious(
    selector: {organization: $organization, project: $project, target: $target, version: $version}
  ) {
    __typename
    ...SchemaCompareResultFields
    ...SchemaCompareErrorFields
  }
  schemaVersion(
    selector: {organization: $organization, project: $project, target: $target, version: $version}
  ) {
    __typename
    ...SchemaVersionFields
  }
}

fragment SchemaCompareResultFields on SchemaCompareResult {
  initial
  changes {
    total
    nodes {
      ...SchemaChangeFields
      __typename
    }
    __typename
  }
  diff {
    before
    after
    __typename
  }
}

fragment SchemaChangeFields on SchemaChange {
  path
  message
  criticality
}

fragment SchemaCompareErrorFields on SchemaCompareError {
  message
}

fragment SchemaVersionFields on SchemaVersion {
  id
  date
  valid
  commit {
    id
    author
    service
    commit
    __typename
  }
}

and compare data.schemaCompareToPrevious.diff.before and data.schemaCompareToPrevious.diff.after from response.

@TuvalSimha
Copy link
Collaborator

Hi @FluorescentHallucinogen ,
Thank you for your contribution. At the moment we are not looking into supporting this kind of feature in Inspector, because we think it might make maintenance more complicated, and since we think that visual diff is working fine, but it's not scalable after ~50 types.

I do think this PR is a good reference for users who wants to create a custom setup on top of Voyager and Inspector, so maybe we can convert that into an example?

@TuvalSimha TuvalSimha closed this Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants