Skip to content

Commit

Permalink
fix(tests): Fixed tests, updated logo
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed Apr 21, 2018
1 parent cf8d6f7 commit 019d122
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 83 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "JS examples debug",
"program": "${workspaceFolder}/examples/authorization/index.js",
"skipFiles": ["<node_internals>/**/*.js"]
},
{
"type": "node",
"request": "launch",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p align="center"><img src="media/logo.svg" width="150" /></p>
<p align="center"><img src="media/logo.png" width="150" /></p>

# graphql-middleware

Expand Down
57 changes: 0 additions & 57 deletions examples/authorization/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions examples/logging/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { GraphQLServer } = require('graphql-yoga')
const { makeExecutableSchema } = require('graphql-tools')
const { applyFieldMiddleware } = require('graphql-middleware')
const { applyMiddleware } = require('graphql-middleware')

// Schema

Expand Down Expand Up @@ -28,7 +28,7 @@ const logMiddleware = async (resolve, parent, args, ctx, info) => {
// Server

const schema = makeExecutableSchema({ typeDefs, resolvers })
const analysedSchema = applyFieldMiddleware(schema, logMiddleware)
const analysedSchema = applyMiddleware(schema, logMiddleware)

const server = new GraphQLServer({
schema: analysedSchema,
Expand Down
50 changes: 50 additions & 0 deletions examples/permissions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { GraphQLServer } = require('graphql-yoga')
const { makeExecutableSchema } = require('graphql-tools')
const { applyMiddleware } = require('graphql-middleware')

// Schema

const code = 'supersecret'

const typeDefs = `
type Query {
open: String!
secured: String!
}
`

const resolvers = {
Query: {
open: () => `Open data, everyone's welcome!`,
secured: () => `Personal diary - this is for my eyes only!`,
},
}

// Middleware

const permissions = {
Query: {
secured: async (resolve, parent, args, ctx, info) => {
// Include your agent code as Authorization: <token> header.
const permit = ctx.request.get('Authorization') === code

if (!permit) {
throw new Error(`Not authorised!`)
}

return resolve()
},
},
}

// Server

const schema = makeExecutableSchema({ typeDefs, resolvers })
const protectedSchema = applyMiddleware(schema, permissions)

const server = new GraphQLServer({
schema: protectedSchema,
context: req => ({ ...req }),
})

server.start(() => console.log('Server is running on localhost:4000'))
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "authorization",
"name": "permissions",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
Expand Down
File renamed without changes.
Binary file added media/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion media/logo.svg

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "graphql-middleware",
"description": "GraphQL Middleware done right!",
"version": "0.0.0-semantic-release",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -29,14 +30,13 @@
"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}",
"lint":
"tslint --project tsconfig.json {src}/**/*.ts && prettier-check --ignore-path .gitignore {src,.}/{*.ts,*.js}",
"test-ava": "ava test.js --verbose",
"test": "npm run lint && npm run build && npm run test-ava",
"semantic-release": "semantic-release"
},
"files": [
"dist"
],
"files": ["dist"],
"release": {
"branch": "master"
},
Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
GraphQLFieldResolver,
GraphQLInterfaceType,
} from 'graphql'
import { mergeSchemas } from 'graphql-tools'
import { addResolveFunctionsToSchema } from 'graphql-tools'
import { IResolvers } from 'graphql-tools/dist/Interfaces'
import {
IMiddleware,
Expand Down Expand Up @@ -153,10 +153,9 @@ function addMiddlewareToSchema(
): GraphQLSchema {
const resolvers = generateResolverFromSchemaAndMiddleware(schema, middleware)

return mergeSchemas({
schemas: [schema],
resolvers,
})
addResolveFunctionsToSchema(schema, resolvers)

return schema
}

// Exposed functions
Expand Down
12 changes: 0 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ const typeMiddlewareBefore = {
const _args = { arg: 'changed' }
return resolve(parent, _args)
},
// TODO this should work without explicit implementation
Nothing: {
nothing: async (resolve, parent, args, context, info) => {
return resolve()
},
},
}

const typeMiddlewareAfter = {
Expand All @@ -113,12 +107,6 @@ const typeMiddlewareAfter = {
const res = resolve()
return 'changed'
},
// TODO this should work without explicit implementation
Nothing: {
nothing: async (resolve, parent, args, context, info) => {
return resolve()
},
},
}

// Schema Middleware
Expand Down

0 comments on commit 019d122

Please sign in to comment.