Skip to content Skip to sidebar Skip to footer

Dynamic Query Graphql Apollo With Java

The routine of working with the graphql apollo is that add file query .graphql i would create dynamic query with java and i do not create file for each query example querys : one :

Solution 1:

It is possible to use dynamic queries with Apollo and Java. After building the corresponding java files using graphql queries, just provide the dynamic parameters in the query using setter and provide the query to the callback.

      EntryDetailQuery productListQuery = EntryDetailQuery.builder().repoFullName("test_repo").build();

      ApolloCall.Callback<EntryDetailQuery.Data> callback = new ApolloCall.Callback<EntryDetailQuery.Data>() {

        @Override
        public void onResponse(@Nonnull Response<EntryDetailQuery.Data> response) {
            logger.debug("Response from graphql:" + response);
        }

        @Override
        public void onFailure(@Nonnull ApolloException e) {
            logger.error("Error in getting response from graphql:" + e.getMessage());
        }
    };

    apolloGraphQlClient.getApolloClient().query(productListQuery).enqueue(callback);

Post a Comment for "Dynamic Query Graphql Apollo With Java"