Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GraphQL Orchestrator stitches the schemas from multiple micro-services and orchestrates the graphql queries to these services accurately at runtime

License

NotificationsYou must be signed in to change notification settings

graph-quilt/graphql-orchestrator-java

graphql-orchestrator-java

A powerful Java library for aggregating and executing GraphQL operations from multiple microservices using a single unified schema.

Master BuildBuilds

Introduction

graphql-orchestrator-java simplifies the process of accessing data from various GraphQL microservices by providing a unified GraphQL schema.This enables you to query multiple microservices through a single endpoint, reducing complexity and improving performance.

The library supports two strategies to aggregate and combine the schemas from multiple microservices

At query execution time, it orchestrates the GraphQL queries to the appropriate micro-services, using the populargraphql-javalibrary as the execution engine.

Features

Getting Started

Dependency

<dependency>    <groupId>com.intuit.graphql</groupId>    <artifactId>graphql-orchestrator-java</artifactId>    <version>${graphql.orchestrator.version}</version></dependency>

Usage in code

  • Implement the ServiceProvider interface. You will need a new instance for each GraphQL Service.

Consider the following 2 service providers below

classPersonNameServiceimplementsServiceProvider {publicstaticfinalStringschema ="type Query { person: Person } "       +"type Person { firstName : String lastName: String }";@OverridepublicStringgetNameSpace() {return"PERSON_NAME"; }@OverridepublicMap<String,String>sdlFiles() {returnImmutableMap.of("schema.graphqls",schema); }@OverridepublicCompletableFuture<Map<String,Object>>query(finalExecutionInputexecutionInput,finalGraphQLContextcontext) {//{'data':{'person':{'firstName':'GraphQL Orchestrator', 'lastName': 'Java'}}}"Map<String,Object>data =ImmutableMap        .of("data",ImmutableMap.of("person",ImmutableMap.of("firstName","GraphQL Orchestrator","lastName","Java")));returnCompletableFuture.completedFuture(data);  }}
classPersonAddressServiceimplementsServiceProvider {publicstaticfinalStringschema ="type Query { person: Person }"      +"type Person { address : Address }"      +"type Address { city: String state: String zip: String}";@OverridepublicStringgetNameSpace() {return"PERSON_ADDRESS";}@OverridepublicMap<String,String>sdlFiles() {returnImmutableMap.of("schema.graphqls",schema);}@OverridepublicCompletableFuture<Map<String,Object>>query(finalExecutionInputexecutionInput,finalGraphQLContextcontext) {//{'data':{'person':{'address':{ 'city' 'San Diego', 'state': 'CA', 'zip': '92129' }}}}"Map<String,Object>data =ImmutableMap        .of("data",ImmutableMap.of("person",ImmutableMap.of("address",ImmutableMap.of("city","San Diego","state","CA","zip","92129"))));returnCompletableFuture.completedFuture(data);  }}
  • Create an instance of Orchestrator and execute the query as below.
// create a runtimeGraph by stitching service providersRuntimeGraphruntimeGraph =SchemaStitcher.newBuilder()        .service(newPersonNameService())           .service(newPersonAddressService())          .build()        .stitchGraph();// pass the runtime graph to GraphQLOrchestratorGraphQLOrchestratorgraphQLOrchestrator =GraphQLOrchestrator.newOrchestrator()        .runtimeGraph(runtimeGraph).build();//Execute the queryCompletableFuture<ExecutionResult>execute =graphQLOrchestrator        .execute(ExecutionInput.newExecutionInput()              .query("query {person {firstName lastName address {city state zip}}}")              .build()        );ExecutionResultexecutionResult =execute.get();System.out.println(executionResult.getData().toString());// Output:// {person={firstName=GraphQL Orchestrator, lastName=Java, address={city=San Diego, state=CA, zip=92129}}}

The Orchestrator uses a recursive algorithm to combine the schemas from multiple services and generate the following unified schema.

typeQuery {person:Person }typePerson {firstName:StringlastName:Stringaddress:Address}typeAddress {city:Stringstate:Stringzip:String}

Graph Quilt Gateway

Graph Quilt Gateway is a SpringBoot application that uses the graphql-orchestrator-java.

Documentation

DetailedDocumentation can be found here

Contributing

If you are interested in contributing to this project, please read theCONTRIBUTING.md file for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see theLICENSE file for details.

Acknowledgments

  • Thanks to the contributors of thegraphql-java library.
  • Thanks to the contributors of this project for their hard work and dedication.

About

GraphQL Orchestrator stitches the schemas from multiple micro-services and orchestrates the graphql queries to these services accurately at runtime

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors16


[8]ページ先頭

©2009-2025 Movatter.jp