Skip to content

Commit 0c4d26d

Browse files
committed
fix: don't treat empty operation name as special
previously, if an empty operation name was given and multiple operations were provided in the query, then the first operation would be returned. not entirely sure why this would be the desired behaviour, when an exception would be thrown for any other value that doesn't match an existing operation in the query.
1 parent e5f21b8 commit 0c4d26d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/main/java/graphql/language/NodeUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static GetOperationResult getOperation(Document document, String operatio
7878
}
7979
OperationDefinition operation;
8080

81-
if (operationName == null || operationName.isEmpty()) {
81+
if (operationName == null) {
8282
operation = operationsByName.values().iterator().next();
8383
} else {
8484
operation = operationsByName.get(operationName);

src/test/groovy/graphql/language/NodeUtilTest.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ class NodeUtilTest extends Specification {
3030
''')
3131

3232
when:
33-
NodeUtil.getOperation(doc, 'Unknown')
33+
NodeUtil.getOperation(doc, operationName)
3434

3535
then:
3636
def ex = thrown(UnknownOperationException)
37-
ex.message == "Unknown operation named 'Unknown'."
37+
ex.message == "Unknown operation named '$operationName'."
38+
39+
where:
40+
operationName << ['Unknown', '']
3841
}
3942

4043
def d1 = Directive.newDirective().name("d1").build()

0 commit comments

Comments
 (0)