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

[RFC] Add Validation rule for unique directives per location. #229

Merged
merged 1 commit into from
Oct 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,49 @@ query @skip(if: $foo) {
```


### Directives Are Unique Per Location

** Formal Specification **

* For every {location} in the document for which Directives can apply:
* Let {directives} be the set of Directives which apply to {location}.
* For each {directive} in {directives}:
* Let {directiveName} be the name of {directive}.
* Let {namedDirectives} be the set of all Directives named {directiveName}
in {directives}.
* {namedDirectives} must be a set of one.

** Explanatory Text **

Directives are used to describe some metadata or behavioral change on the
definition they apply to. When more than one directive of the same name is used,
the expected metadata or behavior becomes ambiguous, therefore only one of each
directive is allowed per location.

For example, the following query will not pass validation because `@skip` has
been used twice for the same field:

```!graphql
query ($foo: Boolean = true, $bar: Boolean = false) {
field @skip(if: $foo) @skip(if: $bar)
}
```

However the following example is valid because `@skip` has been used only once
per location, despite being used twice in the query and on the same named field:

```graphql
query ($foo: Boolean = true, $bar: Boolean = false) {
field @skip(if: $foo) {
subfieldA
}
field @skip(if: $bar) {
subfieldB
}
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

A particularly interesting example is that this is also valid:

fieldA @skip(if: $foo)
fieldA @skip(if: $bar)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great point - I should add that



## Variables

### Variable Uniqueness
Expand Down