- #10073
8471a18
Thanks @n1ru4l! - Reduce noise of generated code by only generating code relevant to GraphQL operations.
-
#10075
67e7556
Thanks @n1ru4l! - Add note about enabling bundle size reduction for the generatedgraphql
tag file. -
Updated dependencies [
67e7556
,3f4f546
]:- @graphql-codegen/gql-tag-operations@4.0.10
- @graphql-codegen/visitor-plugin-common@5.4.0
- @graphql-codegen/typescript-operations@4.3.0
- @graphql-codegen/typescript@4.1.0
- @graphql-codegen/typed-document-node@5.0.10
- #9817
7ac42a3
Thanks @nikitalocalhost! - Resolve runtime error when using the babel plugin within an ESM environment.
- Updated dependencies [
79fee3c
]:- @graphql-codegen/visitor-plugin-common@5.3.1
- @graphql-codegen/gql-tag-operations@4.0.9
- @graphql-codegen/typescript-operations@4.2.3
- @graphql-codegen/typed-document-node@5.0.9
- @graphql-codegen/typescript@4.0.9
- Updated dependencies [
808ada5
,14ce39e
]:- @graphql-codegen/visitor-plugin-common@5.3.0
- @graphql-codegen/gql-tag-operations@4.0.8
- @graphql-codegen/typescript-operations@4.2.2
- @graphql-codegen/typed-document-node@5.0.8
- @graphql-codegen/typescript@4.0.8
-
#10001
1be6e65
Thanks @n1ru4l! - Support discriminatingnull
andundefined
within theuseFragment
function.function MyComponent(props: FragmentType<typeof MyFragment> | null) { const data = useFragment(MyFragment, props) // data is `MyFragment | null` } function MyComponent(props: FragmentType<typeof MyFragment> | undefined) { const data = useFragment(MyFragment, props) // data is `MyFragment | undefined` }
Before, the returned type from
useFragment
was alwaysTType | null | undefined
. -
#9804
5e594ef
Thanks @rachel-church! - PreservingArray<T>
orReadonlyArray<T>
inuseFragment()
return type.
-
#9996
99f449c
Thanks @nahn20! - Added configuration to allow for custom hash functions for persisted documents in the client presetimport { type CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { schema: 'schema.graphql', documents: ['src/**/*.tsx'], generates: { './src/gql/': { preset: 'client', presetConfig: { persistedDocuments: { hashAlgorithm: operation => { const shasum = crypto.createHash('sha512') shasum.update(operation) return shasum.digest('hex') } } } } } }
-
Updated dependencies [
5501c62
]:- @graphql-codegen/add@5.0.3
- Updated dependencies [
dfc5310
,156cc2b
,dfc5310
,b49457b
]:- @graphql-codegen/plugin-helpers@5.0.4
- @graphql-codegen/visitor-plugin-common@5.2.0
- @graphql-codegen/gql-tag-operations@4.0.7
- @graphql-codegen/typescript-operations@4.2.1
- @graphql-codegen/typed-document-node@5.0.7
- @graphql-codegen/typescript@4.0.7
- #9889
cd60e14
Thanks @Sojaner! - Omit__typename
from being added on the root node of a subscription when usingaddTypenameSelectionDocumentTransform
with documentTransforms since a single root node is expected and the code generator fails because of that (refer to https://spec.graphql.org/draft/#sec-Single-root-field)
- Updated dependencies [
920b443
,ed9c205
]:- @graphql-codegen/visitor-plugin-common@5.1.0
- @graphql-codegen/typescript-operations@4.2.0
- @graphql-codegen/gql-tag-operations@4.0.6
- @graphql-codegen/typed-document-node@5.0.6
- @graphql-codegen/typescript@4.0.6
- Updated dependencies [
53f270a
]:- @graphql-codegen/visitor-plugin-common@5.0.0
- @graphql-codegen/gql-tag-operations@4.0.5
- @graphql-codegen/typescript-operations@4.1.3
- @graphql-codegen/typed-document-node@5.0.5
- @graphql-codegen/typescript@4.0.5
-
Updated dependencies [
4e69568
]:- @graphql-codegen/visitor-plugin-common@4.1.2
- @graphql-codegen/typescript-operations@4.1.2
- @graphql-codegen/add@5.0.2
- @graphql-codegen/gql-tag-operations@4.0.4
- @graphql-codegen/typed-document-node@5.0.4
- @graphql-codegen/typescript@4.0.4
- @graphql-codegen/plugin-helpers@5.0.3
-
#9557
48ddaeae1
Thanks @konomae! - Add eslint-disable comment to fragment-masking.ts -
Updated dependencies [
7718a8113
]:- @graphql-codegen/visitor-plugin-common@4.1.1
- @graphql-codegen/gql-tag-operations@4.0.3
- @graphql-codegen/typescript-operations@4.1.1
- @graphql-codegen/typed-document-node@5.0.3
- @graphql-codegen/typescript@4.0.3
- #9811
d8364e045
Thanks @saihaj! - The client preset now allows the use of thefutureProofEnums
config option
- #9811
d8364e045
Thanks @saihaj! - dependencies updates:- Updated dependency
tslib@~2.6.0
↗︎ (from~2.5.0
, independencies
)
- Updated dependency
- Updated dependencies [
d8364e045
,d8364e045
,d8364e045
,d8364e045
,d8364e045
,d8364e045
,d8364e045
,d8364e045
,d8364e045
]:- @graphql-codegen/add@5.0.1
- @graphql-codegen/gql-tag-operations@4.0.2
- @graphql-codegen/plugin-helpers@5.0.2
- @graphql-codegen/typed-document-node@5.0.2
- @graphql-codegen/typescript@4.0.2
- @graphql-codegen/typescript-operations@4.1.0
- @graphql-codegen/visitor-plugin-common@4.1.0
-
#9562
5beee9794
Thanks @n1ru4l! - Add theaddTypenameSelectionDocumentTransform
for automatically adding__typename
selections to all objct type selection sets.This is useful for GraphQL Clients such as Apollo Client or urql that need typename information for their cache to function.
Example Usage
import { addTypenameSelectionDocumentTransform } from '@graphql-codegen/client-preset'; import { CodegenConfig } from "@graphql-codegen/cli"; const config: CodegenConfig = { schema: "YOUR_GRAPHQL_ENDPOINT", documents: ["./**/*.{ts,tsx}"], ignoreNoDocuments: true, generates: { "./gql/": { preset: "client", plugins: [], presetConfig: { persistedDocuments: true, }, documentTransforms: [addTypenameSelectionDocumentTransform], }, }, }; export default config;
- Updated dependencies [
bb1e0e96e
]:- @graphql-codegen/plugin-helpers@5.0.1
-
#9497
2276708d0
Thanks @eddeee888! - Revert default ID scalar input type to stringWe changed the ID Scalar input type from
string
tostring | number
in the latest major version oftypescript
plugin. This causes issues for server plugins (e.g. typescript-resolvers) that depends ontypescript
plugin. This is because the scalar type needs to be manually inverted on setup which is confusing. -
Updated dependencies [
2276708d0
]:- @graphql-codegen/visitor-plugin-common@4.0.1
- @graphql-codegen/typescript-operations@4.0.1
- @graphql-codegen/typescript@4.0.1
- @graphql-codegen/gql-tag-operations@4.0.1
- @graphql-codegen/typed-document-node@5.0.1
-
#9196
3848a2b73
Thanks @beerose! - Add@defer
directive supportWhen a query includes a deferred fragment field, the server will return a partial response with the non-deferred fields first, followed by the remaining fields once they have been resolved.
Once start using the
@defer
directive in your queries, the generated code will automatically include support for the directive.// src/index.tsx import { graphql } from './gql' const OrdersFragment = graphql(` fragment OrdersFragment on User { orders { id total } } `) const GetUserQuery = graphql(` query GetUser($id: ID!) { user(id: $id) { id name ...OrdersFragment @defer } } `)
The generated type for
GetUserQuery
will have information that the fragment is incremental, meaning it may not be available right away.// gql/graphql.ts export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({ __typename?: 'Query' } & { ' $fragmentRefs'?: { OrdersFragment: Incremental<OrdersFragment> } })
Apart from generating code that includes support for the
@defer
directive, the Codegen also exports a utility function calledisFragmentReady
. You can use it to conditionally render components based on whether the data for a deferred fragment is available:const OrdersList = (props: { data: FragmentType<typeof OrdersFragment> }) => { const data = useFragment(OrdersFragment, props.data); return ( // render orders list ) }; function App() { const { data } = useQuery(GetUserQuery); return ( {data && ( <> {isFragmentReady(GetUserQuery, OrdersFragment, data) && <OrdersList data={data} />} </> )} ); } export default App;
-
#9353
d7e335b58
Thanks @charpeni! - Implement the ability the specify the hash algorithm used for persisted documents viapersistedDocuments.hashAlgorithm
-
#9449
4d9ea1a5a
Thanks @n1ru4l! - dependencies updates:- Updated dependency
@graphql-tools/documents@^1.0.0
↗︎ (from^0.1.0
, independencies
) - Updated dependency
@graphql-tools/utils@^10.0.0
↗︎ (from^9.0.0
, independencies
)
- Updated dependency
-
#9385
a7dda3546
Thanks @beerose! - Improve isFragmentReady utility function to work with noUncheckedIndexedAccess TSC setting -
#9196
3848a2b73
Thanks @beerose! - PassemitLegacyCommonJSImports
andisStringDocumentMode
to the client preset config -
#9414
ca02ad172
Thanks @beerose! - Include nested fragments in string documentMode -
Updated dependencies [
4d9ea1a5a
,4d9ea1a5a
,4d9ea1a5a
,f46803a8c
,3848a2b73
,ba84a3a27
,63827fabe
,50471e651
,5aa95aa96
,ca02ad172
,e1dc75f3c
,bb66c2a31
,5950f5a68
,5aa95aa96
]:- @graphql-codegen/gql-tag-operations@4.0.0
- @graphql-codegen/plugin-helpers@5.0.0
- @graphql-codegen/visitor-plugin-common@4.0.0
- @graphql-codegen/typed-document-node@5.0.0
- @graphql-codegen/typescript-operations@4.0.0
- @graphql-codegen/typescript@4.0.0
- @graphql-codegen/add@5.0.0
- Updated dependencies [
386cf9044
,402cb8ac0
]:- @graphql-codegen/visitor-plugin-common@3.1.1
- @graphql-codegen/gql-tag-operations@3.0.1
- @graphql-codegen/typescript-operations@3.0.4
- @graphql-codegen/typed-document-node@4.0.1
- @graphql-codegen/typescript@3.0.4
- #9137
2256c8b5d
Thanks @beerose! - AddTypedDocumentNode
string alternative that doesn't require GraphQL AST on the client. This change requires@graphql-typed-document-node/core
in version3.2.0
or higher.
- #9137
2256c8b5d
Thanks @beerose! - dependencies updates:- Updated dependency
@graphql-typed-document-node/core@3.2.0
↗︎ (from3.1.2
, independencies
)
- Updated dependency
- Updated dependencies [
e56790104
,b7dacb21f
,f104619ac
,92d86b009
,2256c8b5d
,acb647e4e
,9f4d9c5a4
]:- @graphql-codegen/visitor-plugin-common@3.1.0
- @graphql-codegen/plugin-helpers@4.2.0
- @graphql-codegen/typescript@3.0.3
- @graphql-codegen/typed-document-node@4.0.0
- @graphql-codegen/gql-tag-operations@3.0.0
- @graphql-codegen/typescript-operations@3.0.3
- #9049
9430c3811
Thanks @renovate! - dependencies updates:- Updated dependency
@graphql-typed-document-node/core@3.1.2
↗︎ (from3.1.1
, independencies
)
- Updated dependency
- Updated dependencies [
ba0610bbd
,4b49f6fbe
,b343626c9
]:- @graphql-codegen/visitor-plugin-common@3.0.2
- @graphql-codegen/gql-tag-operations@2.0.2
- @graphql-codegen/typescript-operations@3.0.2
- @graphql-codegen/typed-document-node@3.0.2
- @graphql-codegen/typescript@3.0.2
-
#8893
a118c307a
Thanks @n1ru4l! - It is no longer mandatory to declare an empty plugins array when using a preset -
#8723
a3309e63e
Thanks @kazekyo! - Introduce a new feature called DocumentTransform.DocumentTransform is a functionality that allows you to modify
documents
before they are processed by plugins. You can use functions passed to thedocumentTransforms
option to make changes to GraphQL documents.To use this feature, you can write
documentTransforms
as follows:import type { CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { schema: 'https://localhost:4000/graphql', documents: ['src/**/*.tsx'], generates: { './src/gql/': { preset: 'client', documentTransforms: [ { transform: ({ documents }) => { // Make some changes to the documents return documents } } ] } } } export default config
For instance, to remove a
@localOnlyDirective
directive fromdocuments
, you can write the following code:import type { CodegenConfig } from '@graphql-codegen/cli' import { visit } from 'graphql' const config: CodegenConfig = { schema: 'https://localhost:4000/graphql', documents: ['src/**/*.tsx'], generates: { './src/gql/': { preset: 'client', documentTransforms: [ { transform: ({ documents }) => { return documents.map(documentFile => { documentFile.document = visit(documentFile.document, { Directive: { leave(node) { if (node.name.value === 'localOnlyDirective') return null } } }) return documentFile }) } } ] } } } export default config
DocumentTransform can also be specified by file name. You can create a custom file for a specific transformation and pass it to
documentTransforms
.Let's create the document transform as a file:
module.exports = { transform: ({ documents }) => { // Make some changes to the documents return documents } }
Then, you can specify the file name as follows:
import type { CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { schema: 'https://localhost:4000/graphql', documents: ['src/**/*.tsx'], generates: { './src/gql/': { preset: 'client', documentTransforms: ['./my-document-transform.js'] } } } export default config
-
#8879
8206b268d
Thanks @renovate! - dependencies updates:- Updated dependency
tslib@~2.5.0
↗︎ (from~2.4.0
, independencies
)
- Updated dependency
-
#8995
fe2e9c7a5
Thanks @charpeni! - UsegqlTagName
for generated examples -
#8971
6b6fe3cbc
Thanks @n1ru4l! - Allow passing fragment documents to APIs like ApollosreadFragment
-
Updated dependencies [
8206b268d
,8206b268d
,8206b268d
,8206b268d
,8206b268d
,8206b268d
,8206b268d
,a118c307a
,fe2e9c7a5
,6b6fe3cbc
,6b6fe3cbc
,a3309e63e
]:- @graphql-codegen/add@4.0.1
- @graphql-codegen/gql-tag-operations@2.0.1
- @graphql-codegen/plugin-helpers@4.1.0
- @graphql-codegen/typed-document-node@3.0.1
- @graphql-codegen/typescript@3.0.1
- @graphql-codegen/typescript-operations@3.0.1
- @graphql-codegen/visitor-plugin-common@3.0.1
-
#8885
fd0b0c813
Thanks @n1ru4l! - dependencies updates:- Updated dependency
@babel/helper-plugin-utils@^7.20.2
↗︎ (from^7.14.5
, independencies
) - Updated dependency
@babel/template@^7.20.7
↗︎ (from^7.15.4
, independencies
)
- Updated dependency
-
Updated dependencies [
fc79b65d4
,fd0b0c813
]:- @graphql-codegen/visitor-plugin-common@3.0.0
- @graphql-codegen/plugin-helpers@4.0.0
- @graphql-codegen/add@4.0.0
- @graphql-codegen/gql-tag-operations@2.0.0
- @graphql-codegen/typescript-operations@3.0.0
- @graphql-codegen/typed-document-node@3.0.0
- @graphql-codegen/typescript@3.0.0
-
#8757
4f290aa72
Thanks @n1ru4l! - Add support for persisted documents.You can now generate and embed a persisted documents hash for the executable documents.
/** codegen.ts */ import { CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { schema: 'https://swapi-graphql.netlify.app/.netlify/functions/index', documents: ['src/**/*.tsx'], ignoreNoDocuments: true, // for better experience with the watcher generates: { './src/gql/': { preset: 'client', plugins: [], presetConfig: { persistedDocuments: true } } } } export default config
This will generate
./src/gql/persisted-documents.json
(dictionary of hashes with their operation string).In addition to that each generated document node will have a
__meta__.hash
property.import { gql } from './gql.js' const allFilmsWithVariablesQueryDocument = graphql(/* GraphQL */ ` query allFilmsWithVariablesQuery($first: Int!) { allFilms(first: $first) { edges { node { ...FilmItem } } } } `) console.log((allFilmsWithVariablesQueryDocument as any)['__meta__']['hash'])
-
#8757
4f290aa72
Thanks @n1ru4l! - Add support for embedding metadata in the document AST.It is now possible to embed metadata (e.g. for your GraphQL client within the emitted code).
/** codegen.ts */ import { CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { schema: 'https://swapi-graphql.netlify.app/.netlify/functions/index', documents: ['src/**/*.tsx'], ignoreNoDocuments: true, // for better experience with the watcher generates: { './src/gql/': { preset: 'client', plugins: [], presetConfig: { onExecutableDocumentNode(documentNode) { return { operation: documentNode.definitions[0].operation, name: documentNode.definitions[0].name.value } } } } } } export default config
You can then access the metadata via the
__meta__
property on the document node.import { gql } from './gql.js' const allFilmsWithVariablesQueryDocument = graphql(/* GraphQL */ ` query allFilmsWithVariablesQuery($first: Int!) { allFilms(first: $first) { edges { node { ...FilmItem } } } } `) console.log((allFilmsWithVariablesQueryDocument as any)['__meta__'])
- #8757
4f290aa72
Thanks @n1ru4l! - dependencies updates:- Added dependency
@graphql-tools/documents@^0.1.0
↗︎ (todependencies
)
- Added dependency
- Updated dependencies [
a98198524
]:- @graphql-codegen/visitor-plugin-common@2.13.8
- @graphql-codegen/gql-tag-operations@1.6.2
- @graphql-codegen/typescript-operations@2.5.13
- @graphql-codegen/typed-document-node@2.3.13
- @graphql-codegen/typescript@2.8.8
-
#8796
902451601
Thanks @shmax! - remove extra asterisk and add missing semicolon in generated output -
Updated dependencies [
902451601
]:- @graphql-codegen/gql-tag-operations@1.6.1
- Updated dependencies [
eb454d06c
,2a33fc774
]:- @graphql-codegen/visitor-plugin-common@2.13.7
- @graphql-codegen/gql-tag-operations@1.6.0
- @graphql-codegen/typescript-operations@2.5.12
- @graphql-codegen/typed-document-node@2.3.12
- @graphql-codegen/typescript@2.8.7
-
#8771
ed87c782b
Thanks @renovate! - dependencies updates:- Updated dependency
@graphql-tools/utils@^9.0.0
↗︎ (from^8.8.0
, independencies
)
- Updated dependency
-
#8752
cbca5a7ea
Thanks @pbrink231! - add typescriptavoidOptionals
to forwarded config -
Updated dependencies [
ed87c782b
,ed87c782b
,ed87c782b
,6c6b6f2df
]:- @graphql-codegen/gql-tag-operations@1.5.12
- @graphql-codegen/plugin-helpers@3.1.2
- @graphql-codegen/visitor-plugin-common@2.13.6
- @graphql-codegen/typescript-operations@2.5.11
- @graphql-codegen/typed-document-node@2.3.11
- @graphql-codegen/typescript@2.8.6
-
46f75304a
Thanks @saihaj! - fix the version of@graphql-codegen/plugin-helpers@3.1.1
-
Updated dependencies [
307a5d350
,46f75304a
]:- @graphql-codegen/plugin-helpers@3.1.1
- @graphql-codegen/add@3.2.3
- @graphql-codegen/visitor-plugin-common@2.13.5
- @graphql-codegen/gql-tag-operations@1.5.11
- @graphql-codegen/typescript-operations@2.5.10
- @graphql-codegen/typed-document-node@2.3.10
- @graphql-codegen/typescript@2.8.5
-
#8702
0eb0dde8a
Thanks @ithinkdancan! - add config for nonOptionalTypename -
Updated dependencies [
a6c2097f4
,a6c2097f4
,a6c2097f4
,f79a00e8a
,c802a0c0b
]:- @graphql-codegen/plugin-helpers@3.0.0
- @graphql-codegen/typed-document-node@2.3.9
- @graphql-codegen/visitor-plugin-common@2.13.4
- @graphql-codegen/add@3.2.2
- @graphql-codegen/gql-tag-operations@1.5.10
- @graphql-codegen/typescript-operations@2.5.9
- @graphql-codegen/typescript@2.8.4
- Updated dependencies [
62f655452
]:- @graphql-codegen/visitor-plugin-common@2.13.3
- @graphql-codegen/typescript-operations@2.5.8
- @graphql-codegen/gql-tag-operations@1.5.9
- @graphql-codegen/typed-document-node@2.3.8
- @graphql-codegen/typescript@2.8.3
- #8657
4b96035a8
Thanks @charlypoly! - Export a testing helper:makeFragmentData(data, fragment)
- Updated dependencies [
00ddc9368
]:- @graphql-codegen/gql-tag-operations@1.5.8
- Updated dependencies [
ef4c2c9c2
]:- @graphql-codegen/visitor-plugin-common@2.13.2
- @graphql-codegen/typescript@2.8.2
- @graphql-codegen/gql-tag-operations@1.5.7
- @graphql-codegen/typescript-operations@2.5.7
- @graphql-codegen/typed-document-node@2.3.7
- Updated dependencies [
63dc8f205
]:- @graphql-codegen/visitor-plugin-common@2.13.1
- @graphql-codegen/plugin-helpers@2.7.2
- @graphql-codegen/gql-tag-operations@1.5.6
- @graphql-codegen/typescript-operations@2.5.6
- @graphql-codegen/typed-document-node@2.3.6
- @graphql-codegen/typescript@2.8.1
- #8523
3a3202fbb
Thanks @charlypoly! - allow non-typescript plugins
- #8498
a46b8d99c
Thanks @charlypoly! - Fragment masking$fragmentName
and$fragmentRefs
are optionals
-
#8500
71aae7a92
Thanks @charlypoly! - Add warning and errors to prevent unwanted configuration -
Updated dependencies [
a46b8d99c
]:- @graphql-codegen/visitor-plugin-common@2.13.0
- @graphql-codegen/gql-tag-operations@1.5.5
- @graphql-codegen/typescript-operations@2.5.5
- @graphql-codegen/typed-document-node@2.3.5
- @graphql-codegen/typescript@2.7.5
- #8472
a08fb6502
Thanks @panusoi! - The client preset now allows the use of theenumsAsTypes
config option
- Updated dependencies [
1bd7f771c
]:- @graphql-codegen/visitor-plugin-common@2.12.2
- @graphql-codegen/gql-tag-operations@1.5.4
- @graphql-codegen/typescript-operations@2.5.4
- @graphql-codegen/typed-document-node@2.3.4
- @graphql-codegen/typescript@2.7.4
- #8457
126194017
Thanks @charlypoly! - typo in config mapping
- #8455
d19573d88
Thanks @charlypoly! - The client preset now allows the use of the followingconfig
:scalars
defaultScalarType
strictScalars
namingConvention
useTypeImports
skipTypename
arrayInputCoercion
-
#8443
e2d115146
Thanks @charlypoly! - fix(gql-tag-operations): issues with "no documents" scenario -
Updated dependencies [
e2d115146
]:- @graphql-codegen/gql-tag-operations@1.5.3
-
#8402
a76c606e3
Thanks @charlypoly! - dependencies updates:- Updated dependency
@graphql-codegen/gql-tag-operations@1.5.1
↗︎ (from^1.5.0
, independencies
)
- Updated dependency
-
#8402
a76c606e3
Thanks @charlypoly! - update@graphql-codegen/gql-tag-operations
-
Updated dependencies [
a76c606e3
]:- @graphql-codegen/gql-tag-operations@1.5.2
-
#8302
876844e76
Thanks @charlypoly! -@graphql-codegen/gql-tag-operations
and@graphql-codegen/gql-tag-operations-preset
Introduce a
gqlTagName
configuration option
@graphql-codegen/client-preset
New preset for GraphQL Code Generator v3, more information on the RFC: #8296
@graphql-codegen/cli
Update init wizard with 3.0 recommendations (
codegen.ts
,client
preset) -
Updated dependencies [
876844e76
]:- @graphql-codegen/gql-tag-operations@1.5.0