问题
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?
回答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);
来源:https://stackoverflow.com/questions/51608768/dynamic-query-graphql-apollo-with-java