|
| 1 | +package graphql.execution |
| 2 | + |
| 3 | +import graphql.execution.instrumentation.Instrumentation |
| 4 | +import graphql.language.Document |
| 5 | +import graphql.language.FragmentDefinition |
| 6 | +import graphql.language.OperationDefinition |
| 7 | +import graphql.parser.Parser |
| 8 | +import graphql.schema.GraphQLSchema |
| 9 | +import spock.lang.Specification |
| 10 | + |
| 11 | +class ExecutionContextBuilderTest extends Specification { |
| 12 | + |
| 13 | + |
| 14 | + def "builds the correct ExecutionContext"() { |
| 15 | + given: |
| 16 | + ExecutionContextBuilder executionContextBuilder = new ExecutionContextBuilder() |
| 17 | + |
| 18 | + ValuesResolver valuesResolver = Mock(ValuesResolver) |
| 19 | + executionContextBuilder.valuesResolver(valuesResolver) |
| 20 | + |
| 21 | + Instrumentation instrumentation = Mock(Instrumentation) |
| 22 | + executionContextBuilder.instrumentation(instrumentation) |
| 23 | + |
| 24 | + ExecutionStrategy queryStrategy = Mock(ExecutionStrategy) |
| 25 | + executionContextBuilder.queryStrategy(queryStrategy) |
| 26 | + |
| 27 | + ExecutionStrategy mutationStrategy = Mock(ExecutionStrategy) |
| 28 | + executionContextBuilder.mutationStrategy(mutationStrategy) |
| 29 | + |
| 30 | + ExecutionStrategy subscriptionStrategy = Mock(ExecutionStrategy) |
| 31 | + executionContextBuilder.subscriptionStrategy(subscriptionStrategy) |
| 32 | + |
| 33 | + GraphQLSchema schema = Mock(GraphQLSchema) |
| 34 | + executionContextBuilder.graphQLSchema(schema) |
| 35 | + |
| 36 | + def executionId = ExecutionId.generate() |
| 37 | + executionContextBuilder.executionId(executionId) |
| 38 | + |
| 39 | + def context = "context" |
| 40 | + executionContextBuilder.context(context) |
| 41 | + |
| 42 | + def root = "root" |
| 43 | + executionContextBuilder.root(root) |
| 44 | + |
| 45 | + Document document = new Parser().parseDocument("query myQuery(\$var: String){...MyFragment} fragment MyFragment on Query{foo}") |
| 46 | + def operation = document.definitions[0] as OperationDefinition |
| 47 | + def fragment = document.definitions[1] as FragmentDefinition |
| 48 | + executionContextBuilder.document(document) |
| 49 | + |
| 50 | + String operationName = "myQuery" |
| 51 | + executionContextBuilder.operationName(operationName) |
| 52 | + |
| 53 | + def variables = Collections.emptyMap() |
| 54 | + executionContextBuilder.variables(variables) |
| 55 | + |
| 56 | + |
| 57 | + valuesResolver.getVariableValues(schema, operation.getVariableDefinitions(), variables) >> [var: 'value'] |
| 58 | + when: |
| 59 | + def executionContext = executionContextBuilder.build() |
| 60 | + |
| 61 | + then: |
| 62 | + executionContext.executionId == executionId |
| 63 | + executionContext.instrumentation == instrumentation |
| 64 | + executionContext.graphQLSchema == schema |
| 65 | + executionContext.queryStrategy == queryStrategy |
| 66 | + executionContext.mutationStrategy == mutationStrategy |
| 67 | + executionContext.subscriptionStrategy == subscriptionStrategy |
| 68 | + executionContext.root == root |
| 69 | + executionContext.context == context |
| 70 | + executionContext.variables == [var: 'value'] |
| 71 | + executionContext.getFragmentsByName() == [MyFragment: fragment] |
| 72 | + executionContext.operationDefinition == operation |
| 73 | + } |
| 74 | +} |
0 commit comments