Skip to content

Instantly share code, notes, and snippets.

@gc-codesnippets
Created May 10, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gc-codesnippets/fd258f14fcd7f6386a8b1a62d8b1a8be to your computer and use it in GitHub Desktop.
Save gc-codesnippets/fd258f14fcd7f6386a8b1a62d8b1a8be to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = require('path')
const fetch = require('node-fetch')
const { Binding } = require('graphql-binding')
const { HttpLink } = require('apollo-link-http')
const { makeRemoteExecutableSchema } = require('graphql-tools')
class RemoteBinding extends Binding {
constructor({ typeDefsPath, endpoint }) {
const link = new HttpLink({ uri: endpoint, fetch })
const typeDefs = fs.readFileSync(
path.join(__dirname, typeDefsPath),
'utf-8',
)
const schema = makeRemoteExecutableSchema({ link, schema: typeDefs })
super({ schema })
}
}
module.exports = RemoteBinding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment