问题
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):
- Apollo Android - Don't let the name fool you, it's perfectly usable from normal Java. Not the most ergonomic solution, but it works.
- 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