Skip to content

Commit

Permalink
GraphQL Binding forward to middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed May 25, 2018
0 parents commit 6aed918
Show file tree
Hide file tree
Showing 9 changed files with 2,534 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
jobs:
build:
docker:
- image: 'circleci/node:latest'
steps:
- checkout
- run:
name: install
command: npm install
- run:
name: test
command: npm test
- run:
name: release
command: npm run semantic-release || true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node_modules

.DS_Store
*.log*
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# graphql-middleware-forward-binding

[![CircleCI](https://circleci.com/gh/maticzav/graphql-middleware-forward-binding.svg?style=shield)](https://circleci.com/gh/maticzav/graphql-middleware-forward-binding)
[![npm version](https://badge.fury.io/js/graphql-middleware-forward-binding.svg)](https://badge.fury.io/js/graphql-middleware-forward-binding)

> GraphQL Middleware plugin for forwarding request to GraphQL Bindings.
## Usage

> With GraphQL Yoga and Prisma
```ts
import { GraphQLServer } from 'graphql-yoga'
import { forward } from 'graphql-middleware-forward-binding'
import { Prisma } from 'prisma'

const typeDefs = `
type Query {
hello: String!
bug: String!
}
`

const bindingForwardMiddleware = forward('db')

const server = GraphQLServer({
typeDefs,
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

```ts
function forward(database: string): IMiddleware
```

## License

MIT @ Matic Zavadlal
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "graphql-middleware-forward-binding",
"description": "GraphQL Binding forwardTo plugin for GraphQL Middleware",
"version": "0.0.0-semantic-release",
"files": ["dist"],
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
},
"scripts": {
"prepublish": "npm run test",
"build": "rm -rf dist && tsc -d",
"lint":
"tslint --project tsconfig.json {src}/**/*.ts && prettier-check --ignore-path .gitignore {src,.}/{*.ts,*.js}",
"test": "npm run lint && npm run build",
"semantic-release": "semantic-release"
},
"author": "Matic Zavadlal <[email protected]>",
"dependencies": {
"graphql-binding": "^2.0.0",
"graphql-middleware": "^1.2.3"
},
"devDependencies": {
"@types/node": "^10.1.2",
"prettier": "^1.12.1",
"prettier-check": "^2.0.0",
"semantic-release": "^15.5.0",
"tslint": "^5.10.0",
"tslint-config-prettier": "^1.13.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.8.3"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/maticzav/graphql-middleware-forward-binding.git"
}
}
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IMiddleware } from 'graphql-middleware'
import { forwardTo } from 'graphql-binding'

export const forward = (database: string): IMiddleware => {
if (!database) {
throw new Error(`Missing database name.`)
}

return async function(resolve, parent, args, ctx, info) {
return forwardTo(database)(parent, args, ctx, info)
}
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"rootDir": "./src",
"outDir": "./dist",
"sourceMap": true,
"lib": ["dom", "es2017", "esnext.asynciterable"],
"experimentalDecorators": true
},
"exclude": ["node_modules", "examples"]
}
7 changes: 7 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["tslint-config-standard", "tslint-config-prettier"],
"rules": {
"no-use-before-declare": false,
"space-before-function-paren": false
}
}
Loading

0 comments on commit 6aed918

Please sign in to comment.