-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL Binding forward to middleware
- Loading branch information
0 parents
commit 6aed918
Showing
9 changed files
with
2,534 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dist | ||
node_modules | ||
|
||
.DS_Store | ||
*.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.