简体   繁体   English

用java动态查询graphql apollo

[英]dynamic query graphql apollo with java

The routine of working with the graphql apollo is that add file query .graphql使用graphql apollo的例程是添加文件查询.graphql

i would create dynamic query with java and i do not create file for each query我会用java创建动态查询,我不会为每个查询创建文件

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事实上,我想用Java获取动态查询

is it possible?是否可以?

It is possible to use dynamic queries with Apollo and Java.可以在 Apollo 和 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.使用graphql查询构建相应的java文件后,只需在查询中使用setter提供动态参数并将查询提供给回调即可。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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