javarestgraphqlgraphql-java

how to use GraphQL from Java?


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


Solution

  • 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.

    But! There is a number of dedicated GraphQL clients that make it more convenient (copied from my other answer):

    1. Spring's GraphQL client - Dynamic client (with optional response-to-POJO mapping)
    2. SmallRye GraphQL - Offers both a dynamic and a typesafe client
    3. Netflix DGS client - Has both a simple and a type-safe client
    4. Apollo Kotlin - Generates Kotlin and Java models from GraphQL queries.
    5. There's a Node based Java client generator and a Maven plugin for it too.
    6. Nodes
    7. Shopify's GraphQL code gen - Needs (J)Ruby to run but generates Java code.
    8. Manifold can be used as a GraphQL client

    These are all different beasts, as you'll see, so you'll have to decide what fits.