Skip to content

Commit

Permalink
Generator docs
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed Jul 9, 2018
1 parent a19f3af commit 6070367
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,26 @@ interface IMiddlewareFieldMap {

type IMiddleware = IMiddlewareFunction | IMiddlewareTypeMap

function middleware(
generator: (schema: GraphQLSchema) => IMiddleware,
): MiddlewareGenerator

function applyMiddleware(
schema: GraphQLSchema,
...middleware: IMiddleware[]
...middleware: (IMiddleware | MiddlewareGenerator)[]
): GraphQLSchema
```

### Middleware Generator

In some cases, your middleware could depend on how your schema looks. In such situations, you can turn your middleware into a middleware generator. Middleware generators are denoted with function `middleware` and receive `schema` as the first argument.

```ts
const schemaDependentMiddleware = middleware(schema => {
return generateMiddlewareFromSchema(schema)
})
```

## GraphQL Middleware Use Cases

* Logging
Expand Down

0 comments on commit 6070367

Please sign in to comment.