I'm trying to write a java-graphql client using Netflix DGS. In the developer documentation, the following sample code is given for generating query using classes generated with DGS codegen.
GraphQLQueryRequest graphQLQueryRequest =
new GraphQLQueryRequest(
new TicksGraphQLQuery.Builder()
.first(first)
.after(after)
.build(),
new TicksConnectionProjectionRoot()
.edges()
.node()
.date()
.route()
.name()
.votes()
.starRating()
.parent()
.grade());
Here all the fields to be queried are given in the code itself, using TicksConnectionProjectionRoot.
But if I want to query 15-20 fields with many nested types then it will be tiresome. Is there any way to generate the graphql request or a projection like this using a .graphql file containing the grapqhl query and fields needed.
If it is your junit test then I would suggest to use DgsQueryExecutor directly.
query.txtcontains actual graph query string the client sends via http request.DgsQueryExecutor has various methods to suit most of testing needs.
If calling via http then you can use
MonoGraphQLClientand pass your query string directly.queryis string and you can read it from resource. More about client can be found at https://netflix.github.io/dgs/advanced/java-client/ and https://fullstackcode.dev/2022/02/10/java-graphql-client-using-netflix-dgs-framework/