Skip to content

maticzav/graphql-middleware-forward-binding

Repository files navigation

graphql-middleware-forward-binding

CircleCI npm version

GraphQL Middleware plugin for forwarding request to GraphQL Bindings.

Usage

With GraphQL Yoga and Prisma

import { GraphQLServer } from 'graphql-yoga'
import { forward } from 'graphql-middleware-forward-binding'
import { Prisma } from 'prisma-binding'

const bindingForwardMiddleware = forward('Query', 'Mutation.createBasket')('db')

const server = GraphQLServer({
  typeDefs: 'generated-schema.graphql',
  resolvers: {},
  middlewares: [bindingForwardMiddleware],
  context: req => ({
    ...req,
    db: new Prisma({
      endpoint: 'https://eu1.prisma.sh/public-saberbow/prisma-yoga/dev',
      debug: true,
    }),
  }),
})

serve.start(() => `Server running on http://localhost:4000`)

API

function forward(types: string[])(database: string): IMiddleware

License

MIT @ Matic Zavadlal