-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codegen): change to use
.graphql
file
Considering migration from a project already using codegen, I would like to handle typed-document-node from a `.graphql` extension file. It is possible to generate TypedDocumentNode from a `.graphql` extension file, and although it is possible to import them at the point of use, importing from /src/gql/graphql again leads to an increase in file chunks after bundling. Therefore, it attempts to split the file using the near-operation-file preset. Even for TypedDocumentNode imported from a split file, type conversion by fragment-masking was possible.
- Loading branch information
Showing
14 changed files
with
72 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as Types from '~/gql/graphql'; | ||
|
||
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; | ||
export const FilmItemFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FilmItem"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Film"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"releaseDate"}},{"kind":"Field","name":{"kind":"Name","value":"producers"}}]}}]} as unknown as DocumentNode<Types.FilmItemFragment, unknown>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fragment FilmItem on Film { | ||
id | ||
title | ||
releaseDate | ||
producers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as Types from '~/gql/graphql'; | ||
|
||
import { graphql, ResponseResolver, GraphQLRequest, GraphQLContext } from 'msw' | ||
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; | ||
import { FilmItemFragmentDoc } from './FilmItem.generated'; | ||
|
||
/** | ||
* @param resolver a function that accepts a captured request and may return a mocked response. | ||
* @see https://mswjs.io/docs/basics/response-resolver | ||
* @example | ||
* mockAllFilmsQueryQuery((req, res, ctx) => { | ||
* const { first, last } = req.variables; | ||
* return res( | ||
* ctx.data({ allFilms }) | ||
* ) | ||
* }) | ||
*/ | ||
export const mockAllFilmsQueryQuery = (resolver: ResponseResolver<GraphQLRequest<Types.AllFilmsQueryQueryVariables>, GraphQLContext<Types.AllFilmsQueryQuery>, any>) => | ||
graphql.query<Types.AllFilmsQueryQuery, Types.AllFilmsQueryQueryVariables>( | ||
'allFilmsQuery', | ||
resolver | ||
) | ||
|
||
|
||
export const AllFilmsQueryDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"allFilmsQuery"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"last"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"allFilms"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"last"},"value":{"kind":"Variable","name":{"kind":"Name","value":"last"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"FilmItem"}}]}}]}}]}}]}},...FilmItemFragmentDoc.definitions]} as unknown as DocumentNode<Types.AllFilmsQueryQuery, Types.AllFilmsQueryQueryVariables>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
query allFilmsQuery($first: Int!, $last: Int!) { | ||
allFilms(first: $first, last: $last) { | ||
edges { | ||
node { | ||
...FilmItem | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters