Skip to content

Commit 8e185e1

Browse files
committed
Fixed tests when builder is empty and the ER is null
1 parent 4494ad3 commit 8e185e1

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/main/java/graphql/extensions/ExtensionsBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ public Map<Object, Object> buildExtensions() {
113113
*/
114114
public ExecutionResult setExtensions(ExecutionResult executionResult) {
115115
assertNotNull(executionResult);
116-
return executionResult.transform(builder -> builder.extensions(buildExtensions()));
116+
Map<Object, Object> currentExtensions = executionResult.getExtensions();
117+
Map<Object, Object> builderExtensions = buildExtensions();
118+
// if there was no extensions map before, and we are not adding anything new
119+
// then leave it null
120+
if (currentExtensions == null && builderExtensions.isEmpty()) {
121+
return executionResult;
122+
}
123+
return executionResult.transform(builder -> builder.extensions(builderExtensions));
117124
}
118125
}

src/test/groovy/graphql/extensions/ExtensionsBuilderTest.groovy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,27 @@ class ExtensionsBuilderTest extends Specification {
193193
id : "ID!",
194194
]
195195
}
196+
197+
def "integration test showing it leaves extensions null if they are empty"() {
198+
def sdl = """
199+
type Query {
200+
name : String!
201+
street : String
202+
id : ID!
203+
}
204+
"""
205+
206+
def ei = ExecutionInput.newExecutionInput("query q { name street id }")
207+
.root(["name" : "Brad", "id" :1234])
208+
.build()
209+
210+
211+
def graphQL = TestUtil.graphQL(sdl, newRuntimeWiring().build()).build()
212+
213+
when:
214+
def er = graphQL.execute(ei)
215+
then:
216+
er.errors.isEmpty()
217+
er.extensions == null
218+
}
196219
}

0 commit comments

Comments
 (0)