|
| 1 | +package graphql |
| 2 | + |
| 3 | +import graphql.execution.DataFetcherResult |
| 4 | +import graphql.schema.DataFetcher |
| 5 | +import graphql.schema.DataFetchingEnvironment |
| 6 | +import graphql.schema.idl.RuntimeWiring |
| 7 | +import graphql.schema.idl.TypeRuntimeWiring |
| 8 | +import graphql.validation.ValidationError |
| 9 | +import graphql.validation.ValidationErrorType |
| 10 | +import spock.lang.Specification |
| 11 | + |
| 12 | +class Issue1559 extends Specification { |
| 13 | + |
| 14 | + def graphql = TestUtil.graphQL(""" |
| 15 | + type Query { |
| 16 | + contextAwareList: [ContextAwareEntity!]! |
| 17 | + } |
| 18 | + |
| 19 | + type ContextAwareEntity { |
| 20 | + name: String |
| 21 | + contextInfo: String |
| 22 | + } |
| 23 | + |
| 24 | + """, |
| 25 | + RuntimeWiring.newRuntimeWiring() |
| 26 | + .type("ContextAwareEntity", { |
| 27 | + it.dataFetcher("contextInfo", { it.getLocalContext() }) |
| 28 | + }) |
| 29 | + .build()) |
| 30 | + .build() |
| 31 | + |
| 32 | + def "#1559 test if a list of DataFetcherResults is processed properly"() { |
| 33 | + |
| 34 | + when: |
| 35 | + def input = ExecutionInput.newExecutionInput() |
| 36 | + .root([contextAwareList: [ |
| 37 | + DataFetcherResult.newResult().localContext("the context 1").data([name: "the name 1"]).build(), |
| 38 | + DataFetcherResult.newResult().localContext("the context 2").data([name: "the name 2"]).build(), |
| 39 | + DataFetcherResult.newResult().localContext("the context 3").data([name: "the name 3"]).build(), |
| 40 | + DataFetcherResult.newResult().localContext("the context 4").data([name: "the name 4"]).build(), |
| 41 | + ]]) |
| 42 | + .query(''' |
| 43 | + query getTheList { |
| 44 | + contextAwareList { |
| 45 | + name |
| 46 | + contextInfo |
| 47 | + } |
| 48 | + } |
| 49 | + ''') |
| 50 | + .build() |
| 51 | + def executionResult = graphql.execute(input) |
| 52 | + |
| 53 | + then: |
| 54 | + executionResult.errors.isEmpty() |
| 55 | + executionResult.data == [ contextAwareList: [ |
| 56 | + [name: "the name 1", contextInfo: "the context 1"], |
| 57 | + [name: "the name 2", contextInfo: "the context 2"], |
| 58 | + [name: "the name 3", contextInfo: "the context 3"], |
| 59 | + [name: "the name 4", contextInfo: "the context 4"], |
| 60 | + ]] |
| 61 | + |
| 62 | + } |
| 63 | + def "#1559 test if null validations are processed properly on DataFetcherResult List"() { |
| 64 | + |
| 65 | + when: |
| 66 | + def input = ExecutionInput.newExecutionInput() |
| 67 | + .root([contextAwareList: [ |
| 68 | + DataFetcherResult.newResult().localContext("the context 1").data([name: "the name 1"]).build(), |
| 69 | + DataFetcherResult.newResult().localContext("the context 2").data(null).build(), |
| 70 | + null, |
| 71 | + DataFetcherResult.newResult().localContext("the context 4").data([name: "the name 4"]).build(), |
| 72 | + ]]) |
| 73 | + .query(''' |
| 74 | + query getTheList { |
| 75 | + contextAwareList { |
| 76 | + name |
| 77 | + contextInfo |
| 78 | + } |
| 79 | + } |
| 80 | + ''') |
| 81 | + .build() |
| 82 | + def executionResult = graphql.execute(input) |
| 83 | + |
| 84 | + then: |
| 85 | + executionResult.errors.size() == 2 |
| 86 | + executionResult.errors[0].path == ['contextAwareList', 1] |
| 87 | + executionResult.errors[1].path == ['contextAwareList', 2] |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments