express plugin for stitching GitHub’s GraphQL API
npm install @gr2m/express-github-stitch
> express plugin for stitching GitHub’s GraphQL API
``bash`
npm install @gr2m/express-github-stitch
`js
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 },twitter
// resolve the 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
`bash`
curl http://localhost:3000/ \
-XPOST \
-H"Authorization: bearer
-H"Content-Type: application/json" \
-d '{"query":"{ viewer { foo } }"}'
Which returns something like this
`json`
{"data":{"viewer":{"foo":"bar"}}}
You can use the GraphiQL app to send
queries. Don’t forget to set the Authorization header to bearer .
express-github-stitch` is based on Apollo’s GraphQL Tools for Schema Stitching