Search in sources :

Example 1 with ExecutionStepInfo

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;
}
Also used : MergedSelectionSet(graphql.execution.MergedSelectionSet) FieldCollectorParameters(graphql.execution.FieldCollectorParameters) ExecutionStepInfo.newExecutionStepInfo(graphql.execution.ExecutionStepInfo.newExecutionStepInfo) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) GraphQLObjectType(graphql.schema.GraphQLObjectType) OperationDefinition(graphql.language.OperationDefinition)

Example 2 with ExecutionStepInfo

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);
}
Also used : NonNullableFieldWasNullException(graphql.execution.NonNullableFieldWasNullException) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) ResolvedValue(graphql.execution.nextgen.result.ResolvedValue) LeafExecutionResultNode(graphql.execution.nextgen.result.LeafExecutionResultNode)

Example 3 with ExecutionStepInfo

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));
}
Also used : GraphQLList(graphql.schema.GraphQLList) HashMap(java.util.HashMap) DataFetchingFieldSelectionSet(graphql.schema.DataFetchingFieldSelectionSet) Field(graphql.language.Field) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) ObjectField(org.dotwebstack.framework.core.model.ObjectField) MergedField(graphql.execution.MergedField) Field(graphql.language.Field) CompletableFuture(java.util.concurrent.CompletableFuture) DataLoaderRegistry(org.dataloader.DataLoaderRegistry) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) ObjectField(org.dotwebstack.framework.core.model.ObjectField) GraphQLObjectType.newObject(graphql.schema.GraphQLObjectType.newObject) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with ExecutionStepInfo

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));
}
Also used : CollectionRequest(org.dotwebstack.framework.core.query.model.CollectionRequest) HashMap(java.util.HashMap) DataFetchingFieldSelectionSet(graphql.schema.DataFetchingFieldSelectionSet) GroupedFlux(reactor.core.publisher.GroupedFlux) KeyGroupedFlux(org.dotwebstack.framework.core.datafetchers.KeyGroupedFlux) Flux(reactor.core.publisher.Flux) Field(graphql.language.Field) ObjectField(org.dotwebstack.framework.core.model.ObjectField) MergedField(graphql.execution.MergedField) Field(graphql.language.Field) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) ObjectField(org.dotwebstack.framework.core.model.ObjectField) GraphQLObjectType.newObject(graphql.schema.GraphQLObjectType.newObject) RequestContext(org.dotwebstack.framework.core.query.model.RequestContext) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 5 with ExecutionStepInfo

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));
}
Also used : ExecutionStepInfo(graphql.execution.ExecutionStepInfo) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutionStepInfo (graphql.execution.ExecutionStepInfo)18 Test (org.junit.jupiter.api.Test)7 MergedField (graphql.execution.MergedField)6 ArrayList (java.util.ArrayList)6 DataFetchingFieldSelectionSet (graphql.schema.DataFetchingFieldSelectionSet)5 HashMap (java.util.HashMap)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 Field (graphql.language.Field)4 GraphQLObjectType.newObject (graphql.schema.GraphQLObjectType.newObject)4 ObjectField (org.dotwebstack.framework.core.model.ObjectField)4 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)3 GraphQLObjectType (graphql.schema.GraphQLObjectType)3 Map (java.util.Map)3 RequestContext (org.dotwebstack.framework.core.query.model.RequestContext)3 GraphQLError (graphql.GraphQLError)2 FetchedValue (graphql.execution.FetchedValue)2 FieldCollectorParameters (graphql.execution.FieldCollectorParameters)2 MergedSelectionSet (graphql.execution.MergedSelectionSet)2 NonNullableFieldWasNullException (graphql.execution.NonNullableFieldWasNullException)2 ResolvedValue (graphql.execution.nextgen.result.ResolvedValue)2