Skip to content

Commit 994ba71

Browse files
committed
Add language to ensure fragments are unique within a document
1 parent 750d4ee commit 994ba71

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

spec/Section 5 -- Validation.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,60 @@ fragment missingRequiredArg on Arguments {
448448

449449
### Fragment Declarations
450450

451+
#### Fragment Name Uniqueness
452+
453+
** Formal Specification **
454+
455+
* For each fragment definition {fragment} in the document
456+
* Let {fragmentName} be the name of {fragment}.
457+
* Let {fragments} be all fragment definitions in the document named {fragmentName}.
458+
* {fragments} must be a set of one.
459+
460+
** Explanatory Text **
461+
462+
Fragment definitions are referenced in fragment spreads by name. To avoid
463+
ambiguity, each fragment's name must be unique within a document.
464+
465+
Inline fragments are not considered fragment definitions, and unaffected by this
466+
validation rule.
467+
468+
For example the following document is valid:
469+
470+
```graphql
471+
{
472+
...fragmentOne
473+
...fragmentTwo
474+
}
475+
476+
fragment fragmentOne on Dog {
477+
name
478+
}
479+
480+
fragment fragmentTwo on Dog {
481+
owner {
482+
name
483+
}
484+
}
485+
```
486+
487+
While this document is invalid:
488+
489+
```graphql
490+
{
491+
...fragmentOne
492+
}
493+
494+
fragment fragmentOne on Dog {
495+
name
496+
}
497+
498+
fragment fragmentOne on Dog {
499+
owner {
500+
name
501+
}
502+
}
503+
```
504+
451505
#### Fragment Spread Type Existence
452506

453507
** Formal Specification **

0 commit comments

Comments
 (0)