use of graphql.execution.ExecutionStepInfo in project graphql-java by graphql-java.
the class ExecutionHelper method getFieldSubSelection.
public FieldSubSelection getFieldSubSelection(ExecutionContext executionContext) {
OperationDefinition operationDefinition = executionContext.getOperationDefinition();
GraphQLObjectType operationRootType = Common.getOperationRootType(executionContext.getGraphQLSchema(), operationDefinition);
FieldCollectorParameters collectorParameters = FieldCollectorParameters.newParameters().schema(executionContext.getGraphQLSchema()).objectType(operationRootType).fragments(executionContext.getFragmentsByName()).variables(executionContext.getVariables()).build();
MergedSelectionSet mergedSelectionSet = fieldCollector.collectFields(collectorParameters, operationDefinition.getSelectionSet());
ExecutionStepInfo executionInfo = newExecutionStepInfo().type(operationRootType).path(ResultPath.rootPath()).build();
FieldSubSelection fieldSubSelection = FieldSubSelection.newFieldSubSelection().source(executionContext.getRoot()).localContext(executionContext.getLocalContext()).mergedSelectionSet(mergedSelectionSet).executionInfo(executionInfo).build();
return fieldSubSelection;
}
use of graphql.execution.ExecutionStepInfo in project graphql-java by graphql-java.
the class ResultNodesCreator method createResultNode.
public ExecutionResultNode createResultNode(FetchedValueAnalysis fetchedValueAnalysis) {
ResolvedValue resolvedValue = createResolvedValue(fetchedValueAnalysis);
ExecutionStepInfo executionStepInfo = fetchedValueAnalysis.getExecutionStepInfo();
if (fetchedValueAnalysis.isNullValue() && executionStepInfo.isNonNullType()) {
NonNullableFieldWasNullException nonNullableFieldWasNullException = new NonNullableFieldWasNullException(executionStepInfo, executionStepInfo.getPath());
return new LeafExecutionResultNode(executionStepInfo, resolvedValue, nonNullableFieldWasNullException);
}
if (fetchedValueAnalysis.isNullValue()) {
return new LeafExecutionResultNode(executionStepInfo, resolvedValue, null);
}
if (fetchedValueAnalysis.getValueType() == FetchedValueAnalysis.FetchedValueType.OBJECT) {
return createUnresolvedNode(fetchedValueAnalysis);
}
if (fetchedValueAnalysis.getValueType() == FetchedValueAnalysis.FetchedValueType.LIST) {
return createListResultNode(fetchedValueAnalysis);
}
return new LeafExecutionResultNode(executionStepInfo, resolvedValue, null);
}
use of graphql.execution.ExecutionStepInfo in project dotwebstack-framework by dotwebstack.
the class BackendDataFetcherTest method get_returnsCompletableFuture_ifNotSubscription_ListTypeTrue_and_JoinCondition.
@Test
@Disabled("fix me")
void get_returnsCompletableFuture_ifNotSubscription_ListTypeTrue_and_JoinCondition() {
Map<String, Object> source = new HashMap<>();
source.put("a", "bbb");
Map<String, Object> condition = new HashMap<>();
condition.put("b", "ccc");
var joinCondition = JoinCondition.builder().key(condition).build();
source.put("$join:aaa", joinCondition);
graphql.language.Field fieldMock = new Field("aaa");
var requestContext = RequestContext.builder().objectField(mock(ObjectField.class)).source(source).build();
when(requestFactory.createRequestContext(environment)).thenReturn(requestContext);
when(environment.getSource()).thenReturn(source);
lenient().when(environment.getField()).thenReturn(fieldMock);
GraphQLList listType = mock(GraphQLList.class);
when(environment.getFieldType()).thenReturn(listType);
mockOperationDefinition(OperationDefinition.Operation.QUERY);
when(environment.getDataLoaderRegistry()).thenReturn(new DataLoaderRegistry());
var collectionRequest = CollectionRequest.builder().objectRequest(ObjectRequest.builder().build()).build();
DataFetchingFieldSelectionSet selectionSet = mock(DataFetchingFieldSelectionSet.class);
when(environment.getSelectionSet()).thenReturn(selectionSet);
var executionStepInfo = mockExecutionStepInfoWithResultPath("fff", "fff");
lenient().when(requestFactory.createCollectionRequest(eq(executionStepInfo), eq(selectionSet))).thenReturn(collectionRequest);
var result = backendDataFetcher.get(environment);
assertThat(result, notNullValue());
assertTrue(result instanceof CompletableFuture);
verify(requestFactory, times(2)).createCollectionRequest(any(ExecutionStepInfo.class), any(DataFetchingFieldSelectionSet.class));
verify(requestFactory).createRequestContext(any(DataFetchingEnvironment.class));
}
use of graphql.execution.ExecutionStepInfo in project dotwebstack-framework by dotwebstack.
the class BackendDataFetcherTest method get_returnsFluxMap_ifSourceNull_SubscriptionTrue.
@Test
void get_returnsFluxMap_ifSourceNull_SubscriptionTrue() {
var requestContext = RequestContext.builder().objectField(mock(ObjectField.class)).source(null).build();
when(requestFactory.createRequestContext(environment)).thenReturn(requestContext);
when(environment.getSource()).thenReturn(null);
graphql.language.Field fieldMock = new Field("aaa");
lenient().when(environment.getField()).thenReturn(fieldMock);
mockOperationDefinition(OperationDefinition.Operation.SUBSCRIPTION);
var collectionRequest = mock(CollectionRequest.class);
var selectionSet = mock(DataFetchingFieldSelectionSet.class);
when(environment.getSelectionSet()).thenReturn(selectionSet);
var executionStepInfo = mockExecutionStepInfoWithResultPath("bbb", "bbb");
lenient().when(requestFactory.createCollectionRequest(eq(executionStepInfo), eq(selectionSet))).thenReturn(collectionRequest);
Map<String, Object> data = new HashMap<>();
data.put("aa", new String[] { "a", "b" });
when(backendLoader.loadMany(any(CollectionRequest.class), any(RequestContext.class))).thenReturn(Flux.just(data));
mockGraphQlFieldDefinition(Map.of());
var result = ((Flux<?>) backendDataFetcher.get(environment)).blockFirst();
assertThat(result, CoreMatchers.is(notNullValue()));
assertTrue(result instanceof Map);
assertThat(((Map<?, ?>) result).get("aa"), is(data.get("aa")));
verify(requestFactory).createCollectionRequest(any(ExecutionStepInfo.class), any(DataFetchingFieldSelectionSet.class));
verify(backendLoader).loadMany(any(CollectionRequest.class), any(RequestContext.class));
}
use of graphql.execution.ExecutionStepInfo in project dotwebstack-framework by dotwebstack.
the class GraphQlHelperTest method getRequestStepInfo_returnsExisting_forRequestStepInfo.
@Test
void getRequestStepInfo_returnsExisting_forRequestStepInfo() {
ExecutionStepInfo root = mock(ExecutionStepInfo.class);
ExecutionStepInfo request = mock(ExecutionStepInfo.class);
when(request.getParent()).thenReturn(root);
when(request.hasParent()).thenReturn(true);
var actual = getRequestStepInfo(request);
assertThat(actual, equalTo(request));
}
Aggregations