Skip to content

Commit 97c4b70

Browse files
committed
patch(doc): decribe the visitAllArgs factory method
1 parent 3df358e commit 97c4b70

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ npm install graphql-middleware-typed-arguments
1010

1111
## Overview
1212

13-
`graphql-middleware-typed-arguments` lets you wrap a function around field arguments of any type. The classic example is GraphQLUpload type in conjunction with Apollo Upload Server. Now, also, you can attach an inspection function to any type of query argument.
13+
`graphql-middleware-typed-arguments` lets you wrap a function around field arguments of any type. The classic example is GraphQLUpload type in conjunction with Apollo Upload Server. Now, also, you can attach an inspection function to any type of query argument, such as complicated validation of telephone numbers or delivery addresses where fields of the input object type depend upon each other in complex ways. And there's more: you can also produce middleware to visit all field arguments regardless of type.
1414

1515
## Features
1616

@@ -114,13 +114,22 @@ server.listen(() => {
114114
## API
115115

116116
```ts
117-
interface IConfig<V, T> {
117+
interface ITypeConfig<V, T> {
118118
type: GraphQLType | string
119119
transform: (value: V, root: any, args: {}, context: any, info: GraphQLResolveInfo) => Promise<T>
120120
}
121121

122122
export const processTypeArgs<V, T> = (
123-
config: IConfig<V, T>
123+
config: ITypeConfig<V, T>
124+
): IMiddleware
125+
126+
interface IConfig {
127+
// behave yourself here: the visitor should change type very carefully, such as dereferencing to validate an ID
128+
visitor: (value: any, root: any, args: {}, context: any, info: GraphQLResolveInfo) => Promise<any>
129+
}
130+
131+
export const visitAllArgs = (
132+
config: IConfig
124133
): IMiddleware
125134

126135
// input and output types are up to you, just provide the transform function

0 commit comments

Comments
 (0)