Skip to content

Commit e580c1c

Browse files
committed
feat(core): Type definitions, Renovate
1 parent caf35b6 commit e580c1c

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
> GraphQL Middleware plugin for forwarding request to GraphQL Bindings.
77
8-
```bash
9-
yarn add graphql-middleware-forward-binding
10-
```
11-
128
## Usage
139

1410
> With GraphQL Yoga and Prisma
@@ -18,10 +14,11 @@ import { GraphQLServer } from 'graphql-yoga'
1814
import { forward } from 'graphql-middleware-forward-binding'
1915
import { Prisma } from 'prisma-binding'
2016

21-
const bindingForwardMiddleware = forward('db')
17+
const bindingForwardMiddleware = forward('Query', 'Mutation')('db')
2218

2319
const server = GraphQLServer({
2420
typeDefs: 'generated-schema.graphql',
21+
resolvers: {},
2522
middlewares: [bindingForwardMiddleware],
2623
context: req => ({
2724
...req,
@@ -38,7 +35,7 @@ serve.start(() => `Server running on http://localhost:4000`)
3835
## API
3936

4037
```ts
41-
function forward(database: string): IMiddleware
38+
function forward(types: string[])(database: string): IMiddleware
4239
```
4340

4441
## License

renovate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": ["config:base", "docker:disable"],
3+
"packageRules": {
4+
"rangeStrategy": "bump"
5+
}
6+
}

src/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import { IMiddleware } from 'graphql-middleware'
22
import { forwardTo } from 'graphql-binding'
33

4-
export const forward = (database: string): IMiddleware => {
4+
export const forward = (...types: string[]) => (
5+
database: string,
6+
): IMiddleware => {
57
if (!database) {
68
throw new Error(`Missing database name.`)
79
}
810

9-
return async function(resolve, parent, args, ctx, info) {
11+
if (!types) {
12+
throw new Error(`Missing forwarded types list.`)
13+
}
14+
15+
const fn = async function(resolve, parent, args, ctx, info) {
1016
return forwardTo(database)(parent, args, ctx, info)
1117
}
18+
19+
const middleware = types.reduce(
20+
(_types, type) => ({
21+
..._types,
22+
[type]: fn,
23+
}),
24+
{},
25+
)
26+
27+
return middleware
1228
}

0 commit comments

Comments
 (0)