@Override public void accept(ExecutionResult result) { try { QueryResult queryResult = convertToQueryResult(result); resultHandler.handle(Future.succeededFuture(queryResult)); } catch (Exception e) { resultHandler.handle(Future.failedFuture(e)); } } });
/** * Executes a blocking call to the GraphQL query processor and executes the query. * * @param graphqlQuery the graphql query * @param variables the variables to pass to the query * @return the graphql query result */ public QueryResult queryBlocking(String graphqlQuery, JsonObject variables) { Objects.requireNonNull(graphqlQuery, "GraphQL query cannot be null"); GraphQL graphQL = new GraphQL(schema()); ExecutionResult result; if (variables == null) { result = graphQL.execute(graphqlQuery); } else { result = graphQL.execute(graphqlQuery, (Object) null, variables.getMap()); } return convertToQueryResult(result); }
@Test public void should_Create_Query_Result_From_Failed_Execution_Result() { // given final ExecutionResult input = QUERY_RESULT_FAILURE; // when QueryResult result = new QueryResult(new QueryResult(SchemaDefinition.convertToQueryResult(input).toJson())); // then assertEquals(result.getData(), new JsonObject()); assertEquals(result, result); assertNotEquals(result, "test"); assertFalse(result.isSucceeded()); assertNotNull(result.getErrors()); assertEquals(2, result.getErrors().size()); assertEquals(result.getErrors().get(0), result.getErrors().get(0)); assertNotEquals(result.getErrors().get(0), "test"); assertEquals("ValidationError", result.getErrors().get(0).getErrorType()); assertEquals("Validation error of type UnknownType: Error1", result.getErrors().get(0).getMessage()); assertNotNull(result.getErrors().get(0).getLocations()); assertNotNull(result.getErrors().get(1).getLocations()); assertEquals(2, result.getErrors().get(1).getLocations().size()); assertEquals(1, result.getErrors().get(0).getLocations().get(0).getLine()); assertEquals(3, result.getErrors().get(1).getLocations().get(1).getColumn()); assertEquals(EXPECTED_FAILURE, result); assertEquals(EXPECTED_FAILURE.hashCode(), result.hashCode()); }
@Test public void should_Create_Query_Result_From_Succeeded_Execution_Result() { // given final ExecutionResult input = QUERY_RESULT_SUCCESS; // when QueryResult result = new QueryResult(new QueryResult( new QueryResult(SchemaDefinition.convertToQueryResult(input)).toJson())); // then assertNotNull(result.getData()); assertEquals(true, result.getData().getBoolean("query-data")); assertTrue(result.isSucceeded()); assertNotNull(result.getErrors()); assertEquals(0, result.getErrors().size()); assertEquals(EXPECTED_SUCCESS, result); assertEquals(EXPECTED_SUCCESS.hashCode(), result.hashCode()); }