brave / ads-ui

Self-service ads UI
Mozilla Public License 2.0
22 stars 11 forks source link

refactor: switch to use graphqlcodegen client-preset #1173

Closed tackley closed 4 months ago

tackley commented 4 months ago

As we use on other internal projects, use the client-preset for codegen. This means we can more easily:

I've tried to be mechanical about the changes here, limiting changes to just what was needed.

github-actions[bot] commented 4 months ago

[puLL-Merge] - brave/ads-ui@1173

Here is my review of the pull request:

Description

This PR migrates the queries and mutations used throughout the frontend codebase to be generated from a central location using GraphQL Codegen. This removes the need to manually update types and query/mutation hooks in multiple locations whenever the GraphQL schema changes.

Changes ### Changes - Added `src/graphql-client/gql.ts` which contains the generated GraphQL document nodes, fragment docs, query/mutation functions and types - Added `src/graphql-client/graphql.ts` which contains the generated GraphQL types - Updated all usages of the old manually generated GraphQL files under `src/graphql/` to instead import from the new `src/graphql-client/` files - Removed the old `src/graphql/` directory containing the manually generated files - Updated `codegen.ts` config to generate the new files under `src/graphql-client/` - Added `src/graphql-client/` to `.gitattributes` and `.prettierignore` to mark the generated files

Security Hotspots

This change does not introduce any new security vulnerabilities. It simply changes how the GraphQL types and operations are generated and imported in the codebase.

The generated files under src/graphql-client/ should not be manually edited, as noted by the linguist-generated attribute. This properly communicates that developers should not make changes directly in those files.

The biggest risk would be if the central codegen.ts config that controls the generation was misconfigured in a way that caused invalid or incomplete types/operations to be generated. However, this risk is low and would likely be caught quickly in development.