Skip to content

Instantly share code, notes, and snippets.

@suciuvlad
Last active July 14, 2018 11:14
Show Gist options
  • Select an option

  • Save suciuvlad/b5bab2cc48c1c995bcfb0abed6c39622 to your computer and use it in GitHub Desktop.

Select an option

Save suciuvlad/b5bab2cc48c1c995bcfb0abed6c39622 to your computer and use it in GitHub Desktop.
graphql-microservices-example
import { introspectSchema, makeRemoteExecutableSchema, mergeSchemas } from 'graphql-tools';
import { createHttpLink } from 'apollo-link-http';
import fetch from 'node-fetch';
const createSchema = async () => {
const movieServiceLink = createHttpLink({
uri: `https://w5vwzkn9zz.lp.gql.zone/graphql`,
fetch
});
const cosmicJsServiceLink = createHttpLink({
uri: `https://graphql.cosmicjs.com/v1`,
fetch
});
const createCosmicJsServiceSchema = async () => {
const schema = await introspectSchema(cosmicJsServiceLink);
return makeRemoteExecutableSchema({
schema,
link: cosmicJsServiceLink
});
}
const createMovieServiceSchema = async () => {
const schema = await introspectSchema(movieServiceLink);
return makeRemoteExecutableSchema({
schema,
link: movieServiceLink
});
}
const movieServiceSchema = await createMovieServiceSchema();
const cosmicJsServiceSchema = await createCosmicJsServiceSchema();
return mergeSchemas({
schemas: [movieServiceSchema, cosmicJsServiceSchema]
});
}
export const schema = createSchema();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment