@gr2m/express-github-stitch
v1.0.4
Published
express plugin for stitching GitHub’s GraphQL API
Downloads
14
Maintainers
Readme
express-github-stitch
express plugin for stitching GitHub’s GraphQL API
Install
npm install @gr2m/express-github-stitch
Usage
const express = require('express')
const app = express()
const stitchGithub = require('@gr2m/express-github-stitch')
const schema = `
extend type User {
foo: String
}
`
const resolvers = mergeInfo => ({
User: {
foo: {
// define requirements for resolver, in this case url + login
fragment: `fragment UserFragment on User { websiteUrl, login }`,
// resolve the `twitter` property
async resolve (parent, args, context, info) {
return 'bar'
}
}
}
})
app.use(stitchGithub({schema, resolvers}))
app.listen(3000)
You can now send a query to localhost:3000
curl http://localhost:3000/ \
-XPOST \
-H"Authorization: bearer <your token here>" \
-H"Content-Type: application/json" \
-d '{"query":"{ viewer { foo } }"}'
Which returns something like this
{"data":{"viewer":{"foo":"bar"}}}
You can use the GraphiQL app to send
queries. Don’t forget to set the Authorization
header to bearer <your token here>
.
How it works
express-github-stitch
is based on Apollo’s GraphQL Tools for Schema Stitching