Giter VIP home page Giter VIP logo

ktutnik / graphql-directive Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 157 KB

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

TypeScript 100.00%
authorization directive graphql graphql-directive typescript validation validator

graphql-directive's People

Contributors

ktutnik avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

graphql-directive's Issues

Validator custom message

Its should be possible to provide custom message on validator like @validate(method: EMAIL, message: "Email tidak valid")

Custom validation (async)

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")
}

Authorization directive

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 }) 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.