@gr2m/express-github-stitch

1.0.4 • Public • Published

express-github-stitch

Greenkeeper badge

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

License

MIT

Package Sidebar

Install

npm i @gr2m/express-github-stitch

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

5.22 kB

Total Files

5

Last publish

Collaborators

  • gr2m