Skip to content

Commit

Permalink
feat(core): Nilan has an idea! (added support for nested selection)
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed Jun 14, 2018
1 parent e580c1c commit 30bfb4a
Show file tree
Hide file tree
Showing 5 changed files with 1,975 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { GraphQLServer } from 'graphql-yoga'
import { forward } from 'graphql-middleware-forward-binding'
import { Prisma } from 'prisma-binding'

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

const server = GraphQLServer({
typeDefs: 'generated-schema.graphql',
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "graphql-middleware-forward-binding",
"description": "GraphQL Binding forwardTo plugin for GraphQL Middleware",
"version": "0.0.0-semantic-release",
"files": ["dist"],
"files": [
"dist"
],
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"typescript": {
Expand All @@ -11,18 +13,20 @@
"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",
"lint": "tslint --project tsconfig.json {src}/**/*.ts && prettier-check --ignore-path .gitignore {src,.}/{*.ts,*.js}",
"test": "npm run lint && npm run build && ava",
"semantic-release": "semantic-release"
},
"author": "Matic Zavadlal <[email protected]>",
"dependencies": {
"dot-prop": "^4.2.0",
"graphql-binding": "^2.0.0",
"graphql-middleware": "^1.2.3"
},
"devDependencies": {
"@types/dot-prop": "^4.2.0",
"@types/node": "^10.1.2",
"ava": "^0.25.0",
"graphql": "^0.13.2",
"prettier": "^1.12.1",
"prettier-check": "^2.0.0",
Expand Down
9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IMiddleware } from 'graphql-middleware'
import { forwardTo } from 'graphql-binding'
import { set } from 'dot-prop'

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

const middleware = types.reduce(
(_types, type) => ({
..._types,
[type]: fn,
}),
{},
)
const middleware = types.reduce((_types, type) => set(_types, type, fn), {})

return middleware
}
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import test from 'ava'
import { forwardTo } from 'graphql-binding'
import { forward } from './dist'

test('Constructs tree correctly', async t => {
const tree = forward('Query', 'Mutation.foo', 'Mutation.bar')('db')

t.deepEqual(Object.keys(tree), ['Query', 'Mutation'])
t.is(typeof tree.Query, 'function')
t.deepEqual(Object.keys(tree.Mutation), ['foo', 'bar'])
})
Loading

0 comments on commit 30bfb4a

Please sign in to comment.