use of graphql.execution.ExecutionStepInfo in project graphql-orchestrator-java by intuit.
the class GraphQLServiceBatchLoaderTest method callsAllHooks.
@Test
public void callsAllHooks() {
QueryExecutor emptyFn = (input, context) -> CompletableFuture.completedFuture(new HashMap<>());
final BatchLoaderExecutionHooks mockHooks = mock(BatchLoaderExecutionHooks.class);
GraphQLServiceBatchLoader loader = newQueryExecutorBatchLoader().queryExecutor(emptyFn).serviceMetadata(mockServiceMetadata).batchLoaderExecutionHooks(mockHooks).build();
GraphQLObjectType queryType = GraphQLObjectType.newObject().name("query").build();
MergedField mergedField1 = newMergedField(newField("first").build()).build();
GraphQLSchema graphQLSchema = newSchema().query(queryType).build();
DataFetchingEnvironment dfe = newDataFetchingEnvironment().variables(ImmutableMap.of("1", "3")).graphQLSchema(graphQLSchema).context(GraphQLContext.newContext().build()).mergedField(mergedField1).parentType(queryType).executionStepInfo(ExecutionStepInfo.newExecutionStepInfo().path(ExecutionPath.parse("/first")).field(mergedField1).type(GraphQLObjectType.newObject().name("FirstType").build()).build()).build();
loader.load(Collections.singletonList(dfe)).whenComplete((not, used) -> {
verify(mockHooks, times(1)).onBatchLoadStart(any(), any());
verify(mockHooks, times(1)).onExecutionInput(any(), any());
verify(mockHooks, times(1)).onQueryResult(any(), any());
verify(mockHooks, times(1)).onBatchLoadEnd(any(), any());
}).toCompletableFuture().join();
}
use of graphql.execution.ExecutionStepInfo in project graphql-orchestrator-java by intuit.
the class GraphQLServiceBatchLoaderTest method makesCorrectBatchQueryWithCustomFieldAuthorization.
@Test
public void makesCorrectBatchQueryWithCustomFieldAuthorization() {
QueryExecutor validator = (environment, context) -> {
assertThat(environment.getVariables()).describedAs("Batch Loader merges variables").extracting("1", "2").containsOnly("3", "4");
assertThat(environment.getQuery()).contains("query", "first", "second");
assertThat(environment.getOperationName()).isEqualTo("QUERY");
assertThat(environment.getRoot()).isNotNull();
return CompletableFuture.completedFuture(new HashMap<>());
};
GraphQLObjectType queryType = GraphQLObjectType.newObject().name("query").build();
MergedField mergedField1 = newMergedField(newField("first").build()).build();
MergedField mergedField2 = newMergedField(newField("second").build()).build();
GraphQLSchema graphQLSchema = newSchema().query(queryType).build();
GraphQLContext graphQLContext = GraphQLContext.newContext().build();
graphQLContext.put(BatchFieldAuthorization.class, mockBatchFieldAuthorization);
DataFetchingEnvironment dfe1 = newDataFetchingEnvironment().variables(ImmutableMap.of("1", "3")).graphQLSchema(graphQLSchema).context(graphQLContext).mergedField(mergedField1).parentType(queryType).executionStepInfo(ExecutionStepInfo.newExecutionStepInfo().path(ExecutionPath.parse("/first")).field(mergedField1).type(GraphQLObjectType.newObject().name("FirstType").build()).build()).build();
DataFetchingEnvironment dfe2 = newDataFetchingEnvironment().variables(ImmutableMap.of("2", "4")).context(GraphQLContext.newContext().build()).graphQLSchema(graphQLSchema).mergedField(mergedField2).parentType(queryType).executionStepInfo(ExecutionStepInfo.newExecutionStepInfo().path(ExecutionPath.parse("/second")).field(mergedField2).type(GraphQLObjectType.newObject().name("SecondType").build()).build()).build();
GraphQLServiceBatchLoader batchLoader = GraphQLServiceBatchLoader.newQueryExecutorBatchLoader().queryExecutor(validator).serviceMetadata(mockServiceMetadata).queryOperationModifier(new PassthroughQueryModifier()).build();
batchLoader.variableDefinitionFilter = mockVariableDefinitionFilter;
batchLoader.load(asList(dfe1, dfe2));
}
use of graphql.execution.ExecutionStepInfo in project graphql-orchestrator-java by intuit.
the class GraphQLServiceBatchLoaderTest method propagatesVariableDefinitions.
@Test
public void propagatesVariableDefinitions() {
doReturn(new HashSet<String>() {
{
add("TestVariableDefinition");
add("TestVariableDefinition2");
}
}).when(mockVariableDefinitionFilter).getVariableReferencesFromNode(any(GraphQLSchema.class), any(GraphQLObjectType.class), anyMap(), anyMap(), any(Node.class));
QueryExecutor validator = (input, context) -> {
assertThat(input.getQuery()).contains("Bulk_Query($TestVariableDefinition:TestType,$TestVariableDefinition2:TestType2)").contains("fieldWithArgument(SomeArgument:$TestVariableDefinition)");
return CompletableFuture.completedFuture(new HashMap<>());
};
GraphQLObjectType queryType = GraphQLObjectType.newObject().name("query").build();
GraphQLSchema graphQLSchema = newSchema().query(queryType).build();
OperationDefinition operationWithVariableDefinitions = newOperationDefinition().name("Bulk_Query").variableDefinitions(asList(newVariableDefinition("TestVariableDefinition").type(newTypeName("TestType").build()).build(), newVariableDefinition("TestVariableDefinition2").type(newTypeName("TestType2").build()).build())).operation(Operation.QUERY).build();
final MergedField mergedFieldWithArgument = newMergedField(newField("fieldWithArgument").arguments(singletonList(Argument.newArgument("SomeArgument", newVariableReference().name("TestVariableDefinition").build()).build())).build()).build();
final ExecutionStepInfo root = ExecutionStepInfo.newExecutionStepInfo().type(GraphQLObjectType.newObject().name("FakeType").build()).path(ExecutionPath.rootPath()).build();
DataFetchingEnvironment dfe1 = newDataFetchingEnvironment().variables(emptyMap()).graphQLSchema(graphQLSchema).operationDefinition(operationWithVariableDefinitions).context(GraphQLContext.newContext().build()).mergedField(mergedFieldWithArgument).executionStepInfo(ExecutionStepInfo.newExecutionStepInfo().path(ExecutionPath.parse("/fieldWithArgument")).parentInfo(root).field(mergedFieldWithArgument).type(GraphQLObjectType.newObject().name("FirstType").build()).build()).parentType(queryType).build();
GraphQLServiceBatchLoader batchLoader = GraphQLServiceBatchLoader.newQueryExecutorBatchLoader().queryExecutor(validator).serviceMetadata(mockServiceMetadata).queryOperationModifier(new PassthroughQueryModifier()).build();
batchLoader.variableDefinitionFilter = mockVariableDefinitionFilter;
batchLoader.load(singletonList(dfe1));
}
use of graphql.execution.ExecutionStepInfo in project graphql-orchestrator-java by intuit.
the class GraphQLTestUtil method buildCompleteExecutionStepInfo.
public static ExecutionStepInfo buildCompleteExecutionStepInfo(Document document, String... path) {
OperationDefinition query = document.getDefinitionsOfType(OperationDefinition.class).get(0);
Map<String, FragmentDefinition> fragmentDefinitions = document.getDefinitionsOfType(FragmentDefinition.class).stream().collect(Collectors.toMap(FragmentDefinition::getName, Function.identity()));
ExecutionStepInfo parent = newExecutionStepInfo().type(newObject().name("FakeType").build()).path(rootPath()).build();
Queue<String> paths = new LinkedList<>(Arrays.asList(path));
Stack<ExecutionStepInfo> hierarchy = new Stack<>();
hierarchy.push(parent);
for (final Selection selection : query.getSelectionSet().getSelections()) {
final Field field = (Field) selection;
if (field.getName().equals(paths.peek())) {
paths.poll();
buildExecutionStepInfo(field, parent, fragmentDefinitions, "", hierarchy, paths);
}
}
return hierarchy.pop();
}
use of graphql.execution.ExecutionStepInfo in project graphql-orchestrator-java by intuit.
the class MergedFieldModifierTest method filtersNonRelevantFields.
@Test
public void filtersNonRelevantFields() {
ExecutionStepInfo executionStepInfo = buildCompleteExecutionStepInfo(document, "consumer", "finance", "tax");
DataFetchingEnvironment dataFetchingEnvironment = newDataFetchingEnvironment().executionStepInfo(executionStepInfo).mergedField(executionStepInfo.getField()).build();
final MergedFieldModifierResult result = new MergedFieldModifier(dataFetchingEnvironment).getFilteredRootField();
assertThat(printPreOrder(result.getMergedField().getSingleField(), graphQLSchema, result.getFragmentDefinitions())).containsExactly("consumer", "finance", "tax", "returns", "returnHeader", "taxYr", "inline:someField");
}
Aggregations