{"_id":"@baijanstack/graphql-rp-directive","_rev":"7-6d1a6979d4fd0b224c1cf80b018e6a0c","name":"@baijanstack/graphql-rp-directive","dist-tags":{"next":"0.0.4","latest":"0.0.8"},"versions":{"0.0.1":{"name":"@baijanstack/graphql-rp-directive","version":"0.0.1","author":{"name":"Baijanath Tharu"},"license":"MIT","_id":"@baijanstack/graphql-rp-directive@0.0.1","maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"dist":{"shasum":"fc82d2cc9b49219ee890b62a75f87fc6ee550634","tarball":"https://registry.npmjs.org/@baijanstack/graphql-rp-directive/-/graphql-rp-directive-0.0.1.tgz","fileCount":8,"integrity":"sha512-yM72nXhRgwUjLkR9Yfc8Rr+eVVY0TPmg/u0TbKhE8xhZBJhYiaDVnvLj0e8jMyZ4MYFwjaXO681zL+S3jYEZ6w==","signatures":[{"sig":"MEQCIF44IaApGxuqnAIjnpg/UdL1p0+ii+S0IxlLERTsLwQwAiAGmNHG8Y7c7tkkwLOjEM43NgM0DUGGTq5/DJAIg1vG1A==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1520},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"767cce82e9a8d06b9d6457c604e53011518f51dc","_npmUser":{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"},"_npmVersion":"9.5.1","description":"This is used to do authorization in graphql using directives. You can use role or permission based directive to implement the authorization using this package as per your requirements.","directories":{},"_nodeVersion":"18.16.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"tslib":"2.6.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-rp-directive_0.0.1_1688795988579_0.6513365571188023","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@baijanstack/graphql-rp-directive","version":"0.0.2","author":{"name":"Baijanath Tharu"},"license":"MIT","_id":"@baijanstack/graphql-rp-directive@0.0.2","maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"dist":{"shasum":"40876e0772f548223379ca926de2e8bf061b65e7","tarball":"https://registry.npmjs.org/@baijanstack/graphql-rp-directive/-/graphql-rp-directive-0.0.2.tgz","fileCount":8,"integrity":"sha512-aNbntM4WoqvJzxuhlyu2NcDmeyKWQQhxCUTN1cI8yg6DOsYdbF0ZNEnUBWXzp4IcsbBq85htLqX7YUdMVBdf1g==","signatures":[{"sig":"MEUCIQDLIlIzxItXhNJ9ko86kicTi7oEcyHCj5yqt7jcftDKEAIgD3RP9caejEj2XxGE6KfAjynFYgtmAaVnTfnlg/AyrLU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1519},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"767cce82e9a8d06b9d6457c604e53011518f51dc","_npmUser":{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"},"_npmVersion":"9.5.1","description":"This is used to do authorization in graphql using directives. You can use role or permission based directive to implement the authorization using this package as per your requirements.","directories":{},"_nodeVersion":"18.16.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","peerDependencies":{"tslib":"2.6.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-rp-directive_0.0.2_1688798295939_0.570044837552599","host":"s3://npm-registry-packages"}},"0.0.3":{"name":"@baijanstack/graphql-rp-directive","version":"0.0.3","author":{"name":"Baijanath Tharu"},"license":"MIT","_id":"@baijanstack/graphql-rp-directive@0.0.3","maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"dist":{"shasum":"314a314339b7aa2c8dd48e71a1264c4f8b26ba53","tarball":"https://registry.npmjs.org/@baijanstack/graphql-rp-directive/-/graphql-rp-directive-0.0.3.tgz","fileCount":8,"integrity":"sha512-EwWePRLOZtKs8Tsz0SD4LUo0JZZjAk2RFa1RftHYNbtcs0dCuJc6rsU7UtbTj4WKplYmf2POPYH9lWSz7xjKdg==","signatures":[{"sig":"MEUCIQCCcJXcrHmDhT7ol6OQKaF1ivs79OkF9n7xjbYcMsxVuwIgMfNR7VEQ9CgTM3IHqJCWREMh27r7OvGqInAyNpo+b0M=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1519},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"6aaaba15809ab45da5637d5b295274fef23a36ca","_npmUser":{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"},"_npmVersion":"9.5.1","description":"This is used to do authorization in graphql using directives. You can use role or permission based directive to implement the authorization using this package as per your requirements.","directories":{},"_nodeVersion":"18.16.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","peerDependencies":{"tslib":"2.6.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-rp-directive_0.0.3_1688805519271_0.11660434281850462","host":"s3://npm-registry-packages"}},"0.0.4":{"name":"@baijanstack/graphql-rp-directive","version":"0.0.4","author":{"name":"Baijanath Tharu"},"license":"MIT","_id":"@baijanstack/graphql-rp-directive@0.0.4","maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"dist":{"shasum":"5ef6ef8b93072c01d5feba9e188d8ce110cd0b11","tarball":"https://registry.npmjs.org/@baijanstack/graphql-rp-directive/-/graphql-rp-directive-0.0.4.tgz","fileCount":14,"integrity":"sha512-qVY4pzCxAQCuBm8Cg4Hf8PCa3rF+BIosvWRwjMTRa7D741v5o5c3SOUxULfDNYsqVisxCtwY4Wiz1p5QaGVkNg==","signatures":[{"sig":"MEYCIQD6tHT/k4oVL/KfyEBOqhUgYEc1Ru5xNMAX+QfHEPf+HgIhANn4oQmd8frCaX1+9cUPYA9xE0DLGl7STjuOazvP+gV4","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":11675},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"458266a7426151ad374532e2654626fb13761a2c","_npmUser":{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"},"_npmVersion":"9.5.1","description":"This is used to do authorization in graphql using directives. You can use role or permission based directive to implement the authorization using this package as per your requirements.","directories":{},"_nodeVersion":"18.16.0","dependencies":{"graphql":"^16.7.1","@graphql-tools/utils":"9.2.1","@graphql-tools/schema":"^10.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","peerDependencies":{"tslib":"1.14.1","apollo-server-express":"3.12.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-rp-directive_0.0.4_1688806208760_0.03402734158201004","host":"s3://npm-registry-packages"}},"0.0.5":{"name":"@baijanstack/graphql-rp-directive","version":"0.0.5","author":{"name":"Baijanath Tharu"},"license":"MIT","_id":"@baijanstack/graphql-rp-directive@0.0.5","maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"dist":{"shasum":"d74eb54ef797820d7c2ccd034956a311bbb76eef","tarball":"https://registry.npmjs.org/@baijanstack/graphql-rp-directive/-/graphql-rp-directive-0.0.5.tgz","fileCount":14,"integrity":"sha512-3Zt9nCzIwQH6CL8qfTjFc/c1Bt/PGuFAyyPCmmT9dOE5PZhMcLmbIC0swHGjBEoIUQutqikA4z7yv3OGjK9fkQ==","signatures":[{"sig":"MEYCIQDDWBnbrA5SjYbDBXPcDB5g0RfxEEeFudbFSuKZhiHJAgIhAINyjNrN2rUWzzCjQw41DN1Qm5zyCZDXbsQwBlXuU28J","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":11675},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"2876ba683c0b24add4ef65cbda8850f848c2eac7","_npmUser":{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"},"_npmVersion":"9.5.1","description":"This is used to do authorization in graphql using directives. You can use role or permission based directive to implement the authorization using this package as per your requirements.","directories":{},"_nodeVersion":"18.16.0","dependencies":{"graphql":"^16.7.1","@graphql-tools/utils":"9.2.1","@graphql-tools/schema":"^10.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"tslib":"1.14.1","apollo-server-express":"3.12.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-rp-directive_0.0.5_1688832088844_0.4994939744463964","host":"s3://npm-registry-packages"}},"0.0.6":{"name":"@baijanstack/graphql-rp-directive","version":"0.0.6","author":{"name":"Baijanath Tharu"},"license":"MIT","_id":"@baijanstack/graphql-rp-directive@0.0.6","maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"homepage":"https://github.com/baijanathTharu/baijanstack/tree/main#readme","bugs":{"url":"https://github.com/baijanathTharu/baijanstack/issues"},"dist":{"shasum":"02f7d104b8869971b07ed5d2dcac18c093b19251","tarball":"https://registry.npmjs.org/@baijanstack/graphql-rp-directive/-/graphql-rp-directive-0.0.6.tgz","fileCount":14,"integrity":"sha512-DoBAIDMrtWsM9TEfvwDCC5C+sqtcbFgVH6g0pVAQibLEYDRybGwOyJMkVO89l9NEUgbkStRnH0c2DOKptb4Txg==","signatures":[{"sig":"MEQCIAPI/+RMEdqzofrQYl+DLBhHGtvmTN1bKIPxDAHFrzEkAiAkfYeJBaD29kVTiS969DAuEW1PaL3GoBwjSfNtLLtadQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14511},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"b77a354463c6b65e009212daa85cca12814c7c32","_npmUser":{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"},"repository":{"url":"git+https://github.com/baijanathTharu/baijanstack.git#main","type":"git"},"_npmVersion":"9.5.1","description":"This is used to do authorization in graphql using directives. You can use permission based directive to implement the authorization using this package as per your requirements.","directories":{},"_nodeVersion":"18.16.0","dependencies":{"graphql":"^16.7.1","@graphql-tools/utils":"9.2.1","@graphql-tools/schema":"^10.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"tslib":"1.14.1","apollo-server-express":"3.12.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-rp-directive_0.0.6_1688832520859_0.5894268362126207","host":"s3://npm-registry-packages"}},"0.0.7":{"name":"@baijanstack/graphql-rp-directive","version":"0.0.7","author":{"name":"Baijanath Tharu"},"license":"MIT","_id":"@baijanstack/graphql-rp-directive@0.0.7","maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"dist":{"shasum":"50dfc75730eef485e424614566be353a140ab417","tarball":"https://registry.npmjs.org/@baijanstack/graphql-rp-directive/-/graphql-rp-directive-0.0.7.tgz","fileCount":14,"integrity":"sha512-JfZ+CBIgOUcazRmDKov7NmwEyge4EyBZG62e+9daLNnUo6N8NfgHBZ5kwJCgOBfb0VR19RZPX/k7q5iCrIYBaw==","signatures":[{"sig":"MEUCIQDnvCjxPQeUqHnQHBmwfD52GA022yTVolxfez3tK21DkgIgLuaBZgPSz8MY2GU++NTKQnhJv+oPXiXW2OI2ec02tyk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16527},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"2c811d2746af7481e36746f1bd45f8839aed2289","_npmUser":{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"},"_npmVersion":"10.5.0","description":"This is used to do authorization in graphql using directives. You can use permission based directive to implement the authorization using this package as per your requirements.","directories":{},"_nodeVersion":"18.20.2","dependencies":{"graphql":"^16.7.1","@graphql-tools/utils":"9.2.1","@graphql-tools/schema":"^10.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"tslib":"1.14.1","apollo-server-express":"3.12.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-rp-directive_0.0.7_1738823128541_0.9900887669007263","host":"s3://npm-registry-packages-npm-production"}},"0.0.8":{"name":"@baijanstack/graphql-rp-directive","version":"0.0.8","type":"commonjs","license":"MIT","publishConfig":{"access":"public"},"author":{"name":"Baijanath Tharu"},"dependencies":{"@graphql-tools/schema":"^10.0.0","@graphql-tools/utils":"9.2.1","graphql":"^16.7.1"},"peerDependencies":{"apollo-server-express":"3.12.0","tslib":"1.14.1"},"main":"./src/index.js","types":"./src/index.d.ts","_id":"@baijanstack/graphql-rp-directive@0.0.8","gitHead":"c9c02699a85b5660df061391f35b80307ae9226a","description":"This is used to do authorization in graphql using directives. You can use permission based directive to implement the authorization using this package as per your requirements.","_nodeVersion":"18.20.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-QMOFzPPIDP+5A1gTFXHIvbXIit04ZD79nn2iXLDIBksQssGEa1ytC8C2qsSxF4sNQMcPbSMCTRrO6Ac3Bn/wOA==","shasum":"a75ef8c97faebc043e3ea3b8fdae86dbcfc29097","tarball":"https://registry.npmjs.org/@baijanstack/graphql-rp-directive/-/graphql-rp-directive-0.0.8.tgz","fileCount":14,"unpackedSize":16527,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBrQvd4nMT9u4bh3eci/qy2fzXw6M724eNLVwuY340RPAiEAhHpJSCGXrCDrdOJMs6Kz00RCu/f9HwtTv3CZFWm6kwY="}]},"_npmUser":{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"},"directories":{},"maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/graphql-rp-directive_0.0.8_1739250032781_0.8110669884735866"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-08T05:59:48.493Z","modified":"2025-02-11T05:00:33.165Z","0.0.1":"2023-07-08T05:59:48.801Z","0.0.2":"2023-07-08T06:38:16.101Z","0.0.3":"2023-07-08T08:38:39.446Z","0.0.4":"2023-07-08T08:50:08.947Z","0.0.5":"2023-07-08T16:01:29.065Z","0.0.6":"2023-07-08T16:08:41.051Z","0.0.7":"2025-02-06T06:25:28.754Z","0.0.8":"2025-02-11T05:00:32.960Z"},"author":{"name":"Baijanath Tharu"},"license":"MIT","description":"This is used to do authorization in graphql using directives. You can use permission based directive to implement the authorization using this package as per your requirements.","maintainers":[{"name":"baijanaththaru","email":"bnchaudhary.tharu@gmail.com"}],"readme":"# graphql-rp-directive\n\nThis is used to do authorization in graphql using directives. You can use permission based directive to implement the authorization using this package as per your requirements.\n\n## Usage\n\n1. Install the dependency.\n\n```bash\nnpm install @baijanstack/graphql-rp-directive\n```\n\n2. Update your typedefs with the necessary directive.\n\n```ts\nconst typedefs = gql`\n  directive @hasPermission(permissions: [String!]) on FIELD_DEFINITION | OBJECT\n\n  # your other typedefs\n  # ...\n`;\n```\n\n3. Create your role and permission data.\n\n> Note: If you have static role and permission, you can create the role and permission object as below: However, if you have dynamic role and permissions, you can pass it from the context like we pass the user object.\n\n```ts\nimport { getAuthorizedSchema, TRolePermission } from '@baijanstack/graphql-rp-directive';\n\nconst rolePermissionsData: TRolePermission = {\n  ADMIN: {\n    permissions: ['READ_SECURE_DATA', 'READ_RESTRICTED_FIELD', 'READ_MUTATION_RESPONSE', 'CREATE_FIELD'],\n  },\n  PUBLIC: {\n    permissions: ['READ_MUTATION_RESPONSE'],\n  },\n};\n```\n\n4. Create your executable schema with your typedefs and resolvers.\n\n```ts\nconst schema = makeExecutableSchema({\n  typeDefs,\n  resolvers,\n});\n```\n\n5. Add the permission directives to your schema.\n\n```ts\nconst schemaWithPermissionDirective = getAuthorizedSchema(schema, {\n  rolePermissionsData,\n});\n```\n\n6. Pass `schemaWithPermissionDirective` as schema to your graphql server and return the `user` object from the context.\n\n> Note: If you have a dynamic role and permissions, you have to pass the dynamic `roleAndPermission` object of type `TRolePermission` as shown below. The dynamic permissions take priority than the static permission if you passed both of them.\n\n```ts\nconst server = new ApolloServer<{\n  user: {\n    roles: Array<string>;\n  };\n  roleAndPermission?: TRolePermission;\n}>({\n  schema: schemaWithPermissionDirective,\n  context: {\n    user: {\n      roles: ['PUBLIC'],\n    },\n    // This context can be async function and you can pass the `roleAndPermission`\n    // by quering your database or reading from cache.\n    roleAndPermission: {\n      ADMIN: {\n        permissions: ['READ_SECURE_DATA', 'READ_RESTRICTED_FIELD', 'READ_MUTATION_RESPONSE', 'CREATE_FIELD'],\n      },\n      PUBLIC: {\n        permissions: ['READ_MUTATION_RESPONSE'],\n      },\n    },\n  },\n});\n```\n\n7. By default, all your resolvers request will be denied unless you specify the directive on the field or object.\n\n8. Apply directives to your typedefs.\n\n```ts\nconst typeDefs = `\ndirective @hasPermission(permissions: [String!]) on FIELD_DEFINITION | OBJECT\n\ntype Query {\n  # this api will be denied request because it is missing the directive\n  publicFields: PublicField\n  restrictedFields: RestrictedField @hasPermission(permissions: [\"READ_RESTRICTED_FIELD\"])\n  secureFields: SecureField @hasPermission(permissions: [\"READ_SECURE_DATA\"])\n}\n\ntype PublicField {\n  name: String!\n}\n\ntype RestrictedField {\n  name: String!\n}\n\ntype SecureField @hasPermission(permissions: [\"READ_SECURE_DATA\"]) {\n  name: String!\n  email: String!\n}\n\ntype Mutation {\n  createFields(id: Int!): MutationResponse! @hasPermission(permissions: [\"CREATE_FIELD\"])\n}\n\ntype MutationResponse @hasPermission(permissions: [\"READ_MUTATION_RESPONSE\"]) {\n  done: Boolean!\n}\n`;\n```\n","readmeFilename":"README.md"}