Skip to content

Commit

Permalink
fix(beta): First beta
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed Apr 20, 2018
1 parent 6b2ff4e commit cf8d6f7
Show file tree
Hide file tree
Showing 5 changed files with 1,491 additions and 47 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<p align="center"><img src="media/logo.png" width="800" /></p>
<p align="center"><img src="media/logo.svg" width="150" /></p>

# graphql-middleware

[![CircleCI](https://circleci.com/gh/graphcool/graphql-middleware.svg?style=shield)](https://circleci.com/gh/graphcool/graphql-middleware)
[![npm version](https://badge.fury.io/js/graphql-middleware.svg)](https://badge.fury.io/js/graphql-middleware)
![npm](https://img.shields.io/npm/dt/graphql-middleware.svg)

All in one solution to manage middleware in your GraphQL projects.

Expand All @@ -25,7 +24,7 @@ yarn add graphql-middleware
## Usage

```ts
import { applyFieldMiddleware } from 'graphql-middleware'
import { applyMiddleware } from 'graphql-middleware'
import { makeExecutableSchema } from 'graphql-tools'
import { authMiddleware, metricsMiddleware } from './middlewares'

Expand Down Expand Up @@ -55,7 +54,7 @@ const resolvers = {

const schema = makeExecutableSchema({ typeDefs, resolvers })

const schemaWithFieldMiddlewares = applyFieldMiddleware(
const schemaWithMiddleware = applyMiddleware(
schema,
metricsMiddleware,
authMiddleware,
Expand Down Expand Up @@ -85,8 +84,8 @@ const resolvers = {
const server = new GraphQLServer({
typeDefs,
resolvers,
fieldMiddlewares: [authMiddleware, metricsMiddleware],
documentMiddlewares: [],
fieldMiddleware: [authMiddleware, metricsMiddleware],
documentMiddleware: [],
})
server.start(() => console.log('Server is running on localhost:4000'))
```
Expand All @@ -98,27 +97,27 @@ server.start(() => console.log('Server is running on localhost:4000'))
A middleware is a resolver function that wraps another resolver function.

```ts
type IFieldMiddlewareFunction = (
type IMiddlewareFunction = (
resolve: Function,
parent: any,
args: any,
context: any,
info: GraphQLResolveInfo,
) => Promise<any>

interface IFieldMiddlewareTypeMap {
[key: string]: IFieldMiddlewareFunction | IFieldMiddlewareFieldMap
interface IMiddlewareTypeMap {
[key: string]: IMiddlewareFunction | IMiddlewareFieldMap
}

interface IFieldMiddlewareFieldMap {
[key: string]: IFieldMiddlewareFunction
interface IMiddlewareFieldMap {
[key: string]: IMiddlewareFunction
}

type IFieldMiddleware = IFieldMiddlewareFunction | IFieldMiddlewareTypeMap
type IMiddleware = IMiddlewareFunction | IMiddlewareTypeMap

function applyFieldMiddleware(
function applyMiddleware(
schema: GraphQLSchema,
...middlewares: IFieldMiddleware[]
...middlewares: IMiddleware[]
): GraphQLSchema
```

Expand Down
Binary file removed media/logo.png
Binary file not shown.
1 change: 1 addition & 0 deletions media/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"prettier": "^1.11.1",
"prettier-check": "^2.0.0",
"rimraf": "^2.6.2",
"semantic-release": "^15.1.7",
"tslint": "^5.9.1",
"tslint-config-prettier": "^1.10.0",
"tslint-config-standard": "^7.0.0",
Expand All @@ -30,7 +31,8 @@
"build": "rm -rf dist && tsc -d",
"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"
"test": "npm run lint && npm run build && npm run test-ava",
"semantic-release": "semantic-release"
},
"files": [
"dist"
Expand Down
Loading

0 comments on commit cf8d6f7

Please sign in to comment.