This project is a human-friendly library used to implement the concept GraphQL Schema Stitching. The goal is to stitch together multiple GraphQL schema in a flash.
A use case could be the need to abstract multiple heterogeneous datasources through a single GraphQL endpoint. This is commonly encountered in large microservices architecture.
- NodeJS
- NPM
npm install graphql-stitcher
const stitcher = new GraphQLStitcher();
// "countries" public API
const countrySchema = await stitcher.loadRemoteSchema('https://countries.trevorblades.com');
// Github API
const githubSchema = await stitcher.loadRemoteSchema('https://api.github.com/graphql', {
headers: { authorization: `Bearer ${process.env.STRIPE_TOKEN}`, },
});
// Local GraphQL schema
const dbSchema = stitche.loadLocalSchema(__dirname + '/graphql');
// Stitch!
const schema = stitcher.stitch();
// … … …
// Example with ApolloServer
const server = new ApolloServer({ schema });
A complete example can be found in the example/ directory.
.loadRemoteSchema(string uri, object opts) -> Promise
-
uri: the remote location of the GraphQL remote schema. Example:
'https://api.github.com/graphql'
-
opts: (optional) a Javascript Object to pass more options to the HTTP request that will fetch the GraphQL schema. Most of the time, it is used to pass authentication details. Example:
{ headers: { authorization: `Bearer ${process.env.STRIPE_TOKEN}` }}
.loadLocalSchema(string directory) -> Object
The loadLocalSchema
function automatically import all files specified under the parameter passed as an argument directory
. Each file should respect the following syntax:
module.exports = function () {
this.getSchema = function () {
};
this.getResolver = function () {
};
}
A complete example can be found in the example/ directory.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature)
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request
This project is currently maintained by Forest Admin. Don't hesitate to join the Slack community if you have any questions: http://community.forestadmin.com