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

Add 'diffSchema' utility function #3224

Open
IvanGoncharov opened this issue Aug 10, 2021 · 2 comments
Open

Add 'diffSchema' utility function #3224

IvanGoncharov opened this issue Aug 10, 2021 · 2 comments

Comments

@IvanGoncharov
Copy link
Member

Extracted from #1127 see #1127 (comment)

We shoud add diffSchemas function. That returns something like this:

type SchemaDifference = {|
  added: {|
    queryType?: GraphQLObjectType,
    // ...
    types: Array<GraphQLTypes>,
    directives: Array<GraphQLDirectives>
  |},
  changed: {|
    queryType?: ValueDifference<GraphQLType>,
    // ...
    types: Array<TypeDifference>,
    directives: Array<DirectivesDifference>
  |}
  // ...
|};

type ValueDifference<T> = { old: T, new: T };

type TypeDifference = ScalarTypeDifference | ObjectTypeDifference; /* ... */

type ObjectTypeDifference = {|
  name: string,
  added: {|
    description: string,
    fields: Array<GraphQLField>
    // ...
  |},
  changed: {|
    description: ValueDifference<string>,
    fields: Array<FieldDifference>
    // ...
  |}
  // ...
|};

It will allow to implement your particular check as:

const diff = diffSchema(oldSchema, newSchema);

for (const newType of diff.added.types) {
  if (newType.description) {
    console.log("Description of a new type ...");
  }
  newType.getFields().forEach(reportNewField);
}

for (const typeDiff of diff.changed.types) {
  if (typeDiff.added.description) {
    console.log("Added type description ...");
  }
  typeDiff.added.fields.forEach(reportNewField);
  if (typeDiff.changed.description) {
    console.log("Changed type description ...");
  }
  for (const fieldDiff of typeDiff.changed.field) {
    if (fieldDiff.added.description) {
      console.log("Added field description ...");
      // ...
    }
  }
}

function reportNewField(field) {
  if (field.description) {
    // ...
  }
}
@yaacovCR
Copy link
Contributor

Does this add value in core beyond https://github.com/kamilkisiela/graphql-inspector ?

i think in terms of priorities, custom execution and incremental delivery might take precedence? :)

@IvanGoncharov
Copy link
Member Author

@yaacovCR Totally, agree 👍
This is just part of the triage effort before the 16.0.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants