Created
May 10, 2018 14:49
-
-
Save gc-codesnippets/fd258f14fcd7f6386a8b1a62d8b1a8be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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