Skip to content

Commit 65d46bb

Browse files
committed
Operation uniqueness
1 parent 994ba71 commit 65d46bb

File tree

1 file changed

+98
-1
lines changed

1 file changed

+98
-1
lines changed

spec/Section 5 -- Validation.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,103 @@ union DogOrHuman = Dog | Human
5757
union HumanOrAlien = Human | Alien
5858
```
5959

60+
## Operations
61+
62+
### Named Operation Definitions
63+
64+
#### Operation Name Uniqueness
65+
66+
** Formal Specification **
67+
68+
* For each operation definition {operation} in the document
69+
* Let {operationName} be the name of {operation}.
70+
* If {operationName} exists
71+
* Let {operations} be all operation definitions in the document named {operationName}.
72+
* {operations} must be a set of one.
73+
74+
** Explanatory Text **
75+
76+
Each named operation definitions must be unique within a document when referred
77+
to by its name.
78+
79+
For example the following document is valid:
80+
81+
```graphql
82+
query getDogName {
83+
dog {
84+
name
85+
}
86+
}
87+
88+
query getOwnerName {
89+
dog {
90+
owner {
91+
name
92+
}
93+
}
94+
}
95+
```
96+
97+
While this document is invalid:
98+
99+
```!graphql
100+
query getName {
101+
dog {
102+
name
103+
}
104+
}
105+
106+
query getName {
107+
dog {
108+
owner {
109+
name
110+
}
111+
}
112+
}
113+
```
114+
115+
### Anonymous Operation Definitions
116+
117+
#### Lone Anonymous Operation
118+
119+
** Formal Specification **
120+
121+
* Let {operations} be all anonymous operation definitions in the document.
122+
* {operations} must be a set of one.
123+
124+
** Explanatory Text **
125+
126+
GraphQL allows a short-hand form for defining query operations when only that
127+
one operation exists in the document.
128+
129+
For example the following document is valid:
130+
131+
```graphql
132+
{
133+
dog {
134+
name
135+
}
136+
}
137+
```
138+
139+
While this document is invalid:
140+
141+
```!graphql
142+
{
143+
dog {
144+
name
145+
}
146+
}
147+
148+
query getName {
149+
dog {
150+
owner {
151+
name
152+
}
153+
}
154+
}
155+
```
156+
60157
## Fields
61158

62159
### Field Selections on Objects, Interfaces, and Unions Types
@@ -486,7 +583,7 @@ fragment fragmentTwo on Dog {
486583

487584
While this document is invalid:
488585

489-
```graphql
586+
```!graphql
490587
{
491588
...fragmentOne
492589
}

0 commit comments

Comments
 (0)