GraphQL Middleware Typed Arguments lets you define a processor function to massage, validate, authorize, or whatever your query, mutation, or field arguments of a certain type. The middleware was originally developed as GraphQL Middleware Apollo Upload Server, which wonderfully separated streaming uploaded media to its ultimate destination from other concerns.
npm install graphql-middleware-typed-arguments
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.
- 👌 Easy to use.
- 🛴 Half automatic.
- 🏆 Works with every GraphQL server.
The example is taken directly from graphql-middleware-apollo-upload-server which was basis for this generalization. There are two changes from the original: the GraphQLUpload type object is imported, but the type name "Upload" could be used as well. (In fact, type names are simpler way to get at a type defined in SDL.) The second change is providing the type (object or string) to the middleware factory function provided by this package:
processTypeArgs. (The previous version's
upload method has been preseved and implemented as a special case.)
// Note that the visitor and transform functions receive all four resolver args (parent, args, context, & info),// For these functions, info.argument has been set to refer to the relevant argument definition.// input and output types are up to you, just provide the transform function
MIT @ Homeroom