{"id":23197791,"url":"https://github.com/ktutnik/graphql-directive","last_synced_at":"2025-06-25T17:08:49.537Z","repository":{"id":98912052,"uuid":"604864041","full_name":"ktutnik/graphql-directive","owner":"ktutnik","description":"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.","archived":false,"fork":false,"pushed_at":"2023-04-09T12:30:08.000Z","size":157,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T22:55:35.504Z","etag":null,"topics":["authorization","directive","graphql","graphql-directive","typescript","validation","validator"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ktutnik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["ktutnik"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-02-22T00:15:56.000Z","updated_at":"2024-06-30T19:59:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"c46f2e23-7872-4028-a6af-7002a9116d3d","html_url":"https://github.com/ktutnik/graphql-directive","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"3caddf916428147603bca4642b2e92e5b6a431d1"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/ktutnik/graphql-directive","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktutnik%2Fgraphql-directive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktutnik%2Fgraphql-directive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktutnik%2Fgraphql-directive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktutnik%2Fgraphql-directive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktutnik","download_url":"https://codeload.github.com/ktutnik/graphql-directive/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktutnik%2Fgraphql-directive/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260346855,"owners_count":22995146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authorization","directive","graphql","graphql-directive","typescript","validation","validator"],"created_at":"2024-12-18T14:37:25.986Z","updated_at":"2025-06-25T17:08:49.505Z","avatar_url":"https://github.com/ktutnik.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ktutnik"],"categories":[],"sub_categories":[],"readme":"# Comprehensive List Of GraphQL Directives\n[![Node.js CI](https://github.com/ktutnik/graphql-directive/actions/workflows/test.yml/badge.svg)](https://github.com/ktutnik/graphql-directive/actions/workflows/test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/ktutnik/graphql-directive/badge.svg?branch=master)](https://coveralls.io/github/ktutnik/graphql-directive?branch=master)\n\nOffers 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.\n\n## Validator.js Directive\nRefer to the [project documentation](./packages/validator/readme.md) for more detail documentation.\n\nValidation directives simplify the use of popular JavaScript validator libraries inside your GraphQL API. The main goal is to ensure that validation results are consistent across client-side and server-side applications. \n\n### Usage\nValidation method wrapped into a single directive `@validate(method: METHOD[, PARAMETERS])`. \n\n```graphql\nconst typeDefs = `\n    input UserInput {\n        name: String!   @validate(method: LENGTH, min:1, max: 150)\n        email: String!  @validate(method: EMAIL)\n    }\n    type Mutation { \n        addUser(user:UserInput!): Boolean!\n    }\n`\n```\n\nIn order to use the `@validate` directive, you must transform the GraphQL schema using the provided transform function like below.\n\n```typescript\nimport val from \"@graphql-directive/validator\"\nimport { makeExecutableSchema } from \"@graphql-tools/schema\"\n\nconst schema = val.transform(makeExecutableSchema({\n    typeDefs: [\n        val.typeDefs, // @validate type definition\n        typeDefs      // your type definition\n    ],\n    resolvers: { /* resolvers */ }\n}))\n```\n\nThe transform function returns a GraphQL schema, which can be used directly with some GraphQL servers, such as Apollo Server.\n\n## Authorization Directive\nRefer to the [project documentation](./packages/auth/readme.md) for more detail documentation.\n\nThe authorization directive is a library that allows you to easily secure your GraphQL API by defining authorization policies. It simplifies your code and makes it easier to review by applying policies at the field or argument level.\n\n## Usage\n\nAuthorization method wrapped into single directive `@authorize(policy: \"list, of, policy\")` like example below.\n\n```graphql\nconst typeDefs = `\n    input UserInput {\n        name: String!   \n        email: String! \n        role: String   @authorize(policy: \"Admin\")\n    }\n\n    type User {\n        id: String!\n        name: String!   \n        email: String! @authorize(policy: \"Authenticated\")\n        role: String   @authorize(policy: \"Admin\")\n    }\n\n    type Query {\n        users: [User]!\n    }\n\n    type Mutation { \n        addUser(\n            user:UserInput!\n        ): Boolean!\n\n        editUser(\n            id:String!, \n            user:UserInput!\n        ): Boolean!    @authorize(policy: \"Authenticated\")\n    }\n`\n```\n\nDefine each policy logic like below\n\n```typescript\nimport auth, { PolicyFunction } from \"@graphql-directive/auth\"\nimport { makeExecutableSchema } from \"@graphql-tools/schema\"\n\nconst policies: Record\u003cstring, PolicyFunction\u003e = {\n    admin: ({ contextValue }) =\u003e contextValue.user.role === \"admin\",\n    isLogin: ({ contextValue }) =\u003e !!contextValue.user\n}\n\nconst schema = auth.createTransformer({ policies })(makeExecutableSchema({\n    typeDefs: [auth.typeDefs, typeDefs],\n    resolvers: {\n        /* list of resolvers */\n    }\n}))\n```\n\n`contextValue` is a context that is passed from the server. Its the same value that is passed by the third parameter of GraphQL resolver.\n\nThe transform function returns a GraphQL schema, which can be used directly with some GraphQL servers, such as Apollo Server.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktutnik%2Fgraphql-directive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktutnik%2Fgraphql-directive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktutnik%2Fgraphql-directive/lists"}