Skip to content

Commit

Permalink
fix(types): Export IMiddleware, language in README and code
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed Apr 22, 2018
1 parent b26433b commit a16d3a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ yarn add graphql-middleware
```ts
import { applyMiddleware } from 'graphql-middleware'
import { makeExecutableSchema } from 'graphql-tools'
import { authMiddleware, metricsMiddleware } from './middlewares'
import { authMiddleware, metricsMiddleware } from './middleware'

// Minimal example middleware (before & after)
const beepMiddleware = {
Query: {
hello: async (resolve, parent, args, context, info) => {
// You can you middlewares to override arguments
// You can you middleware to override arguments
const argsWithDefault = { name: 'Bob', ...args }
const result = await resolve(parent, argsWithDefault, context, info)
// Or change the returned values of resolvers
Expand Down Expand Up @@ -68,7 +68,7 @@ const schemaWithMiddleware = applyMiddleware(
```ts
import { GraphQLServer } from 'graphql-yoga'
import { authMiddleware, metricsMiddleware } from './middlewares'
import { authMiddleware, metricsMiddleware } from './middleware'

const typeDefs = `
type Query {
Expand Down Expand Up @@ -117,7 +117,7 @@ type IMiddleware = IMiddlewareFunction | IMiddlewareTypeMap

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

Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
IMiddlewareFieldMap,
} from './types'

export { IMiddleware }

// Type checks

function isMiddlewareFunction(obj: any): boolean {
Expand Down Expand Up @@ -162,9 +164,9 @@ function addMiddlewareToSchema(

export function applyMiddleware(
schema: GraphQLSchema,
...middlewares: IMiddleware[]
...middleware: IMiddleware[]
): GraphQLSchema {
const schemaWithMiddleware = middlewares.reduce(
const schemaWithMiddleware = middleware.reduce(
(currentSchema, middleware) =>
addMiddlewareToSchema(currentSchema, middleware),
schema,
Expand Down

0 comments on commit a16d3a5

Please sign in to comment.