leangen / graphql-spqr

Build a GraphQL service in seconds
Apache License 2.0
1.09k stars 179 forks source link

How to use executionResult data #473

Closed yashb042 closed 8 months ago

yashb042 commented 9 months ago

I have been trying to get the values of the custom headers I send from the client request. Upon checking the code, the header value is available till the execution function, i.e., @PostMapping(value = "/graphql", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Map<String, Object> indexFromAnnotated(@RequestBody Map<String, String> request, HttpServletRequest raw) { ExecutionResult executionResult = graphQL.execute(ExecutionInput.newExecutionInput() .query(request.get("query")) .operationName(request.get("operationName")) .context(raw) .build()); return executionResult.toSpecification(); }

Now, my query let's say is mapped to the following function `@GraphQLQuery(name = "firstNPersons") public List getFirstNPersons(@GraphQLArgument(name = "count") int count) { List result = new ArrayList<>();

    Person p1 = new Person();
    p1.setFirstName("John");
    p1.setLastName("Doe");
    result.add(p1);

    Person p2 = new Person();
    p2.setFirstName("Jane");
    p2.setLastName("Doe");
    result.add(p2);

    return result.stream().limit(count).collect(Collectors.toList());
}`

How do I get the executionResult variable in my GraphQLQuery.

I have skimmed through the documentation and issues, but not able to find the answer.

On a side note, we are thinking of integrating one of our major services to graphQL, only some APIs. So, I stumbled across this project. Looks like the project is using the standard GraphQL specification, but still there's lesser community involvement. Should we go ahead with the library or rather implement graphQL from scratch. As I see it, the only benefit this library is giving is to generate the schema file automatically.

yashb042 commented 9 months ago

Okay, I was able to find the executionResult, well specifically headers in my use-case

Screenshot 2023-09-08 at 2 56 18 PM

Is is the best way?

yashb042 commented 8 months ago

The above mentioned way works. Closing it