如何使用Graphql SPQR实现查询过滤器和排序?

时间:2020-09-24 05:09:54

标签: graphql graphql-java graphql-spqr

如何使用Graphql SPQR实现查询过滤器和排序?

我正在寻找使用Graphql SPQR解决方案的解决方案,该方案如下所示。

app.listen(port, () => console.log(`Running on port ${port}`))

1 个答案:

答案 0 :(得分:0)

GraphQL SPQR依赖于代码优先方法。您需要创建Java类和解析器并正确注释它们:

public enum SortOrder {
  @GraphQLEnumValue(name = "ASC") ASC,
  @GraphQLEnumValue(name = "DESC") DESC
}

public class Article {
  //Article implementation here
}

public class Feedback {
  //Feedback implementation here
}

public class GraphQLResolver {

  @GraphQLQuery(name = "getAllArticles", description = "Search articles")
  public List<Article> getAllArticles(
    @NotNull @GraphQLArgument(name = "pageNumber") int pageNumber, 
    @NotNull @GraphQLArgument(name = "pageSize") int pageSize, 
    @NotNull @GraphQLArgument(name = "sortOrder") SortOrder sortOrder, 
    @NotNull @GraphQLArgument(name = "sortBy") String sortBy) {
    //Query implementation here
  }

  //implement other queries and mutation 
}

按照https://github.com/leangen/graphql-spqr的自述文件公开您的graphql解析器。