Skip to content

Conversation

leebyron
Copy link
Collaborator

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:

{
  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.

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

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

{
  name
  ... on Dog {
    name: nickname
  }
}

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
  }
}
```
leebyron added a commit that referenced this pull request Nov 13, 2015
[validation] Loosen overlapping field validation rules
@leebyron leebyron merged commit 3d22850 into master Nov 13, 2015
@leebyron leebyron deleted the overlapping-fields branch November 13, 2015 04:16
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.

1 participant