{"_id":"@asanovr/nestjs-graphql-request","name":"@asanovr/nestjs-graphql-request","dist-tags":{"latest":"0.2.0"},"versions":{"0.2.0":{"name":"@asanovr/nestjs-graphql-request","version":"0.2.0","description":"Badass utilities for integrating graphql-request and NestJS","author":{"name":"Jesse Carter","email":"jesse.r.carter@gmail.com"},"homepage":"https://github.com/golevelup/nestjs#readme","license":"MIT","keywords":["NestJS","graphql-request","sdk","codegen","graphql","gql"],"main":"lib/index.js","typings":"lib/index.d.ts","directories":{"lib":"lib","test":"__tests__"},"repository":{"type":"git","url":"git+https://github.com/asanovr/nestjs.git"},"scripts":{"build":"tsc --build tsconfig.build.json","build:watch":"tsc --build tsconfig.build.json --watch","test":"jest"},"bugs":{"url":"https://github.com/golevelup/nestjs/issues"},"publishConfig":{"access":"public"},"dependencies":{"@golevelup/nestjs-common":"^2.0.1","@golevelup/nestjs-discovery":"^4.0.1","@golevelup/nestjs-modules":"^0.7.1","graphql":"^15.6.1","graphql-request":"^3.5.0"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src","testRegex":".spec.ts$","transform":{"^.+\\.ts$":"ts-jest"},"coverageDirectory":"../coverage","testEnvironment":"node"},"gitHead":"83abc8861cf5f8df94b8cd39964f41ce728aff6d","_id":"@asanovr/nestjs-graphql-request@0.2.0","_nodeVersion":"16.15.1","_npmVersion":"lerna/3.22.1/node@v16.15.1+arm64 (darwin)","dist":{"integrity":"sha512-HyvjlLf1gE3aQVt1I+RD+6iITybFsn4c/QBogcrZog7rlEmEjprtN618EoXnWlba4VgU3X3aaA5ySn4+EpglzA==","shasum":"7414d2892d831f160fb493bf27602dff34f4bb0c","tarball":"https://registry.npmjs.org/@asanovr/nestjs-graphql-request/-/nestjs-graphql-request-0.2.0.tgz","fileCount":20,"unpackedSize":19130,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCEgdMqwA8sELgL7V+YBVsnjLDOzdFfdoTmUnjjUf+9SAIgMK9GEfvwwL0xueX+JEjHEYotPjEDGxgcNiPMaJZ+xrw="}]},"_npmUser":{"name":"asanovr","email":"bioforge91@gmail.com"},"maintainers":[{"name":"asanovr","email":"bioforge91@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-graphql-request_0.2.0_1693545916407_0.8818640956426678"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-01T05:25:16.267Z","0.2.0":"2023-09-01T05:25:16.611Z","modified":"2023-09-01T05:25:16.949Z"},"maintainers":[{"name":"asanovr","email":"bioforge91@gmail.com"}],"description":"Badass utilities for integrating graphql-request and NestJS","homepage":"https://github.com/golevelup/nestjs#readme","keywords":["NestJS","graphql-request","sdk","codegen","graphql","gql"],"repository":{"type":"git","url":"git+https://github.com/asanovr/nestjs.git"},"author":{"name":"Jesse Carter","email":"jesse.r.carter@gmail.com"},"bugs":{"url":"https://github.com/golevelup/nestjs/issues"},"license":"MIT","readme":"# @golevelup/nestjs-graphql-request\n\n<p align=\"center\">\n<a href=\"https://www.npmjs.com/package/@golevelup/nestjs-graphql-request\"><img src=\"https://img.shields.io/npm/v/@golevelup/nestjs-graphql-request.svg?style=flat\" alt=\"version\" /></a>\n<a href=\"https://www.npmjs.com/package/@golevelup/nestjs-graphql-request\"><img alt=\"downloads\" src=\"https://img.shields.io/npm/dt/@golevelup/nestjs-graphql-request.svg?style=flat\"></a>\n<img alt=\"license\" src=\"https://img.shields.io/npm/l/@golevelup/nestjs-graphql-request.svg\">\n</p>\n\n## Description\n\nThis library provides the `GraphQLRequestModule` which makes it easy to initialize an instance of `GraphQLClient` for use in Depdendency Injection. This can be combined with automatic codegen for type safe access to third party GQL APIs from your Nest services\n\n## Usage\n\n### Install\n\n`npm install ---save @golevelup/nestjs-graphql-request`\n\nor\n\n`yarn add @golevelup/nestjs-graphql-request`\n\n### Import\n\nImport and add `GraphQLRequestModule` to the `imports` section of the consuming module.\n\n```typescript\nimport { GraphQLRequestModule } from '@golevelup/nestjs-graphql-request';\n\n@Module({\n  imports: [\n    GraphQLRequestModule.forRoot(GraphQLRequestModule, {\n      // Exposes configuration options based on the graphql-request package\n      endpoint: config.get('endpoint'),\n      options: {\n        headers: {\n          'content-type': 'application/json',\n          'x-hasura-admin-secret': config.get('secret'),\n        },\n      },\n    }),\n  ],\n})\nexport class AppModule {\n  // ...\n}\n```\n\n### Inject the GraphQLClient\n\nTo make GraphQL requests from your controllers or services use the provided decorator `@InjectGraphQLClient`.\n\n```typescript\nimport { InjectGraphQLClient } from '@golevelup/nestjs-graphql-request';\nimport { GraphQLClient } from 'graphql-request';\n\n@Injectable()\nexport class ExampleService {\n  constructor(@InjectGraphQLClient() private readonly client: GraphQLClient) {}\n}\n```\n\n### Typesafe GraphQL Access\n\nThe GraphQL client works best when combined with GraphQL code generation tools for communicating to a GraphQL endpoint. Follow the [GraphQL Code Generator GraphQL Request Plugin Instructions](https://graphql-code-generator.com/docs/plugins/typescript-graphql-request).\n\nRunning the code generator against a GraphQL Endpoint will produce typescript interfaces for all operations and types exposed by the API as well as a `getSdk` function which you can use in conjunction with GraphQL Request to get intellisense and type saftey for all requests you make. The `getSdk` function only requires a GraphQLClient instance (which this library provides). However because each generated SDK is unique per endpoint, it's up to you to wire up the provider for this in your application. This can be done using a Provider Factory with minimal code.\n\n```typescript\nimport {\n  GraphQLRequestModule,\n  GraphQLClientInject,\n} from '@golevelup/nestjs-graphql-request';\nimport { getSdk } from './your-codegen-location';\n\n@Module({\n  imports: [\n    GraphQLRequestModule.forRoot(GraphQLRequestModule, {\n      // Exposes configuration options based on the graphql-request package\n      endpoint: config.get('endpoint'),\n      options: {\n        headers: {\n          'content-type': 'application/json',\n          'x-hasura-admin-secret': config.get('secret'),\n        },\n      },\n    }),\n  ],\n  providers: [\n    {\n      // you can provide whatever key you want. use it in conjunction with @Inject(\"TypeSafeGqlSdk\") to get the SDK instance in your controllers/services\n      provide: 'TypeSafeGqlSdk',\n      inject: [GraphQLClientInject],\n      useFactory: (client: GraphQLClient) => getSdk(client),\n    },\n  ],\n})\nexport class AppModule {\n  // ...\n}\n```\n\n## Contribute\n\nContributions welcome! Read the [contribution guidelines](../../CONTRIBUTING.md) first.\n\n## License\n\n[MIT License](../../LICENSE)\n","readmeFilename":"README.md"}