简体   繁体   中英

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM