private void returnAsJson(HttpServletResponse response, ExecutionResult executionResult) throws IOException { response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); JsonKit.toJson(response, executionResult.toSpecification()); }
@Override public void handle( String target, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { if ("/graphql".equals(target)) { request.setHandled(true); Map<String, Object> json = readJson(httpServletRequest); String query = (String) json.get("query"); if (query == null) { httpServletResponse.setStatus(400); return; } String operationName = (String) json.get("operationName"); Map<String, Object> variables = getVariables(json.get("variables")); ExecutionInput executionInput = ExecutionInput.newExecutionInput() .query(query) .operationName(operationName) .variables(variables) .context(new Object()) .build(); ExecutionResult executionResult = GRAPHQL.execute(executionInput); httpServletResponse.setContentType("application/json"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); GSON.toJson(executionResult.toSpecification(), httpServletResponse.getWriter()); } }
public void toSpec() throws Exception { //::FigureM ExecutionResult executionResult = graphQL.execute(executionInput); Map<String, Object> toSpecificationResult = executionResult.toSpecification(); sendAsJson(toSpecificationResult); //::/FigureM }
resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); GSON.toJson(executionResult.toSpecification(), resp.getWriter()); logger.info("stats: " + dataLoaderRegistry.getStatistics());
public ExecutionResultJSONTesting(String target, HttpServletResponse response) { try { Object result = createER(); if (target.contains("spec")) { result = createER().toSpecification(); } if (target.contains("gson")) { testGson(response, result); } else { testJackson(response, result); } } catch (IOException e) { e.printStackTrace(); } }
GraphQlResponse.getDefaultInstance(), executionResult.toSpecification()); try { logger.info("Response in Json format: " + JsonFormat.printer().print(graphQlResponse));
resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); GSON.toJson(executionResult.toSpecification(), resp.getWriter()); logger.info("stats: " + dataLoaderRegistry.getStatistics());
void batchedRun() { System.out.println("=== BatchedExecutionStrategy ==="); GraphQLSchema schema = buildBatchedSchema(); GraphQL graphQL = GraphQL .newGraphQL(schema) .queryExecutionStrategy(new BatchedExecutionStrategy()) .build(); ExecutionInput executionInput = ExecutionInput.newExecutionInput() .query("query { shops { id name departments { id name products { id name } } } }") .build(); ExecutionResult result = graphQL.execute(executionInput); System.out.println("\nExecutionResult: " + result.toSpecification()); }
void dataLoaderRun() { System.out.println("=== AsyncExecutionStrategy with DataLoader ==="); GraphQLSchema schema = buildDataLoaderSchema(); DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry(); dataLoaderRegistry.register("departments", BatchCompareDataFetchers.departmentsForShopDataLoader); dataLoaderRegistry.register("products", BatchCompareDataFetchers.productsForDepartmentDataLoader); GraphQL graphQL = GraphQL .newGraphQL(schema) .instrumentation(new DataLoaderDispatcherInstrumentation()) .build(); ExecutionInput executionInput = ExecutionInput.newExecutionInput() .query("query { shops { id name departments { id name products { id name } } } }") .dataLoaderRegistry(dataLoaderRegistry) .build(); ExecutionResult result = graphQL.execute(executionInput); System.out.println("\nExecutionResult: " + result.toSpecification()); }
private Object handleImpl(ExecutionResult executionResult, ServerHttpResponse serverHttpResponse) { return executionResult.toSpecification(); } }
private Object handleImpl(ExecutionResult executionResult, ServerHttpResponse serverHttpResponse) { return executionResult.toSpecification(); } }
@JsonCreator public DataMessage(@JsonProperty("id") String id, @JsonProperty("payload") ExecutionResult payload) { super(id, GQL_DATA, payload.toSpecification()); } }
@JsonCreator public DataMessage(@JsonProperty("id") String id, @JsonProperty("payload") ExecutionResult payload) { super(id, GQL_DATA, payload.toSpecification()); } }
/** * Handle POST with the "application/graphql" Content-Type header. * Treat the HTTP POST body contents as the GraphQL query string. * * * @param query a valid {@link GraphQLQueryRequest} input argument * @return {@link ExecutionResult} response * @throws IOException exception */ @PostMapping(value = PATH, consumes = APPLICATION_GRAPHQL_VALUE, produces=MediaType.APPLICATION_JSON_VALUE) public Map<String, Object> postApplicationGraphQL( @RequestBody final String query) throws IOException { return graphQLExecutor.execute(query, null) .toSpecification(); }
@GetMapping( value = "${graphql.spqr.http.endpoint:/graphql}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, headers = "Connection!=Upgrade" ) @ResponseBody public Map<String, Object> executeGet(GraphQLRequest request, HttpServletRequest raw) { ExecutionResult executionResult = graphQL.execute( input(request, raw)); return executionResult.toSpecification(); }
@GetMapping( value = "${graphql.spqr.http.endpoint:/graphql}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, headers = "Connection!=Upgrade" ) @ResponseBody public Map<String, Object> executeGet(GraphQLRequest request, HttpServletRequest raw) { ExecutionResult executionResult = graphQL.execute( input(request, raw)); return executionResult.toSpecification(); }
@PostMapping( value = "${graphql.spqr.http.endpoint:/graphql}", consumes = {"application/graphql", "application/graphql;charset=UTF-8"}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE ) @ResponseBody public Map<String, Object> executeGraphQLPost(@RequestBody String queryBody, GraphQLRequest request, HttpServletRequest raw) { String query = request.getQuery() == null ? queryBody : request.getQuery(); ExecutionResult executionResult = graphQL.execute( input(new GraphQLRequest(query, request.getOperationName(), request.getVariables()), raw)); return executionResult.toSpecification(); }
@PostMapping( value = "${graphql.spqr.http.endpoint:/graphql}", consumes = {"application/graphql", "application/graphql;charset=UTF-8"}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE ) @ResponseBody public Map<String, Object> executeGraphQLPost(@RequestBody String queryBody, GraphQLRequest request, HttpServletRequest raw) { String query = request.getQuery() == null ? queryBody : request.getQuery(); ExecutionResult executionResult = graphQL.execute( input(new GraphQLRequest(query, request.getOperationName(), request.getVariables()), raw)); return executionResult.toSpecification(); }
@PostMapping( value = "${graphql.spqr.http.endpoint:/graphql}", consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE, MediaType.APPLICATION_JSON_VALUE}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE ) @ResponseBody public Map<String, Object> executeJsonPost(@RequestBody GraphQLRequest requestBody, GraphQLRequest requestParams, HttpServletRequest raw) { String query = requestParams.getQuery() == null ? requestBody.getQuery() : requestParams.getQuery(); String operationName = requestParams.getOperationName() == null ? requestBody.getOperationName() : requestParams.getOperationName(); Map<String, Object> variables = requestParams.getVariables() == null ? requestBody.getVariables() : requestParams.getVariables(); ExecutionResult executionResult = graphQL.execute( input(new GraphQLRequest(query, operationName, variables), raw)); return executionResult.toSpecification(); }
@PostMapping( value = "${graphql.spqr.http.endpoint:/graphql}", consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE, MediaType.APPLICATION_JSON_VALUE}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE ) @ResponseBody public Map<String, Object> executeJsonPost(@RequestBody GraphQLRequest requestBody, GraphQLRequest requestParams, HttpServletRequest raw) { String query = requestParams.getQuery() == null ? requestBody.getQuery() : requestParams.getQuery(); String operationName = requestParams.getOperationName() == null ? requestBody.getOperationName() : requestParams.getOperationName(); Map<String, Object> variables = requestParams.getVariables() == null ? requestBody.getVariables() : requestParams.getVariables(); ExecutionResult executionResult = graphQL.execute( input(new GraphQLRequest(query, operationName, variables), raw)); return executionResult.toSpecification(); }