Example GraphQL server using graphql-braid to stitch separate schemas together from "microservices".
$ ./mvnw spring-boot:runTested on Java 11.
graphql-braid has a few undocumented concepts, I'll do my best to describe them below.
The schema provider is responsible for returning a Reader representing the GraphQL SDL. In this example I wanted to provide those schemas from remote servers. As a result, I had to:
- Make an introspection request to my remote server (both cases use Apollo Launchpad)
- Parse the result as JSON and pass the
datavalue to graphql-java'sIntrospectionResultToSchema - Print the resulting
Documentand then feed theStringtoStringReader
At the end of those steps I had a valid Supplier<Reader> that provided the GraphQL schema as represented by the server.
Braid allows for two kinds of "retrievers": local or remote. Again, in my example I wanted to use a remote retriever. The implementation of the GraphQLRemoteRetriever interface is to actually make the HTTP call to the remote server by parsing the query and variables from the ExecutionInput.
Once the remote server responds, you can parse the JSON to an Object and return the completed future.
To expose types underneath stitched schemas, you can provide a list of "links". You basically tell Braid to expose a field in a top-level query (e.g. user nested in order) and Braid will make a bulk request to your users service.
I also added in rejoiner to stitch together a Grpc microserver into the GraphQL API. You can run the PaymentServer class to start the Grpc server and you'll notice the payment field available in GraphiQL.
Currently, not a fan of the naming on the input or payload types.