View Code? Open in Web Editor
NEW
Offers a collection of GraphQL directives for easy validation, authorization, and sanitation, simplifying the implementation of complex functionality in GraphQL APIs. It ensures secure and efficient GraphQL APIs with pre-built solutions.
License: MIT License
graphql-directive's People
Contributors
Watchers
graphql-directive's Issues
Its should be possible to provide custom message on validator like @validate(method: EMAIL, message: "Email tidak valid")
missing tests:
REGEX
SLUG
STRONG_PASSWORD
Should be possible to provide custom validator.
Custom validator is an async function returns Promise<true | string>
. Registered on transformer function.
const customValidator = {
customOne : async ( parent , arg , ctx , info ) => { } ,
customTwo : async ( parent , arg , ctx , info ) => { }
}
const schema = transform ( schema , { customValidator } ) ;
usage
type MyType {
propOne : String ! @validate (method : CUSTOM , impl : " customOne" )
propTwo : String ! @validate (method : CUSTOM , impl : " customTwo" )
}
Provide lightweight authorization directive
import auth from `@graphql-directive/authorization`
const typeDefs = `
type Mutation {
addUser(user:UserInput!): Boolean! @authorize(policy: "admin")
}
`
const policies = {
admin : async ( parent , arg , ctx , info ) => ctx . user . role === "admin"
}
const schema = auth . transform ( execSchema , { policies } )