feat(core): generate TypeScript types from the GraphQL queries - #475
feat(core): generate TypeScript types from the GraphQL queries#475marcalexiei wants to merge 7 commits into
Conversation
|
@marcalexiei is attempting to deploy a commit to the martin-mfg's projects Team on Vercel. A member of the Team first needs to authorize it. |
9b1d028 to
5ccd96c
Compare
|
5ccd96c to
7aadeac
Compare
|
The guide recommends Three things moved this PR off it:
This costs a 253-line script and one post-process (dropping the P.S.: I reverted the WakaTime card migration. |
martin-mfg
left a comment
There was a problem hiding this comment.
I have only looked at generate-graphql-types.js so far:
marcalexiei
left a comment
There was a problem hiding this comment.
I've addressed your feedback and made additional changes:
- JSDoc for types
- banner on top of each generated file
- dependabot group for the new deps
| // pages after the first refetch only `repositories`, a subset of the stats query | ||
| const document = ( | ||
| variables.after ? UserReposDocument : UserInfoDocument | ||
| ) as GraphQLDocument<UserInfoQuery, UserInfoQueryVariables>; |
There was a problem hiding this comment.
Could we avoid this cast?
As far as I can tell, the cast is not correct, although currently it's not a problem in practice, because of how we use fetcher. Would it make sense to return Promise<GraphQLResponse<UserInfoQuery | UserReposQuery>> instead?
There was a problem hiding this comment.
- One fetcher per query, no more cast:
all four GraphQL fetchers are built bycreateGraphQLFetcher(document, scheme)incommon/http.ts, which absorbedhttpGraphQLRequest. FETCH_MULTI_PAGE_STARSis parsed once inconfig.ts:"true": every page,- a positive number: cap
- anything else: one page.
- The pagination loop accumulates extra pages and clones/merges once; a null or non-advancing cursor stops it.
A failing later page returns the first page's data with that page'serrorsandstatusText. - New tests: a numeric page limit with real cursor advancement, and an error on a page after the first.
The queries moved to
src/graphql/queries/*.graphqland their types are generated fromGitHub's schema instead of hand-written.
scripts/generate-graphql-types.jsvalidates each query against@octokit/graphql-schemaand writes one file per query plus a sharedcommon.ts,so a wrong field fails generation and a wrong variable fails
tsc.pnpm check-graphql-typesruns in CI, so the generated types can't drift.httpGraphQLRequesttakes a generated document: the four*QueryResponseinterfaces are gone andGRAPHQL_REPOS_FIELDis a real fragment.Untyped
requeststays exported for the backend, with a TODO for considering its removal.ownerandfiles[].name,user,repositories.nodes);Lang.coloris nullable againparseOwnerAffiliationsreturns the schema'sRepositoryAffiliation.graphqlstays on 16:@octokit/graphql-schemaneeds^16.Warning
The four
apps/backendcontract snapshots were refreshed:the recorded request text changed, the rendered SVGs did not.