how to use GraphQL from Java?

∥☆過路亽.° 提交于 2020-01-04 02:56:29

问题


Any webservice which supports GraphQL is consumable through a Java implementation? Because "it provides an alternative to REST..."?


回答1:


Graphql-java (that you linked to) is an implementation of the GraphQL specification. As such, it is used to create GraphQL servers. A client doesn't need anything special to consume a service, just like it doesn't need anything special to consume a REST service - only to be be able to speak HTTP. You can use any generic HTTP client you like.

Still, you have some more convenient options for creating clients (but both somewhat lacking):

  1. Apollo Android - Don't let the name fool you, it's perfectly usable from normal Java. Not the most ergonomic solution, but it works.
  2. Shopify's Graphql Java Generator - Unfortunately, requires Ruby to build (not to run, of course). Generates Java classes for creating queries in a type-safe way, similar to what wsdl2java Maven plugin does for SOAP services.



回答2:


You can check the graphql-maven-plugin-project, which generates all the necessary code to make it easy to execute GraphQL requests in Java.

It's available at https://github.com/graphql-java-generator/graphql-maven-plugin-project. It's web site is https://graphql-maven-plugin-project.graphql-java-generator.com

Etienne



来源:https://stackoverflow.com/questions/50664293/how-to-use-graphql-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!