|
| 1 | +## Run below commands for the installing the required packages |
| 2 | +- npm install --save graphql |
| 3 | +- npm install --save-dev typescript ts-node |
| 4 | +- npm install @actions/github |
| 5 | + |
| 6 | +### Generating types from Github Graphql Schema |
| 7 | +* Run below commands |
| 8 | +``` |
| 9 | +npm install --save-dev @octokit/graphql-schema @graphql-codegen/cli |
| 10 | +
|
| 11 | +npx graphql-codegen init |
| 12 | +
|
| 13 | +``` |
| 14 | +* After you run above statement, select below options for setup- |
| 15 | + - What type of application are you building? ◉ Backend - API or server |
| 16 | + - Where is your schema?: src/generated/github-schema-loader.ts |
| 17 | + - Pick plugins: |
| 18 | + ◉ TypeScript (required by other typescript plugins) |
| 19 | + ◉ TypeScript Resolvers (strongly typed resolve functions) |
| 20 | + ◯ TypeScript MongoDB (typed MongoDB objects) |
| 21 | + ❯◉ TypeScript GraphQL document nodes (embedded GraphQL document) |
| 22 | + - Where to write the output: (src/generated/graphql.ts) |
| 23 | + - Do you want to generate an introspection file? (Y/n) n |
| 24 | + - How to name the config file? (codegen.yml) |
| 25 | + - What script in package.json should run the codegen? codegen |
| 26 | +* Run these commands |
| 27 | +``` |
| 28 | +npm install |
| 29 | +
|
| 30 | +npm install --save @apollo/client cross-fetch |
| 31 | +
|
| 32 | +npm install --save-dev @graphql-codegen/typescript-operations |
| 33 | +
|
| 34 | +npm run codegen |
| 35 | +
|
| 36 | +``` |
| 37 | +If there is error in generating the codegen with above command, pls copy/paste this code in codegen.yml file and rerun the command ``` npm run codegen``` |
| 38 | + |
| 39 | + ``` |
| 40 | + # codegen.yml |
| 41 | +overwrite: true |
| 42 | +schema: "src/generated/github-schema-loader.ts" |
| 43 | +generates: |
| 44 | + src/generated/graphql.ts: |
| 45 | + plugins: |
| 46 | + - "typescript" |
| 47 | + - "typescript-resolvers" |
| 48 | + - "typescript-document-nodes" |
| 49 | + - "typescript-operations" |
| 50 | +
|
| 51 | +require: |
| 52 | + - ts-node/register |
| 53 | +
|
| 54 | +documents: |
| 55 | + - src/queries/*.graphql |
| 56 | + - src/mutations/*.graphql |
| 57 | + ``` |
| 58 | + |
| 59 | +### Updating schema |
| 60 | +* Run this command - ```npm update @octokit/graphql-schema``` |
| 61 | + |
| 62 | +Once schema is updated, rerun the command to update codegen file -``` npm run codegen``` |
| 63 | + |
| 64 | +## Testing with Jest framework |
| 65 | +* Install by running this - ```npm install --save-dev jest``` |
| 66 | +- Add following to your Package.json |
| 67 | + |
| 68 | +` |
| 69 | +{ |
| 70 | + "scripts": { |
| 71 | + "test": "jest" |
| 72 | + } |
| 73 | +} |
| 74 | +` |
| 75 | +* Finish the setup by running these - |
| 76 | + |
| 77 | +``` |
| 78 | +npm install --save-dev ts-jest |
| 79 | +
|
| 80 | +npm install --save-dev @jest/globals |
| 81 | +
|
| 82 | +npm install --save-dev @types/jest |
| 83 | +
|
| 84 | +npx ts-jest config:init |
| 85 | +``` |
0 commit comments