Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :

query EntryDetailQuery($repoFullName: String!) {
  entry(repoFullName: $repoFullName) {
    id
    repository {
      full_name
      description
      owner {
          login
      }
    }
    postedBy {
      login
    }
  }
}

two :

just request full_name

query EntryDetailQuery($repoFullName: String!) {
  entry(repoFullName: $repoFullName) {
    id
    repository {
      full_name

    }
  }
}

in fact, i would to get dynamic querys with Java

is it possible?

like image 961
Farshid roohi Avatar asked Apr 27 '26 13:04

Farshid roohi


1 Answers

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);
like image 173
Dhruv Avatar answered Apr 30 '26 04:04

Dhruv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!