Skip to content

[validation] Allow safe divergence #229

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

Merged
merged 1 commit into from
Nov 13, 2015
Merged

Conversation

leebyron
Copy link
Contributor

As pointed out in #53, our validation is more conservative than it needs to be in some cases. Particularly, two fields which could not overlap are still treated as a potential conflict.

This change loosens this rule, allowing fields which can never both apply in a frame of execution to diverge.

@leebyron
Copy link
Contributor Author

cc @schrockn @alangenfeld @mnylen

@schrockn-zz
Copy link
Contributor

yeah this makes a lot of sense #shipit

@leebyron leebyron force-pushed the allow-safe-divergence branch 2 times, most recently from ffc9bec to 4eaf6fd Compare November 13, 2015 02:00
As pointed out in #53, our validation is more conservative than it needs to be in some cases. Particularly, two fields which could not overlap are still treated as a potential conflict.

This change loosens this rule, allowing fields which can never both apply in a frame of execution to diverge.
@leebyron leebyron force-pushed the allow-safe-divergence branch from 4eaf6fd to d71e063 Compare November 13, 2015 02:01
leebyron added a commit that referenced this pull request Nov 13, 2015
[validation] Allow safe divergence
@leebyron leebyron merged commit 6a3eac7 into master Nov 13, 2015
@leebyron leebyron deleted the allow-safe-divergence branch November 13, 2015 02:07
leebyron added a commit to graphql/graphql-spec that referenced this pull request Nov 13, 2015
This loosens the rules for fields of the same response name which occur in the same selection set. Implemented in JS by graphql/graphql-js#230 and graphql/graphql-js#229

This allows for fields of the same response name to differ in a few conditions deemed to be safe where previously the validation was too conservative.

The currently supported directives: @Skip and @include do not create an ambiguous or erroneous query when used on conflicting fields in a divergent fashion. In fact, this may be intended when many different conditions should result in the same outcome. For example:

```graphql
{
  field @include(if: $firstCondition)
  field @include(if: $secondCondition)
}
```

This example could be considered as the intent of fetching `field` given `$firstCondition || $secondCondition`. While this example is contrived, there are more complex examples where such fields are nested within fragments that this condition is reasonable.

The following example is now legal, since no object can be both the concrete object type "Cat" and "Dog" at the same time, so the response shape is still unambiguous provided the types are known.

```graphql
{
  ... on Cat {
    name
  }
  ... on Dog {
    name: nickname
  }
}
```

However the following is still not legal, since it results in ambiguity:

```graphql
{
  name
  ... on Dog {
    name: nickname
  }
}
```
andimarek added a commit to graphql-java/graphql-java that referenced this pull request Dec 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants