Skip to content

Commit 30bfb4a

Browse files
committed
feat(core): Nilan has an idea! (added support for nested selection)
1 parent e580c1c commit 30bfb4a

File tree

5 files changed

+1975
-49
lines changed

5 files changed

+1975
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { GraphQLServer } from 'graphql-yoga'
1414
import { forward } from 'graphql-middleware-forward-binding'
1515
import { Prisma } from 'prisma-binding'
1616

17-
const bindingForwardMiddleware = forward('Query', 'Mutation')('db')
17+
const bindingForwardMiddleware = forward('Query', 'Mutation.createBasket')('db')
1818

1919
const server = GraphQLServer({
2020
typeDefs: 'generated-schema.graphql',

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"name": "graphql-middleware-forward-binding",
33
"description": "GraphQL Binding forwardTo plugin for GraphQL Middleware",
44
"version": "0.0.0-semantic-release",
5-
"files": ["dist"],
5+
"files": [
6+
"dist"
7+
],
68
"main": "dist/index.js",
79
"typings": "dist/index.d.ts",
810
"typescript": {
@@ -11,18 +13,20 @@
1113
"scripts": {
1214
"prepublish": "npm run test",
1315
"build": "rm -rf dist && tsc -d",
14-
"lint":
15-
"tslint --project tsconfig.json {src}/**/*.ts && prettier-check --ignore-path .gitignore {src,.}/{*.ts,*.js}",
16-
"test": "npm run lint && npm run build",
16+
"lint": "tslint --project tsconfig.json {src}/**/*.ts && prettier-check --ignore-path .gitignore {src,.}/{*.ts,*.js}",
17+
"test": "npm run lint && npm run build && ava",
1718
"semantic-release": "semantic-release"
1819
},
1920
"author": "Matic Zavadlal <matic.zavadlal@gmail.com>",
2021
"dependencies": {
22+
"dot-prop": "^4.2.0",
2123
"graphql-binding": "^2.0.0",
2224
"graphql-middleware": "^1.2.3"
2325
},
2426
"devDependencies": {
27+
"@types/dot-prop": "^4.2.0",
2528
"@types/node": "^10.1.2",
29+
"ava": "^0.25.0",
2630
"graphql": "^0.13.2",
2731
"prettier": "^1.12.1",
2832
"prettier-check": "^2.0.0",

src/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IMiddleware } from 'graphql-middleware'
22
import { forwardTo } from 'graphql-binding'
3+
import { set } from 'dot-prop'
34

45
export const forward = (...types: string[]) => (
56
database: string,
@@ -16,13 +17,7 @@ export const forward = (...types: string[]) => (
1617
return forwardTo(database)(parent, args, ctx, info)
1718
}
1819

19-
const middleware = types.reduce(
20-
(_types, type) => ({
21-
..._types,
22-
[type]: fn,
23-
}),
24-
{},
25-
)
20+
const middleware = types.reduce((_types, type) => set(_types, type, fn), {})
2621

2722
return middleware
2823
}

test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import test from 'ava'
2+
import { forwardTo } from 'graphql-binding'
3+
import { forward } from './dist'
4+
5+
test('Constructs tree correctly', async t => {
6+
const tree = forward('Query', 'Mutation.foo', 'Mutation.bar')('db')
7+
8+
t.deepEqual(Object.keys(tree), ['Query', 'Mutation'])
9+
t.is(typeof tree.Query, 'function')
10+
t.deepEqual(Object.keys(tree.Mutation), ['foo', 'bar'])
11+
})

0 commit comments

Comments
 (0)