graphql.execution.ExecutionId Java Examples

The following examples show how to use graphql.execution.ExecutionId. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenTracingExecutionDecoratorTest.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecutionTracing() {
    ExecutionInput executionInput = ExecutionInput.newExecutionInput()
            .query("{}")
            .context(GraphQLContext.newContext())
            .executionId(ExecutionId.from("1"))
            .build();

    ExecutionResult executionResult = Mockito.mock(ExecutionResult.class);

    OpenTracingExecutionDecorator openTracingExecutionDecorator = new OpenTracingExecutionDecorator();

    openTracingExecutionDecorator.before(executionInput);
    openTracingExecutionDecorator.after(executionInput, executionResult);

    assertEquals(1, MockTracerOpenTracingService.MOCK_TRACER.finishedSpans().size(), "One span should be finished");
    MockSpan span = MockTracerOpenTracingService.MOCK_TRACER.finishedSpans().get(0);
    assertEquals("GraphQL", span.operationName());
    assertEquals("1", span.tags().get("graphql.executionId"), "ExecutionId should be present in span");
}
 
Example #2
Source File: OpenTracingExecutionDecoratorTest.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
@Test
public void spanOperationNameShouldContainGraphQLOperationName() {
    ExecutionInput executionInput = ExecutionInput.newExecutionInput()
            .query("{}")
            .context(GraphQLContext.newContext())
            .operationName("someOperation")
            .executionId(ExecutionId.from("1"))
            .build();

    ExecutionResult executionResult = Mockito.mock(ExecutionResult.class);

    OpenTracingExecutionDecorator openTracingExecutionDecorator = new OpenTracingExecutionDecorator();

    openTracingExecutionDecorator.before(executionInput);
    openTracingExecutionDecorator.after(executionInput, executionResult);

    assertEquals(1, MockTracerOpenTracingService.MOCK_TRACER.finishedSpans().size(), "One span should be finished");
    MockSpan span = MockTracerOpenTracingService.MOCK_TRACER.finishedSpans().get(0);
    assertEquals("GraphQL:someOperation", span.operationName());
    assertEquals("someOperation", span.tags().get("graphql.operationName"),
            "operation name should be present in span");
}
 
Example #3
Source File: MockDataFetchEnvironment.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
public static DataFetchingEnvironment myFastQueryDfe(String typeName, String fieldName, String operationName,
        String executionId) {
    GraphQLNamedType query = mock(GraphQLNamedType.class);
    when(query.getName()).thenReturn(typeName);

    Field field = mock(Field.class);
    when(field.getName()).thenReturn(fieldName);

    OperationDefinition operationDefinition = mock(OperationDefinition.class);
    when(operationDefinition.getName()).thenReturn(operationName);

    ExecutionPath executionPath = mock(ExecutionPath.class);
    when(executionPath.toString()).thenReturn("/" + typeName + "/" + fieldName);
    ExecutionStepInfo executionStepInfo = mock(ExecutionStepInfo.class);
    when(executionStepInfo.getPath()).thenReturn(executionPath);

    DataFetchingEnvironment dfe = mock(DataFetchingEnvironment.class);
    when(dfe.getParentType()).thenReturn(query);
    when(dfe.getField()).thenReturn(field);
    when(dfe.getOperationDefinition()).thenReturn(operationDefinition);
    when(dfe.getExecutionStepInfo()).thenReturn(executionStepInfo);
    when(dfe.getExecutionId()).thenReturn(ExecutionId.from(executionId));

    return dfe;
}
 
Example #4
Source File: Util.java    From rsocket-rpc-java with Apache License 2.0 6 votes vote down vote up
static CompletableFuture<ExecutionResult> executeGraphQLRequest(
    GraphQLRequest request,
    ByteBuf byteBuf,
    DataLoaderRegistry registry,
    GraphQLSchema graphQLSchema,
    Instrumentation instrumentation) {
  ExecutionInput.Builder builder =
      ExecutionInput.newExecutionInput()
          .query(request.getQuery())
          .operationName(request.getOperationName())
          .variables(request.getVariables())
          .context(byteBuf)
          .executionId(ExecutionId.generate());

  if (registry != null) {
    builder.dataLoaderRegistry(registry);
  }

  ExecutionInput executionInput = builder.build();

  return GraphQL.newGraphQL(graphQLSchema)
      .instrumentation(instrumentation)
      .build()
      .executeAsync(executionInput);
}
 
Example #5
Source File: ExecutionService.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
public JsonObject execute(JsonObject jsonInput) {
    String query = jsonInput.getString(QUERY);

    if (config.logPayload()) {
        log.payloadIn(query);
    }

    GraphQL g = getGraphQL();
    if (g != null) {
        // Query
        ExecutionInput.Builder executionBuilder = ExecutionInput.newExecutionInput()
                .query(query)
                .executionId(ExecutionId.from(executionIdPrefix + executionId.getAndIncrement()));

        // Variables
        graphQLVariables.getVariables(jsonInput).ifPresent(executionBuilder::variables);

        // Operation name
        if (hasOperationName(jsonInput)) {
            executionBuilder.operationName(jsonInput.getString(OPERATION_NAME));
        }

        ExecutionInput executionInput = executionBuilder.build();

        ExecutionResult executionResult = execute(g, executionInput);

        JsonObjectBuilder returnObjectBuilder = jsonObjectFactory.createObjectBuilder();

        // Errors
        returnObjectBuilder = addErrorsToResponse(returnObjectBuilder, executionResult);
        // Data
        returnObjectBuilder = addDataToResponse(returnObjectBuilder, executionResult);

        JsonObject jsonResponse = returnObjectBuilder.build();

        if (config.logPayload()) {
            log.payloadOut(jsonResponse.toString());
        }

        return jsonResponse;
    } else {
        log.noGraphQLMethodsFound();
        return null;
    }
}
 
Example #6
Source File: RelayDataFetchingEnvironmentDecorator.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutionId getExecutionId() {
    return delegate.getExecutionId();
}
 
Example #7
Source File: LookUpSubjectByUriFetcherWrapperTest.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ExecutionId getExecutionId() {
  throw new IllegalStateException("Not implemented yet");
}