diff --git a/.changeset/@graphql-codegen_cli-9448-dependencies.md b/.changeset/@graphql-codegen_cli-9448-dependencies.md deleted file mode 100644 index 6f966c8c7fb..00000000000 --- a/.changeset/@graphql-codegen_cli-9448-dependencies.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@graphql-codegen/cli": patch ---- -dependencies updates: - - Updated dependency [`graphql-config@^5.0.0` ↗︎](https://www.npmjs.com/package/graphql-config/v/5.0.0) (from `^4.5.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_cli-9449-dependencies.md b/.changeset/@graphql-codegen_cli-9449-dependencies.md deleted file mode 100644 index 3f8fb9cd18c..00000000000 --- a/.changeset/@graphql-codegen_cli-9449-dependencies.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -"@graphql-codegen/cli": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/apollo-engine-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/apollo-engine-loader/v/8.0.0) (from `^7.3.6`, in `dependencies`) - - Updated dependency [`@graphql-tools/code-file-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/code-file-loader/v/8.0.0) (from `^7.3.17`, in `dependencies`) - - Updated dependency [`@graphql-tools/git-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/git-loader/v/8.0.0) (from `^7.2.13`, in `dependencies`) - - Updated dependency [`@graphql-tools/github-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/github-loader/v/8.0.0) (from `^7.3.28`, in `dependencies`) - - Updated dependency [`@graphql-tools/graphql-file-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/graphql-file-loader/v/8.0.0) (from `^7.5.0`, in `dependencies`) - - Updated dependency [`@graphql-tools/json-file-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/json-file-loader/v/8.0.0) (from `^7.4.1`, in `dependencies`) - - Updated dependency [`@graphql-tools/load@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/load/v/8.0.0) (from `^7.8.0`, in `dependencies`) - - Updated dependency [`@graphql-tools/prisma-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/prisma-loader/v/8.0.0) (from `^7.2.69`, in `dependencies`) - - Updated dependency [`@graphql-tools/url-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/url-loader/v/8.0.0) (from `^7.17.17`, in `dependencies`) - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) - - Updated dependency [`cosmiconfig@^8.1.3` ↗︎](https://www.npmjs.com/package/cosmiconfig/v/8.1.3) (from `^7.0.0`, in `dependencies`) - - Updated dependency [`graphql-config@^5.0.1` ↗︎](https://www.npmjs.com/package/graphql-config/v/5.0.1) (from `^4.5.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_client-preset-9449-dependencies.md b/.changeset/@graphql-codegen_client-preset-9449-dependencies.md deleted file mode 100644 index 031cb0f83a7..00000000000 --- a/.changeset/@graphql-codegen_client-preset-9449-dependencies.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@graphql-codegen/client-preset": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/documents@^1.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/documents/v/1.0.0) (from `^0.1.0`, in `dependencies`) - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_core-9449-dependencies.md b/.changeset/@graphql-codegen_core-9449-dependencies.md deleted file mode 100644 index b49cd44bf29..00000000000 --- a/.changeset/@graphql-codegen_core-9449-dependencies.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@graphql-codegen/core": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/schema@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/schema/v/10.0.0) (from `^9.0.0`, in `dependencies`) - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.1.1`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_gql-tag-operations-9449-dependencies.md b/.changeset/@graphql-codegen_gql-tag-operations-9449-dependencies.md deleted file mode 100644 index 79916e6f10c..00000000000 --- a/.changeset/@graphql-codegen_gql-tag-operations-9449-dependencies.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@graphql-codegen/gql-tag-operations": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_graphql-modules-preset-9449-dependencies.md b/.changeset/@graphql-codegen_graphql-modules-preset-9449-dependencies.md deleted file mode 100644 index f33b30d0cef..00000000000 --- a/.changeset/@graphql-codegen_graphql-modules-preset-9449-dependencies.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@graphql-codegen/graphql-modules-preset": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_plugin-helpers-9449-dependencies.md b/.changeset/@graphql-codegen_plugin-helpers-9449-dependencies.md deleted file mode 100644 index 8bcec5cdebf..00000000000 --- a/.changeset/@graphql-codegen_plugin-helpers-9449-dependencies.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@graphql-codegen/plugin-helpers": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_schema-ast-9449-dependencies.md b/.changeset/@graphql-codegen_schema-ast-9449-dependencies.md deleted file mode 100644 index 43f32c47539..00000000000 --- a/.changeset/@graphql-codegen_schema-ast-9449-dependencies.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@graphql-codegen/schema-ast": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_testing-9407-dependencies.md b/.changeset/@graphql-codegen_testing-9407-dependencies.md deleted file mode 100644 index cc3b91768ed..00000000000 --- a/.changeset/@graphql-codegen_testing-9407-dependencies.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@graphql-codegen/testing": patch ---- -dependencies updates: - - Updated dependency [`nock@13.3.1` ↗︎](https://www.npmjs.com/package/nock/v/13.3.1) (from `13.3.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_typescript-resolvers-9449-dependencies.md b/.changeset/@graphql-codegen_typescript-resolvers-9449-dependencies.md deleted file mode 100644 index 8712c6a5ff6..00000000000 --- a/.changeset/@graphql-codegen_typescript-resolvers-9449-dependencies.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@graphql-codegen/typescript-resolvers": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) diff --git a/.changeset/@graphql-codegen_visitor-plugin-common-9449-dependencies.md b/.changeset/@graphql-codegen_visitor-plugin-common-9449-dependencies.md deleted file mode 100644 index f58cc3260b7..00000000000 --- a/.changeset/@graphql-codegen_visitor-plugin-common-9449-dependencies.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"@graphql-codegen/visitor-plugin-common": patch ---- -dependencies updates: - - Updated dependency [`@graphql-tools/optimize@^2.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/optimize/v/2.0.0) (from `^1.3.0`, in `dependencies`) - - Updated dependency [`@graphql-tools/relay-operation-optimizer@^7.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/relay-operation-optimizer/v/7.0.0) (from `^6.5.0`, in `dependencies`) - - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) diff --git a/.changeset/breezy-rice-retire.md b/.changeset/breezy-rice-retire.md deleted file mode 100644 index dbad5d9dd85..00000000000 --- a/.changeset/breezy-rice-retire.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/plugin-helpers': patch ---- - -Update GitHub loader TypeScript type and usage docs diff --git a/.changeset/cool-waves-impress.md b/.changeset/cool-waves-impress.md deleted file mode 100644 index de178ddba1e..00000000000 --- a/.changeset/cool-waves-impress.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@graphql-codegen/client-preset": patch ---- - -improve error message diff --git a/.changeset/eleven-news-lay.md b/.changeset/eleven-news-lay.md deleted file mode 100644 index ea7853ca6e8..00000000000 --- a/.changeset/eleven-news-lay.md +++ /dev/null @@ -1,72 +0,0 @@ ---- -'@graphql-codegen/typed-document-node': minor -'@graphql-codegen/visitor-plugin-common': minor -'@graphql-codegen/typescript-operations': minor -'@graphql-codegen/typescript': minor -'@graphql-codegen/typescript-resolvers': minor -'@graphql-codegen/client-preset': minor ---- - -Add `@defer` directive support - -When 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. - -```jsx -// 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. - -```tsx -// gql/graphql.ts -export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({ - __typename?: 'Query' -} & { - ' $fragmentRefs'?: { OrdersFragment: Incremental } -}) -``` - -Apart from generating code that includes support for the `@defer` directive, the Codegen also exports a utility function called `isFragmentReady`. You can use it to conditionally render components based on whether the data for a deferred -fragment is available: - -```jsx -const OrdersList = (props: { data: FragmentType }) => { - const data = useFragment(OrdersFragment, props.data); - return ( - // render orders list - ) -}; - -function App() { - const { data } = useQuery(GetUserQuery); - return ( - {data && ( - <> - {isFragmentReady(GetUserQuery, OrdersFragment, data) - && } - - )} - ); -} -export default App; -``` diff --git a/.changeset/four-buckets-carry.md b/.changeset/four-buckets-carry.md deleted file mode 100644 index 6bd7cd5db86..00000000000 --- a/.changeset/four-buckets-carry.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/client-preset': patch ---- - -Improve isFragmentReady utility function to work with noUncheckedIndexedAccess TSC setting diff --git a/.changeset/gold-frogs-explain.md b/.changeset/gold-frogs-explain.md deleted file mode 100644 index 4c663b903f4..00000000000 --- a/.changeset/gold-frogs-explain.md +++ /dev/null @@ -1,139 +0,0 @@ ---- -'@graphql-codegen/visitor-plugin-common': major -'@graphql-codegen/typescript-operations': major -'@graphql-codegen/typescript': major -'@graphql-codegen/typescript-resolvers': major ---- - -Implement Scalars with input/output types - -In GraphQL, Scalar types can be different for client and server. For example, given the native GraphQL ID: -- A client may send `string` or `number` in the input -- A client receives `string` in its selection set (i.e output) -- A server receives `string` in the resolver (GraphQL parses `string` or `number` received from the client to `string`) -- A server may return `string` or `number` (GraphQL serializes the value to `string` before sending it to the client ) - -Currently, we represent every Scalar with only one type. This is what codegen generates as base type: - -```ts -export type Scalars = { - ID: string; -} -``` - -Then, this is used in both input and output type e.g. - -```ts -export type Book = { - __typename?: "Book"; - id: Scalars["ID"]; // Output's ID can be `string` 👍 -}; - -export type QueryBookArgs = { - id: Scalars["ID"]; // Input's ID can be `string` or `number`. However, the type is only `string` here 👎 -}; -``` - -This PR extends each Scalar to have input and output: - -```ts -export type Scalars = { - ID: { - input: string | number; - output: string; - } -} -``` - -Then, each input/output GraphQL type can correctly refer to the correct input/output scalar type: - -```ts -export type Book = { - __typename?: "Book"; - id: Scalars["ID"]['output']; // Output's ID can be `string` 👍 -}; - -export type QueryBookArgs = { - id: Scalars["ID"]['input']; // Input's ID can be `string` or `number` 👍 -}; -``` - -Note that for `typescript-resolvers`, the type of ID needs to be inverted. However, the referenced types in GraphQL input/output types should still work correctly: - -```ts -export type Scalars = { - ID: { - input: string; - output: string | number; - } -} - -export type Book = { - __typename?: "Book"; - id: Scalars["ID"]['output']; // Resolvers can return `string` or `number` in ID fields 👍 -}; - -export type QueryBookArgs = { - id: Scalars["ID"]['input']; // Resolvers receive `string` in ID fields 👍 -}; - -export type ResolversTypes = { - ID: ID: ResolverTypeWrapper; // Resolvers can return `string` or `number` in ID fields 👍 -} - -export type ResolversParentTypes = { - ID: Scalars['ID']['output']; // Resolvers receive `string` or `number` from parents 👍 -}; -``` - ---- - -Config changes: - -1. Scalars option can now take input/output types: - -```ts -config: { - scalars: { - ID: { - input: 'string', - output: 'string | number' - } - } -} -``` - -2. If a string is given (instead of an object with input/output fields), it will be used as both input and output types: - -```ts -config: { - scalars: { - ID: 'string' // This means `string` will be used for both ID's input and output types - } -} -``` - -3. BREAKING CHANGE: External module Scalar types need to be an object with input/output fields - -```ts -config: { - scalars: { - ID: './path/to/scalar-module' - } -} -``` - -If correctly, wired up, the following will be generated: - -```ts -// Previously, imported `ID` type can be a primitive type, now it must be an object with input/output fields -import { ID } from "./path/to/scalar-module"; - -export type Scalars = { - ID: { input: ID['input']; output: ID['output']; } -}; -``` - ---- - -BREAKING CHANGE: This changes Scalar types which could be referenced in other plugins. If you are a plugin maintainer and reference Scalar, please update your plugin to use the correct input/output types. diff --git a/.changeset/khaki-dolphins-pump.md b/.changeset/khaki-dolphins-pump.md deleted file mode 100644 index 7d84ee9c8e1..00000000000 --- a/.changeset/khaki-dolphins-pump.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/plugin-helpers': patch ---- - -Add handleAsSDL property to UrlSchemaOptions type diff --git a/.changeset/long-owls-matter.md b/.changeset/long-owls-matter.md deleted file mode 100644 index d5d2db5295b..00000000000 --- a/.changeset/long-owls-matter.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -'@graphql-codegen/visitor-plugin-common': minor -'@graphql-codegen/typescript-resolvers': minor ---- - -Add excludeTypes config to resolversNonOptionalTypename - -This disables the adding of `__typename` in resolver types for any specified typename. This could be useful e.g. if you're wanting to enable this for all new types going forward but not do a big migration. - -Usage example: - -```typescript -const config: CodegenConfig = { - schema: 'src/schema/**/*.graphql', - generates: { - 'src/schema/types.ts': { - plugins: ['typescript', 'typescript-resolvers'], - config: { - resolversNonOptionalTypename: { - unionMember: true, - excludeTypes: ['MyType'], - } - } - }, - }, -}; -``` diff --git a/.changeset/long-pears-peel.md b/.changeset/long-pears-peel.md deleted file mode 100644 index 86541f8f412..00000000000 --- a/.changeset/long-pears-peel.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -'@graphql-codegen/visitor-plugin-common': minor -'@graphql-codegen/typescript-resolvers': minor ---- - -Use generic to simplify ResolversUnionTypes - -This follows the `ResolversInterfaceTypes`'s approach where the `RefType` generic is used to refer back to `ResolversTypes` or `ResolversParentTypes` in cases of nested Union types diff --git a/.changeset/modern-clouds-prove.md b/.changeset/modern-clouds-prove.md deleted file mode 100644 index b4dfdd864fd..00000000000 --- a/.changeset/modern-clouds-prove.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/client-preset': patch ---- - -Pass `emitLegacyCommonJSImports` and `isStringDocumentMode` to the client preset config diff --git a/.changeset/orange-tables-cry.md b/.changeset/orange-tables-cry.md deleted file mode 100644 index dabe909e0af..00000000000 --- a/.changeset/orange-tables-cry.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/client-preset': minor ---- - -Implement the ability the specify the hash algorithm used for persisted documents via `persistedDocuments.hashAlgorithm` diff --git a/.changeset/quiet-rocks-sin.md b/.changeset/quiet-rocks-sin.md deleted file mode 100644 index 1a6326f1c4d..00000000000 --- a/.changeset/quiet-rocks-sin.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/cli': patch ---- - -Fixed option ignoreNoDocuments when using graphql configs diff --git a/.changeset/strange-eggs-attack.md b/.changeset/strange-eggs-attack.md deleted file mode 100644 index 65bed4b3d37..00000000000 --- a/.changeset/strange-eggs-attack.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@graphql-codegen/visitor-plugin-common': patch -'@graphql-codegen/client-preset': patch ---- - -Include nested fragments in string documentMode diff --git a/.changeset/swift-files-vanish.md b/.changeset/swift-files-vanish.md deleted file mode 100644 index 5ebb91758cc..00000000000 --- a/.changeset/swift-files-vanish.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/cli': patch ---- - -Trigger rebuilds in watch mode while respecting rules of precedence and negation, both in terms of global (top-level) config vs. local (per-output target) config, and in terms of watch patterns (higher priority) vs. documents/schemas (lower priority). This fixes an issue with overly-aggressive rebuilds during watch mode. diff --git a/.changeset/swift-hornets-camp.md b/.changeset/swift-hornets-camp.md deleted file mode 100644 index bfd22e5a831..00000000000 --- a/.changeset/swift-hornets-camp.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"@graphql-codegen/typescript-operations": minor -"@graphql-codegen/typescript-resolvers": minor -"@graphql-codegen/typescript": minor -"@graphql-codegen/visitor-plugin-common": minor ---- - -Added support for disabling suffixes on Enums. diff --git a/.changeset/tame-chairs-check.md b/.changeset/tame-chairs-check.md deleted file mode 100644 index 01d62be2b7a..00000000000 --- a/.changeset/tame-chairs-check.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -'@graphql-codegen/cli': major -'@graphql-codegen/core': major -'@graphql-codegen/add': major -'@graphql-codegen/fragment-matcher': major -'@graphql-codegen/introspection': major -'@graphql-codegen/schema-ast': major -'@graphql-codegen/time': major -'@graphql-codegen/visitor-plugin-common': major -'@graphql-codegen/typescript-document-nodes': major -'@graphql-codegen/gql-tag-operations': major -'@graphql-codegen/typescript-operations': major -'@graphql-codegen/typescript-resolvers': major -'@graphql-codegen/typed-document-node': major -'@graphql-codegen/typescript': major -'@graphql-codegen/client-preset': major -'@graphql-codegen/graphql-modules-preset': major -'@graphql-codegen/testing': major -'@graphql-codegen/plugin-helpers': major ---- - -Require Node.js `>= 16`. Drop support for Node.js 14 diff --git a/.changeset/thin-berries-deny.md b/.changeset/thin-berries-deny.md deleted file mode 100644 index 02522f7b719..00000000000 --- a/.changeset/thin-berries-deny.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/visitor-plugin-common': patch ---- - -Output valid type names with mergeFragmentTypes diff --git a/.changeset/tricky-swans-happen.md b/.changeset/tricky-swans-happen.md deleted file mode 100644 index 1d9d7e100ae..00000000000 --- a/.changeset/tricky-swans-happen.md +++ /dev/null @@ -1,100 +0,0 @@ ---- -'@graphql-codegen/visitor-plugin-common': minor -'@graphql-codegen/typescript-resolvers': minor ---- - -Extract interfaces to ResolversInterfaceTypes and add to resolversNonOptionalTypename - -1. `ResolversInterfaceTypes` is a new type that keeps track of a GraphQL interface and its implementing types. - -For example, consider this schema: - -```graphql -extend type Query { - character(id: ID!): CharacterNode -} - -interface CharacterNode { - id: ID! -} - -type Wizard implements CharacterNode { - id: ID! - screenName: String! - spells: [String!]! -} - -type Fighter implements CharacterNode { - id: ID! - screenName: String! - powerLevel: Int! -} -``` - -The generated types will look like this: - -```ts -export type ResolversInterfaceTypes> = { - CharacterNode: Fighter | Wizard; -}; - -export type ResolversTypes = { - // other types... - CharacterNode: ResolverTypeWrapper["CharacterNode"]>; - Fighter: ResolverTypeWrapper; - Wizard: ResolverTypeWrapper; - // other types... -}; - -export type ResolversParentTypes = { - // other types... - CharacterNode: ResolversInterfaceTypes["CharacterNode"]; - Fighter: Fighter; - Wizard: Wizard; - // other types... -}; -``` - -The `RefType` generic is used to reference back to `ResolversTypes` and `ResolversParentTypes` in some cases such as field returning a Union. - -2. `resolversNonOptionalTypename` also affects `ResolversInterfaceTypes` - -Using the schema above, if we use `resolversNonOptionalTypename` option: - -```typescript -const config: CodegenConfig = { - schema: 'src/schema/**/*.graphql', - generates: { - 'src/schema/types.ts': { - plugins: ['typescript', 'typescript-resolvers'], - config: { - resolversNonOptionalTypename: true // Or `resolversNonOptionalTypename: { interfaceImplementingType: true }` - } - }, - }, -}; -``` - -Then, the generated type looks like this: - -```ts -export type ResolversInterfaceTypes> = { - CharacterNode: (Fighter & { __typename: "Fighter" }) | (Wizard & { __typename: "Wizard" }); -}; - -export type ResolversTypes = { - // other types... - CharacterNode: ResolverTypeWrapper["CharacterNode"]>; - Fighter: ResolverTypeWrapper; - Wizard: ResolverTypeWrapper; - // other types... -}; - -export type ResolversParentTypes = { - // other types... - CharacterNode: ResolversInterfaceTypes["CharacterNode"]; - Fighter: Fighter; - Wizard: Wizard; - // other types... -}; -``` diff --git a/examples/persisted-documents-string-mode/package.json b/examples/persisted-documents-string-mode/package.json index fba4a6a6dc6..49a941c5231 100644 --- a/examples/persisted-documents-string-mode/package.json +++ b/examples/persisted-documents-string-mode/package.json @@ -10,8 +10,8 @@ "@graphql-typed-document-node/core": "3.2.0", "jest": "28.1.3", "babel-jest": "28.1.3", - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/client-preset": "3.0.1", + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/client-preset": "4.0.0", "@babel/core": "7.21.8", "@babel/preset-env": "7.21.5", "@babel/preset-typescript": "7.21.5" diff --git a/examples/persisted-documents/package.json b/examples/persisted-documents/package.json index fc08cf8365d..140ea3184c0 100644 --- a/examples/persisted-documents/package.json +++ b/examples/persisted-documents/package.json @@ -10,8 +10,8 @@ "@graphql-typed-document-node/core": "3.2.0", "jest": "28.1.3", "babel-jest": "28.1.3", - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/client-preset": "3.0.1", + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/client-preset": "4.0.0", "@babel/core": "7.21.8", "@babel/preset-env": "7.21.5", "@babel/preset-typescript": "7.21.5" diff --git a/examples/programmatic-typescript/package.json b/examples/programmatic-typescript/package.json index 3707b4e630b..6b6a977b136 100644 --- a/examples/programmatic-typescript/package.json +++ b/examples/programmatic-typescript/package.json @@ -10,12 +10,12 @@ "test:end2end": "exit 0" }, "dependencies": { - "@graphql-codegen/core": "3.1.0", - "@graphql-codegen/plugin-helpers": "4.2.0", - "@graphql-codegen/typed-document-node": "4.0.1", - "@graphql-codegen/typescript": "3.0.4", - "@graphql-codegen/typescript-operations": "3.0.4", - "@graphql-codegen/typescript-resolvers": "3.2.1", + "@graphql-codegen/core": "4.0.0", + "@graphql-codegen/plugin-helpers": "5.0.0", + "@graphql-codegen/typed-document-node": "5.0.0", + "@graphql-codegen/typescript": "4.0.0", + "@graphql-codegen/typescript-operations": "4.0.0", + "@graphql-codegen/typescript-resolvers": "4.0.0", "@graphql-tools/graphql-file-loader": "8.0.0", "@graphql-tools/load": "8.0.0", "@graphql-tools/schema": "10.0.0", diff --git a/examples/react/apollo-client-defer/package.json b/examples/react/apollo-client-defer/package.json index d6314dd7dc7..bedef2c7c7f 100644 --- a/examples/react/apollo-client-defer/package.json +++ b/examples/react/apollo-client-defer/package.json @@ -11,8 +11,8 @@ "graphql-yoga": "3.9.1" }, "devDependencies": { - "@graphql-codegen/cli": "^3.3.0", - "@graphql-codegen/client-preset": "^3.0.0", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", "@types/jest": "^27.5.2", "@types/node": "^18.11.18", "@types/react": "^18.0.15", diff --git a/examples/react/apollo-client-swc-plugin/package.json b/examples/react/apollo-client-swc-plugin/package.json index 3958283a893..f7088fdf0e6 100644 --- a/examples/react/apollo-client-swc-plugin/package.json +++ b/examples/react/apollo-client-swc-plugin/package.json @@ -9,8 +9,8 @@ }, "devDependencies": { "@graphql-codegen/client-preset-swc-plugin": "0.2.0", - "@graphql-codegen/client-preset": "^3.0.1", - "@graphql-codegen/cli": "^3.3.1", + "@graphql-codegen/client-preset": "^4.0.0", + "@graphql-codegen/cli": "^4.0.0", "@vitejs/plugin-react-swc": "^3.3.0", "@types/react": "18.2.6", "@types/react-dom": "18.2.4", diff --git a/examples/react/apollo-client/package.json b/examples/react/apollo-client/package.json index a64d5876f94..e56c68515b7 100644 --- a/examples/react/apollo-client/package.json +++ b/examples/react/apollo-client/package.json @@ -9,8 +9,8 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@graphql-codegen/cli": "^3.3.1", - "@graphql-codegen/client-preset": "^3.0.1", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", "@vitejs/plugin-react": "^3.1.0", "@types/jest": "^27.5.2", "@types/node": "^18.11.18", diff --git a/examples/react/http-executor/package.json b/examples/react/http-executor/package.json index 3cc88a7887d..2f481c0f660 100644 --- a/examples/react/http-executor/package.json +++ b/examples/react/http-executor/package.json @@ -8,8 +8,8 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@graphql-codegen/cli": "^3.3.1", - "@graphql-codegen/client-preset": "^3.0.1", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", "@vitejs/plugin-react": "^3.1.0", "@types/jest": "^27.5.2", "@types/node": "^18.11.18", diff --git a/examples/react/nextjs-swr/package.json b/examples/react/nextjs-swr/package.json index 9a419e202d9..3010450e694 100644 --- a/examples/react/nextjs-swr/package.json +++ b/examples/react/nextjs-swr/package.json @@ -19,9 +19,9 @@ "swr": "^1.3.0" }, "devDependencies": { - "@graphql-codegen/cli": "^3.3.1", - "@graphql-codegen/client-preset": "^3.0.1", - "@graphql-codegen/schema-ast": "3.0.1", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", + "@graphql-codegen/schema-ast": "4.0.0", "@graphql-codegen/client-preset-swc-plugin": "0.2.0", "@types/node": "^18.11.18", "@types/react": "^18.0.17", diff --git a/examples/react/tanstack-react-query/package.json b/examples/react/tanstack-react-query/package.json index 2f6cb1ed168..05bb53e53dc 100644 --- a/examples/react/tanstack-react-query/package.json +++ b/examples/react/tanstack-react-query/package.json @@ -8,8 +8,8 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@graphql-codegen/cli": "^3.3.1", - "@graphql-codegen/client-preset": "^3.0.1", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", "@vitejs/plugin-react": "^3.1.0", "@types/jest": "^27.5.2", "@types/node": "^18.11.18", diff --git a/examples/react/urql/package.json b/examples/react/urql/package.json index d6773432b49..4d32fd1b928 100644 --- a/examples/react/urql/package.json +++ b/examples/react/urql/package.json @@ -10,8 +10,8 @@ "devDependencies": { "@types/react": "^18.0.17", "@types/react-dom": "^18.0.10", - "@graphql-codegen/cli": "^3.3.1", - "@graphql-codegen/client-preset": "^3.0.1", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", "@vitejs/plugin-react": "^3.1.0", "typescript": "5.0.4", "serve": "14.2.0", diff --git a/examples/typescript-esm/package.json b/examples/typescript-esm/package.json index cf32f57dd0d..ffd85414149 100644 --- a/examples/typescript-esm/package.json +++ b/examples/typescript-esm/package.json @@ -3,8 +3,8 @@ "version": "0.0.0", "private": true, "devDependencies": { - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/client-preset": "3.0.1" + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/client-preset": "4.0.0" }, "dependencies": { "@graphql-typed-document-node/core": "3.2.0", diff --git a/examples/typescript-graphql-request/package.json b/examples/typescript-graphql-request/package.json index 5ccffcdc24c..888f2213f90 100644 --- a/examples/typescript-graphql-request/package.json +++ b/examples/typescript-graphql-request/package.json @@ -3,8 +3,8 @@ "version": "0.0.0", "private": true, "devDependencies": { - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/client-preset": "3.0.1", + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/client-preset": "4.0.0", "babel-jest": "28.1.3", "jest": "28.1.3" }, diff --git a/examples/typescript-resolvers/package.json b/examples/typescript-resolvers/package.json index 7592b939835..b55e48dfc2b 100644 --- a/examples/typescript-resolvers/package.json +++ b/examples/typescript-resolvers/package.json @@ -3,9 +3,9 @@ "version": "0.0.0", "private": true, "devDependencies": { - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/typescript": "3.0.4", - "@graphql-codegen/typescript-resolvers": "3.2.1" + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/typescript": "4.0.0", + "@graphql-codegen/typescript-resolvers": "4.0.0" }, "dependencies": { "graphql": "16.6.0", diff --git a/examples/vite/vite-react-cts/package.json b/examples/vite/vite-react-cts/package.json index e7816d7bbc7..a9cb9cbebf0 100644 --- a/examples/vite/vite-react-cts/package.json +++ b/examples/vite/vite-react-cts/package.json @@ -21,8 +21,8 @@ "vite": "^4.1.0" }, "devDependencies": { - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/client-preset": "3.0.1", + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/client-preset": "4.0.0", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "cypress": "12.12.0", diff --git a/examples/vite/vite-react-mts/package.json b/examples/vite/vite-react-mts/package.json index 32525929299..d5407457be7 100644 --- a/examples/vite/vite-react-mts/package.json +++ b/examples/vite/vite-react-mts/package.json @@ -21,8 +21,8 @@ "vite": "^4.1.0" }, "devDependencies": { - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/client-preset": "3.0.1", + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/client-preset": "4.0.0", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "cypress": "12.12.0", diff --git a/examples/vite/vite-react-ts/package.json b/examples/vite/vite-react-ts/package.json index 28a2b082525..0449ef71333 100644 --- a/examples/vite/vite-react-ts/package.json +++ b/examples/vite/vite-react-ts/package.json @@ -21,8 +21,8 @@ "vite": "^4.1.0" }, "devDependencies": { - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/client-preset": "3.0.1", + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/client-preset": "4.0.0", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "cypress": "12.12.0", diff --git a/examples/vue/apollo-composable/package.json b/examples/vue/apollo-composable/package.json index 2ec8b34d61e..a340c422187 100644 --- a/examples/vue/apollo-composable/package.json +++ b/examples/vue/apollo-composable/package.json @@ -17,8 +17,8 @@ "vue": "^3.2.37" }, "devDependencies": { - "@graphql-codegen/cli": "^3.3.1", - "@graphql-codegen/client-preset": "^3.0.1", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", "@vitejs/plugin-vue": "^4.0.0", "typescript": "^5.0.0", "vite": "^4.1.0", diff --git a/examples/vue/urql/package.json b/examples/vue/urql/package.json index cedc1fb3ae0..b17afe515bc 100644 --- a/examples/vue/urql/package.json +++ b/examples/vue/urql/package.json @@ -16,8 +16,8 @@ "vue": "^3.2.45" }, "devDependencies": { - "@graphql-codegen/cli": "^3.3.1", - "@graphql-codegen/client-preset": "^3.0.1", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", "@vitejs/plugin-vue": "^4.0.0", "typescript": "^5.0.0", "vite": "^4.1.0", diff --git a/examples/vue/villus/package.json b/examples/vue/villus/package.json index c0118aadb46..11542a03593 100644 --- a/examples/vue/villus/package.json +++ b/examples/vue/villus/package.json @@ -16,8 +16,8 @@ "vue": "^3.2.37" }, "devDependencies": { - "@graphql-codegen/cli": "^3.3.1", - "@graphql-codegen/client-preset": "^3.0.1", + "@graphql-codegen/cli": "^4.0.0", + "@graphql-codegen/client-preset": "^4.0.0", "@vitejs/plugin-vue": "^4.0.0", "typescript": "^5.0.0", "vite": "^4.1.0", diff --git a/examples/yoga-tests/package.json b/examples/yoga-tests/package.json index 90ff23fb036..00850163332 100644 --- a/examples/yoga-tests/package.json +++ b/examples/yoga-tests/package.json @@ -9,8 +9,8 @@ "@graphql-typed-document-node/core": "3.2.0", "jest": "28.1.3", "babel-jest": "28.1.3", - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/client-preset": "3.0.1", + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/client-preset": "4.0.0", "@babel/core": "7.21.8", "@babel/preset-env": "7.21.5", "@babel/preset-typescript": "7.21.5" diff --git a/packages/graphql-codegen-cli/CHANGELOG.md b/packages/graphql-codegen-cli/CHANGELOG.md index 76f6bd6ac72..98fa1ae28bd 100644 --- a/packages/graphql-codegen-cli/CHANGELOG.md +++ b/packages/graphql-codegen-cli/CHANGELOG.md @@ -1,5 +1,40 @@ # @graphql-codegen/cli +## 4.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + + - Updated dependency [`graphql-config@^5.0.0` ↗︎](https://www.npmjs.com/package/graphql-config/v/5.0.0) (from `^4.5.0`, in `dependencies`) + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + + - Updated dependency [`@graphql-tools/apollo-engine-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/apollo-engine-loader/v/8.0.0) (from `^7.3.6`, in `dependencies`) + - Updated dependency [`@graphql-tools/code-file-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/code-file-loader/v/8.0.0) (from `^7.3.17`, in `dependencies`) + - Updated dependency [`@graphql-tools/git-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/git-loader/v/8.0.0) (from `^7.2.13`, in `dependencies`) + - Updated dependency [`@graphql-tools/github-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/github-loader/v/8.0.0) (from `^7.3.28`, in `dependencies`) + - Updated dependency [`@graphql-tools/graphql-file-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/graphql-file-loader/v/8.0.0) (from `^7.5.0`, in `dependencies`) + - Updated dependency [`@graphql-tools/json-file-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/json-file-loader/v/8.0.0) (from `^7.4.1`, in `dependencies`) + - Updated dependency [`@graphql-tools/load@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/load/v/8.0.0) (from `^7.8.0`, in `dependencies`) + - Updated dependency [`@graphql-tools/prisma-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/prisma-loader/v/8.0.0) (from `^7.2.69`, in `dependencies`) + - Updated dependency [`@graphql-tools/url-loader@^8.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/url-loader/v/8.0.0) (from `^7.17.17`, in `dependencies`) + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) + - Updated dependency [`cosmiconfig@^8.1.3` ↗︎](https://www.npmjs.com/package/cosmiconfig/v/8.1.3) (from `^7.0.0`, in `dependencies`) + - Updated dependency [`graphql-config@^5.0.1` ↗︎](https://www.npmjs.com/package/graphql-config/v/5.0.1) (from `^4.5.0`, in `dependencies`) + +- [#9371](https://github.com/dotansimha/graphql-code-generator/pull/9371) [`d431f426e`](https://github.com/dotansimha/graphql-code-generator/commit/d431f426eb594b820ac712b9f5c616f4badf6bff) Thanks [@Axxxx0n](https://github.com/Axxxx0n)! - Fixed option ignoreNoDocuments when using graphql configs + +- [#9275](https://github.com/dotansimha/graphql-code-generator/pull/9275) [`2a5da5894`](https://github.com/dotansimha/graphql-code-generator/commit/2a5da589468eb5970587187adae9892ff1f13134) Thanks [@milesrichardson](https://github.com/milesrichardson)! - Trigger rebuilds in watch mode while respecting rules of precedence and negation, both in terms of global (top-level) config vs. local (per-output target) config, and in terms of watch patterns (higher priority) vs. documents/schemas (lower priority). This fixes an issue with overly-aggressive rebuilds during watch mode. + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0)]: + - @graphql-codegen/core@4.0.0 + - @graphql-codegen/plugin-helpers@5.0.0 + ## 3.3.1 ### Patch Changes diff --git a/packages/graphql-codegen-cli/package.json b/packages/graphql-codegen-cli/package.json index 7e75991c8e1..37a7b3eb52f 100644 --- a/packages/graphql-codegen-cli/package.json +++ b/packages/graphql-codegen-cli/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/cli", - "version": "3.3.1", + "version": "4.0.0", "license": "MIT", "bin": { "gql-gen": "dist/cjs/bin.js", @@ -43,8 +43,8 @@ "@babel/generator": "^7.18.13", "@babel/template": "^7.18.10", "@babel/types": "^7.18.13", - "@graphql-codegen/core": "^3.1.0", - "@graphql-codegen/plugin-helpers": "^4.2.0", + "@graphql-codegen/core": "^4.0.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", "@graphql-tools/apollo-engine-loader": "^8.0.0", "@graphql-tools/code-file-loader": "^8.0.0", "@graphql-tools/git-loader": "^8.0.0", diff --git a/packages/graphql-codegen-core/CHANGELOG.md b/packages/graphql-codegen-core/CHANGELOG.md index eef9645b421..929789fc765 100644 --- a/packages/graphql-codegen-core/CHANGELOG.md +++ b/packages/graphql-codegen-core/CHANGELOG.md @@ -1,5 +1,19 @@ # @graphql-codegen/core +## 4.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + - Updated dependency [`@graphql-tools/schema@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/schema/v/10.0.0) (from `^9.0.0`, in `dependencies`) + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.1.1`, in `dependencies`) +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0)]: + - @graphql-codegen/plugin-helpers@5.0.0 + ## 3.1.0 ### Minor Changes diff --git a/packages/graphql-codegen-core/package.json b/packages/graphql-codegen-core/package.json index e1b8f763785..a70d46e755b 100644 --- a/packages/graphql-codegen-core/package.json +++ b/packages/graphql-codegen-core/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/core", - "version": "3.1.0", + "version": "4.0.0", "license": "MIT", "repository": { "type": "git", @@ -37,7 +37,7 @@ "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.1.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", "@graphql-tools/schema": "^10.0.0", "@graphql-tools/utils": "^10.0.0", "tslib": "~2.5.0" diff --git a/packages/plugins/other/add/CHANGELOG.md b/packages/plugins/other/add/CHANGELOG.md index 390d7094b45..c29b0151312 100644 --- a/packages/plugins/other/add/CHANGELOG.md +++ b/packages/plugins/other/add/CHANGELOG.md @@ -1,5 +1,16 @@ # @graphql-codegen/add +## 5.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0)]: + - @graphql-codegen/plugin-helpers@5.0.0 + ## 4.0.1 ### Patch Changes diff --git a/packages/plugins/other/add/package.json b/packages/plugins/other/add/package.json index b8b7523dd5c..5fea1587768 100644 --- a/packages/plugins/other/add/package.json +++ b/packages/plugins/other/add/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/add", - "version": "4.0.1", + "version": "5.0.0", "description": "GraphQL Code Generator plugin for adding custom content to your output file", "repository": { "type": "git", @@ -12,7 +12,7 @@ "lint": "eslint **/*.ts" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.1.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", "tslib": "~2.5.0" }, "peerDependencies": { diff --git a/packages/plugins/other/fragment-matcher/CHANGELOG.md b/packages/plugins/other/fragment-matcher/CHANGELOG.md index 5b3b5230404..04adfcf14fd 100644 --- a/packages/plugins/other/fragment-matcher/CHANGELOG.md +++ b/packages/plugins/other/fragment-matcher/CHANGELOG.md @@ -1,5 +1,16 @@ # @graphql-codegen/fragment-matcher +## 5.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0)]: + - @graphql-codegen/plugin-helpers@5.0.0 + ## 4.0.1 ### Patch Changes diff --git a/packages/plugins/other/fragment-matcher/package.json b/packages/plugins/other/fragment-matcher/package.json index 120673dfb2b..86903960018 100644 --- a/packages/plugins/other/fragment-matcher/package.json +++ b/packages/plugins/other/fragment-matcher/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/fragment-matcher", - "version": "4.0.1", + "version": "5.0.0", "description": "graphql-code-generate plugin for generating fragments matcher introspection file", "repository": { "type": "git", @@ -13,7 +13,7 @@ "test": "jest --no-watchman --config ../../../../jest.config.js" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.1.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", "tslib": "~2.5.0" }, "peerDependencies": { diff --git a/packages/plugins/other/introspection/CHANGELOG.md b/packages/plugins/other/introspection/CHANGELOG.md index 47ea7d755c1..122b4ae3079 100644 --- a/packages/plugins/other/introspection/CHANGELOG.md +++ b/packages/plugins/other/introspection/CHANGELOG.md @@ -1,5 +1,17 @@ # @graphql-codegen/introspection +## 4.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @graphql-codegen/plugin-helpers@5.0.0 + - @graphql-codegen/visitor-plugin-common@4.0.0 + ## 3.0.1 ### Patch Changes diff --git a/packages/plugins/other/introspection/package.json b/packages/plugins/other/introspection/package.json index e813b15f7f0..092d02e7f20 100644 --- a/packages/plugins/other/introspection/package.json +++ b/packages/plugins/other/introspection/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/introspection", - "version": "3.0.1", + "version": "4.0.0", "description": "GraphQL Code Generator plugin for generating an introspection JSON file for a GraphQLSchema", "repository": { "type": "git", @@ -13,8 +13,8 @@ "test": "jest --no-watchman --config ../../../../jest.config.js" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.1.0", - "@graphql-codegen/visitor-plugin-common": "^3.0.1", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/visitor-plugin-common": "^4.0.0", "tslib": "~2.5.0" }, "peerDependencies": { diff --git a/packages/plugins/other/schema-ast/CHANGELOG.md b/packages/plugins/other/schema-ast/CHANGELOG.md index c85f022d968..c2a4444645b 100644 --- a/packages/plugins/other/schema-ast/CHANGELOG.md +++ b/packages/plugins/other/schema-ast/CHANGELOG.md @@ -1,5 +1,18 @@ # @graphql-codegen/schema-ast +## 4.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0)]: + - @graphql-codegen/plugin-helpers@5.0.0 + ## 3.0.1 ### Patch Changes diff --git a/packages/plugins/other/schema-ast/package.json b/packages/plugins/other/schema-ast/package.json index e7195bd55d9..8b7b595ee07 100644 --- a/packages/plugins/other/schema-ast/package.json +++ b/packages/plugins/other/schema-ast/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/schema-ast", - "version": "3.0.1", + "version": "4.0.0", "description": "GraphQL Code Generator plugin for generating a .graphql file from a given schema", "repository": { "type": "git", @@ -13,7 +13,7 @@ "test": "jest --no-watchman --config ../../../../jest.config.js" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.1.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", "@graphql-tools/utils": "^10.0.0", "tslib": "~2.5.0" }, diff --git a/packages/plugins/other/time/CHANGELOG.md b/packages/plugins/other/time/CHANGELOG.md index 9f550d01659..722f0b57182 100644 --- a/packages/plugins/other/time/CHANGELOG.md +++ b/packages/plugins/other/time/CHANGELOG.md @@ -1,5 +1,16 @@ # @graphql-codegen/time +## 5.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0)]: + - @graphql-codegen/plugin-helpers@5.0.0 + ## 4.0.0 ### Major Changes diff --git a/packages/plugins/other/time/package.json b/packages/plugins/other/time/package.json index ff1e98f5321..aadd9ad25db 100644 --- a/packages/plugins/other/time/package.json +++ b/packages/plugins/other/time/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/time", - "version": "4.0.0", + "version": "5.0.0", "description": "GraphQL Code Generator plugin for adding the current time for an output file", "repository": { "type": "git", @@ -12,7 +12,7 @@ "lint": "eslint **/*.ts" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.0.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", "moment": "~2.29.1" }, "devDependencies": { diff --git a/packages/plugins/other/visitor-plugin-common/CHANGELOG.md b/packages/plugins/other/visitor-plugin-common/CHANGELOG.md index 5ee3b300bfb..8c6adc2230a 100644 --- a/packages/plugins/other/visitor-plugin-common/CHANGELOG.md +++ b/packages/plugins/other/visitor-plugin-common/CHANGELOG.md @@ -1,5 +1,351 @@ # @graphql-codegen/visitor-plugin-common +## 4.0.0 + +### Major Changes + +- [#9375](https://github.com/dotansimha/graphql-code-generator/pull/9375) [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929) Thanks [@eddeee888](https://github.com/eddeee888)! - Implement Scalars with input/output types + + In GraphQL, Scalar types can be different for client and server. For example, given the native GraphQL ID: + + - A client may send `string` or `number` in the input + - A client receives `string` in its selection set (i.e output) + - A server receives `string` in the resolver (GraphQL parses `string` or `number` received from the client to `string`) + - A server may return `string` or `number` (GraphQL serializes the value to `string` before sending it to the client ) + + Currently, we represent every Scalar with only one type. This is what codegen generates as base type: + + ```ts + export type Scalars = { + ID: string; + }; + ``` + + Then, this is used in both input and output type e.g. + + ```ts + export type Book = { + __typename?: 'Book'; + id: Scalars['ID']; // Output's ID can be `string` 👍 + }; + + export type QueryBookArgs = { + id: Scalars['ID']; // Input's ID can be `string` or `number`. However, the type is only `string` here 👎 + }; + ``` + + This PR extends each Scalar to have input and output: + + ```ts + export type Scalars = { + ID: { + input: string | number; + output: string; + }; + }; + ``` + + Then, each input/output GraphQL type can correctly refer to the correct input/output scalar type: + + ```ts + export type Book = { + __typename?: 'Book'; + id: Scalars['ID']['output']; // Output's ID can be `string` 👍 + }; + + export type QueryBookArgs = { + id: Scalars['ID']['input']; // Input's ID can be `string` or `number` 👍 + }; + ``` + + Note that for `typescript-resolvers`, the type of ID needs to be inverted. However, the referenced types in GraphQL input/output types should still work correctly: + + ```ts + export type Scalars = { + ID: { + input: string; + output: string | number; + } + } + + export type Book = { + __typename?: "Book"; + id: Scalars["ID"]['output']; // Resolvers can return `string` or `number` in ID fields 👍 + }; + + export type QueryBookArgs = { + id: Scalars["ID"]['input']; // Resolvers receive `string` in ID fields 👍 + }; + + export type ResolversTypes = { + ID: ID: ResolverTypeWrapper; // Resolvers can return `string` or `number` in ID fields 👍 + } + + export type ResolversParentTypes = { + ID: Scalars['ID']['output']; // Resolvers receive `string` or `number` from parents 👍 + }; + ``` + + *** + + Config changes: + + 1. Scalars option can now take input/output types: + + ```ts + config: { + scalars: { + ID: { + input: 'string', + output: 'string | number' + } + } + } + ``` + + 2. If a string is given (instead of an object with input/output fields), it will be used as both input and output types: + + ```ts + config: { + scalars: { + ID: 'string'; // This means `string` will be used for both ID's input and output types + } + } + ``` + + 3. BREAKING CHANGE: External module Scalar types need to be an object with input/output fields + + ```ts + config: { + scalars: { + ID: './path/to/scalar-module'; + } + } + ``` + + If correctly, wired up, the following will be generated: + + ```ts + // Previously, imported `ID` type can be a primitive type, now it must be an object with input/output fields + import { ID } from './path/to/scalar-module'; + + export type Scalars = { + ID: { input: ID['input']; output: ID['output'] }; + }; + ``` + + *** + + BREAKING CHANGE: This changes Scalar types which could be referenced in other plugins. If you are a plugin maintainer and reference Scalar, please update your plugin to use the correct input/output types. + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Minor Changes + +- [#9196](https://github.com/dotansimha/graphql-code-generator/pull/9196) [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96) Thanks [@beerose](https://github.com/beerose)! - Add `@defer` directive support + + When 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. + + ```jsx + // 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. + + ```tsx + // gql/graphql.ts + export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({ + __typename?: 'Query'; + } & { + ' $fragmentRefs'?: { OrdersFragment: Incremental }; + }); + ``` + + Apart from generating code that includes support for the `@defer` directive, the Codegen also exports a utility function called `isFragmentReady`. You can use it to conditionally render components based on whether the data for a deferred + fragment is available: + + ```jsx + const OrdersList = (props: { data: FragmentType }) => { + const data = useFragment(OrdersFragment, props.data); + return ( + // render orders list + ) + }; + + function App() { + const { data } = useQuery(GetUserQuery); + return ( + {data && ( + <> + {isFragmentReady(GetUserQuery, OrdersFragment, data) + && } + + )} + ); + } + export default App; + ``` + +- [#9339](https://github.com/dotansimha/graphql-code-generator/pull/9339) [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c) Thanks [@AaronMoat](https://github.com/AaronMoat)! - Add excludeTypes config to resolversNonOptionalTypename + + This disables the adding of `__typename` in resolver types for any specified typename. This could be useful e.g. if you're wanting to enable this for all new types going forward but not do a big migration. + + Usage example: + + ```typescript + const config: CodegenConfig = { + schema: 'src/schema/**/*.graphql', + generates: { + 'src/schema/types.ts': { + plugins: ['typescript', 'typescript-resolvers'], + config: { + resolversNonOptionalTypename: { + unionMember: true, + excludeTypes: ['MyType'], + }, + }, + }, + }, + }; + ``` + +- [#9229](https://github.com/dotansimha/graphql-code-generator/pull/9229) [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c) Thanks [@eddeee888](https://github.com/eddeee888)! - Use generic to simplify ResolversUnionTypes + + This follows the `ResolversInterfaceTypes`'s approach where the `RefType` generic is used to refer back to `ResolversTypes` or `ResolversParentTypes` in cases of nested Union types + +- [#9304](https://github.com/dotansimha/graphql-code-generator/pull/9304) [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823) Thanks [@esfomeado](https://github.com/esfomeado)! - Added support for disabling suffixes on Enums. + +- [#9229](https://github.com/dotansimha/graphql-code-generator/pull/9229) [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c) Thanks [@eddeee888](https://github.com/eddeee888)! - Extract interfaces to ResolversInterfaceTypes and add to resolversNonOptionalTypename + + 1. `ResolversInterfaceTypes` is a new type that keeps track of a GraphQL interface and its implementing types. + + For example, consider this schema: + + ```graphql + extend type Query { + character(id: ID!): CharacterNode + } + + interface CharacterNode { + id: ID! + } + + type Wizard implements CharacterNode { + id: ID! + screenName: String! + spells: [String!]! + } + + type Fighter implements CharacterNode { + id: ID! + screenName: String! + powerLevel: Int! + } + ``` + + The generated types will look like this: + + ```ts + export type ResolversInterfaceTypes> = { + CharacterNode: Fighter | Wizard; + }; + + export type ResolversTypes = { + // other types... + CharacterNode: ResolverTypeWrapper['CharacterNode']>; + Fighter: ResolverTypeWrapper; + Wizard: ResolverTypeWrapper; + // other types... + }; + + export type ResolversParentTypes = { + // other types... + CharacterNode: ResolversInterfaceTypes['CharacterNode']; + Fighter: Fighter; + Wizard: Wizard; + // other types... + }; + ``` + + The `RefType` generic is used to reference back to `ResolversTypes` and `ResolversParentTypes` in some cases such as field returning a Union. + + 2. `resolversNonOptionalTypename` also affects `ResolversInterfaceTypes` + + Using the schema above, if we use `resolversNonOptionalTypename` option: + + ```typescript + const config: CodegenConfig = { + schema: 'src/schema/**/*.graphql', + generates: { + 'src/schema/types.ts': { + plugins: ['typescript', 'typescript-resolvers'], + config: { + resolversNonOptionalTypename: true, // Or `resolversNonOptionalTypename: { interfaceImplementingType: true }` + }, + }, + }, + }; + ``` + + Then, the generated type looks like this: + + ```ts + export type ResolversInterfaceTypes> = { + CharacterNode: (Fighter & { __typename: 'Fighter' }) | (Wizard & { __typename: 'Wizard' }); + }; + + export type ResolversTypes = { + // other types... + CharacterNode: ResolverTypeWrapper['CharacterNode']>; + Fighter: ResolverTypeWrapper; + Wizard: ResolverTypeWrapper; + // other types... + }; + + export type ResolversParentTypes = { + // other types... + CharacterNode: ResolversInterfaceTypes['CharacterNode']; + Fighter: Fighter; + Wizard: Wizard; + // other types... + }; + ``` + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + + - Updated dependency [`@graphql-tools/optimize@^2.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/optimize/v/2.0.0) (from `^1.3.0`, in `dependencies`) + - Updated dependency [`@graphql-tools/relay-operation-optimizer@^7.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/relay-operation-optimizer/v/7.0.0) (from `^6.5.0`, in `dependencies`) + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) + +- [#9414](https://github.com/dotansimha/graphql-code-generator/pull/9414) [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d) Thanks [@beerose](https://github.com/beerose)! - Include nested fragments in string documentMode + +- [#9369](https://github.com/dotansimha/graphql-code-generator/pull/9369) [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30) Thanks [@asmundg](https://github.com/asmundg)! - Output valid type names with mergeFragmentTypes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0)]: + - @graphql-codegen/plugin-helpers@5.0.0 + ## 3.1.1 ### Patch Changes diff --git a/packages/plugins/other/visitor-plugin-common/package.json b/packages/plugins/other/visitor-plugin-common/package.json index e3ba6a9b3ae..b2407c55956 100644 --- a/packages/plugins/other/visitor-plugin-common/package.json +++ b/packages/plugins/other/visitor-plugin-common/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/visitor-plugin-common", - "version": "3.1.1", + "version": "4.0.0", "license": "MIT", "repository": { "type": "git", @@ -13,7 +13,7 @@ }, "dependencies": { "@graphql-tools/optimize": "^2.0.0", - "@graphql-codegen/plugin-helpers": "^4.2.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", "@graphql-tools/relay-operation-optimizer": "^7.0.0", "@graphql-tools/utils": "^10.0.0", "auto-bind": "~4.0.0", diff --git a/packages/plugins/typescript/document-nodes/CHANGELOG.md b/packages/plugins/typescript/document-nodes/CHANGELOG.md index afd2fa14477..9e927aa1850 100644 --- a/packages/plugins/typescript/document-nodes/CHANGELOG.md +++ b/packages/plugins/typescript/document-nodes/CHANGELOG.md @@ -1,5 +1,17 @@ # @graphql-codegen/typescript-document-nodes +## 4.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @graphql-codegen/plugin-helpers@5.0.0 + - @graphql-codegen/visitor-plugin-common@4.0.0 + ## 3.0.4 ### Patch Changes diff --git a/packages/plugins/typescript/document-nodes/package.json b/packages/plugins/typescript/document-nodes/package.json index 62c6e043d8e..691539a047e 100644 --- a/packages/plugins/typescript/document-nodes/package.json +++ b/packages/plugins/typescript/document-nodes/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/typescript-document-nodes", - "version": "3.0.4", + "version": "4.0.0", "description": "GraphQL Code Generator plugin for generating TypeScript modules with embedded GraphQL document nodes", "repository": { "type": "git", @@ -13,8 +13,8 @@ "test": "jest --no-watchman --config ../../../../jest.config.js" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.2.0", - "@graphql-codegen/visitor-plugin-common": "3.1.1", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/visitor-plugin-common": "4.0.0", "auto-bind": "~4.0.0", "tslib": "~2.5.0" }, diff --git a/packages/plugins/typescript/gql-tag-operations/CHANGELOG.md b/packages/plugins/typescript/gql-tag-operations/CHANGELOG.md index de4f86ceece..a6f72df57d6 100644 --- a/packages/plugins/typescript/gql-tag-operations/CHANGELOG.md +++ b/packages/plugins/typescript/gql-tag-operations/CHANGELOG.md @@ -1,5 +1,19 @@ # @graphql-codegen/gql-tag-operations +## 4.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @graphql-codegen/plugin-helpers@5.0.0 + - @graphql-codegen/visitor-plugin-common@4.0.0 + ## 3.0.1 ### Patch Changes diff --git a/packages/plugins/typescript/gql-tag-operations/package.json b/packages/plugins/typescript/gql-tag-operations/package.json index 7770f1af352..10c8b9d224b 100644 --- a/packages/plugins/typescript/gql-tag-operations/package.json +++ b/packages/plugins/typescript/gql-tag-operations/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/gql-tag-operations", - "version": "3.0.1", + "version": "4.0.0", "description": "GraphQL Code Generator plugin for generating a typed gql tag function", "repository": { "type": "git", @@ -17,8 +17,8 @@ }, "dependencies": { "@graphql-tools/utils": "^10.0.0", - "@graphql-codegen/plugin-helpers": "^4.2.0", - "@graphql-codegen/visitor-plugin-common": "3.1.1", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/visitor-plugin-common": "4.0.0", "auto-bind": "~4.0.0", "tslib": "~2.5.0" }, diff --git a/packages/plugins/typescript/operations/CHANGELOG.md b/packages/plugins/typescript/operations/CHANGELOG.md index 734bc9382ae..f1b7389e2d8 100644 --- a/packages/plugins/typescript/operations/CHANGELOG.md +++ b/packages/plugins/typescript/operations/CHANGELOG.md @@ -1,5 +1,220 @@ # @graphql-codegen/typescript-operations +## 4.0.0 + +### Major Changes + +- [#9375](https://github.com/dotansimha/graphql-code-generator/pull/9375) [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929) Thanks [@eddeee888](https://github.com/eddeee888)! - Implement Scalars with input/output types + + In GraphQL, Scalar types can be different for client and server. For example, given the native GraphQL ID: + + - A client may send `string` or `number` in the input + - A client receives `string` in its selection set (i.e output) + - A server receives `string` in the resolver (GraphQL parses `string` or `number` received from the client to `string`) + - A server may return `string` or `number` (GraphQL serializes the value to `string` before sending it to the client ) + + Currently, we represent every Scalar with only one type. This is what codegen generates as base type: + + ```ts + export type Scalars = { + ID: string; + }; + ``` + + Then, this is used in both input and output type e.g. + + ```ts + export type Book = { + __typename?: 'Book'; + id: Scalars['ID']; // Output's ID can be `string` 👍 + }; + + export type QueryBookArgs = { + id: Scalars['ID']; // Input's ID can be `string` or `number`. However, the type is only `string` here 👎 + }; + ``` + + This PR extends each Scalar to have input and output: + + ```ts + export type Scalars = { + ID: { + input: string | number; + output: string; + }; + }; + ``` + + Then, each input/output GraphQL type can correctly refer to the correct input/output scalar type: + + ```ts + export type Book = { + __typename?: 'Book'; + id: Scalars['ID']['output']; // Output's ID can be `string` 👍 + }; + + export type QueryBookArgs = { + id: Scalars['ID']['input']; // Input's ID can be `string` or `number` 👍 + }; + ``` + + Note that for `typescript-resolvers`, the type of ID needs to be inverted. However, the referenced types in GraphQL input/output types should still work correctly: + + ```ts + export type Scalars = { + ID: { + input: string; + output: string | number; + } + } + + export type Book = { + __typename?: "Book"; + id: Scalars["ID"]['output']; // Resolvers can return `string` or `number` in ID fields 👍 + }; + + export type QueryBookArgs = { + id: Scalars["ID"]['input']; // Resolvers receive `string` in ID fields 👍 + }; + + export type ResolversTypes = { + ID: ID: ResolverTypeWrapper; // Resolvers can return `string` or `number` in ID fields 👍 + } + + export type ResolversParentTypes = { + ID: Scalars['ID']['output']; // Resolvers receive `string` or `number` from parents 👍 + }; + ``` + + *** + + Config changes: + + 1. Scalars option can now take input/output types: + + ```ts + config: { + scalars: { + ID: { + input: 'string', + output: 'string | number' + } + } + } + ``` + + 2. If a string is given (instead of an object with input/output fields), it will be used as both input and output types: + + ```ts + config: { + scalars: { + ID: 'string'; // This means `string` will be used for both ID's input and output types + } + } + ``` + + 3. BREAKING CHANGE: External module Scalar types need to be an object with input/output fields + + ```ts + config: { + scalars: { + ID: './path/to/scalar-module'; + } + } + ``` + + If correctly, wired up, the following will be generated: + + ```ts + // Previously, imported `ID` type can be a primitive type, now it must be an object with input/output fields + import { ID } from './path/to/scalar-module'; + + export type Scalars = { + ID: { input: ID['input']; output: ID['output'] }; + }; + ``` + + *** + + BREAKING CHANGE: This changes Scalar types which could be referenced in other plugins. If you are a plugin maintainer and reference Scalar, please update your plugin to use the correct input/output types. + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Minor Changes + +- [#9196](https://github.com/dotansimha/graphql-code-generator/pull/9196) [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96) Thanks [@beerose](https://github.com/beerose)! - Add `@defer` directive support + + When 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. + + ```jsx + // 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. + + ```tsx + // gql/graphql.ts + export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({ + __typename?: 'Query'; + } & { + ' $fragmentRefs'?: { OrdersFragment: Incremental }; + }); + ``` + + Apart from generating code that includes support for the `@defer` directive, the Codegen also exports a utility function called `isFragmentReady`. You can use it to conditionally render components based on whether the data for a deferred + fragment is available: + + ```jsx + const OrdersList = (props: { data: FragmentType }) => { + const data = useFragment(OrdersFragment, props.data); + return ( + // render orders list + ) + }; + + function App() { + const { data } = useQuery(GetUserQuery); + return ( + {data && ( + <> + {isFragmentReady(GetUserQuery, OrdersFragment, data) + && } + + )} + ); + } + export default App; + ``` + +- [#9304](https://github.com/dotansimha/graphql-code-generator/pull/9304) [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823) Thanks [@esfomeado](https://github.com/esfomeado)! - Added support for disabling suffixes on Enums. + +### Patch Changes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @graphql-codegen/plugin-helpers@5.0.0 + - @graphql-codegen/visitor-plugin-common@4.0.0 + - @graphql-codegen/typescript@4.0.0 + ## 3.0.4 ### Patch Changes diff --git a/packages/plugins/typescript/operations/package.json b/packages/plugins/typescript/operations/package.json index 9b4f51addc8..669478974ad 100644 --- a/packages/plugins/typescript/operations/package.json +++ b/packages/plugins/typescript/operations/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/typescript-operations", - "version": "3.0.4", + "version": "4.0.0", "description": "GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments", "repository": { "type": "git", @@ -13,9 +13,9 @@ "test": "jest --no-watchman --config ../../../../jest.config.js" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.2.0", - "@graphql-codegen/typescript": "^3.0.4", - "@graphql-codegen/visitor-plugin-common": "3.1.1", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/typescript": "^4.0.0", + "@graphql-codegen/visitor-plugin-common": "4.0.0", "auto-bind": "~4.0.0", "tslib": "~2.5.0" }, diff --git a/packages/plugins/typescript/resolvers/CHANGELOG.md b/packages/plugins/typescript/resolvers/CHANGELOG.md index 4535332ad84..0a088002ad2 100644 --- a/packages/plugins/typescript/resolvers/CHANGELOG.md +++ b/packages/plugins/typescript/resolvers/CHANGELOG.md @@ -1,5 +1,345 @@ # @graphql-codegen/typescript-resolvers +## 4.0.0 + +### Major Changes + +- [#9375](https://github.com/dotansimha/graphql-code-generator/pull/9375) [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929) Thanks [@eddeee888](https://github.com/eddeee888)! - Implement Scalars with input/output types + + In GraphQL, Scalar types can be different for client and server. For example, given the native GraphQL ID: + + - A client may send `string` or `number` in the input + - A client receives `string` in its selection set (i.e output) + - A server receives `string` in the resolver (GraphQL parses `string` or `number` received from the client to `string`) + - A server may return `string` or `number` (GraphQL serializes the value to `string` before sending it to the client ) + + Currently, we represent every Scalar with only one type. This is what codegen generates as base type: + + ```ts + export type Scalars = { + ID: string; + }; + ``` + + Then, this is used in both input and output type e.g. + + ```ts + export type Book = { + __typename?: 'Book'; + id: Scalars['ID']; // Output's ID can be `string` 👍 + }; + + export type QueryBookArgs = { + id: Scalars['ID']; // Input's ID can be `string` or `number`. However, the type is only `string` here 👎 + }; + ``` + + This PR extends each Scalar to have input and output: + + ```ts + export type Scalars = { + ID: { + input: string | number; + output: string; + }; + }; + ``` + + Then, each input/output GraphQL type can correctly refer to the correct input/output scalar type: + + ```ts + export type Book = { + __typename?: 'Book'; + id: Scalars['ID']['output']; // Output's ID can be `string` 👍 + }; + + export type QueryBookArgs = { + id: Scalars['ID']['input']; // Input's ID can be `string` or `number` 👍 + }; + ``` + + Note that for `typescript-resolvers`, the type of ID needs to be inverted. However, the referenced types in GraphQL input/output types should still work correctly: + + ```ts + export type Scalars = { + ID: { + input: string; + output: string | number; + } + } + + export type Book = { + __typename?: "Book"; + id: Scalars["ID"]['output']; // Resolvers can return `string` or `number` in ID fields 👍 + }; + + export type QueryBookArgs = { + id: Scalars["ID"]['input']; // Resolvers receive `string` in ID fields 👍 + }; + + export type ResolversTypes = { + ID: ID: ResolverTypeWrapper; // Resolvers can return `string` or `number` in ID fields 👍 + } + + export type ResolversParentTypes = { + ID: Scalars['ID']['output']; // Resolvers receive `string` or `number` from parents 👍 + }; + ``` + + *** + + Config changes: + + 1. Scalars option can now take input/output types: + + ```ts + config: { + scalars: { + ID: { + input: 'string', + output: 'string | number' + } + } + } + ``` + + 2. If a string is given (instead of an object with input/output fields), it will be used as both input and output types: + + ```ts + config: { + scalars: { + ID: 'string'; // This means `string` will be used for both ID's input and output types + } + } + ``` + + 3. BREAKING CHANGE: External module Scalar types need to be an object with input/output fields + + ```ts + config: { + scalars: { + ID: './path/to/scalar-module'; + } + } + ``` + + If correctly, wired up, the following will be generated: + + ```ts + // Previously, imported `ID` type can be a primitive type, now it must be an object with input/output fields + import { ID } from './path/to/scalar-module'; + + export type Scalars = { + ID: { input: ID['input']; output: ID['output'] }; + }; + ``` + + *** + + BREAKING CHANGE: This changes Scalar types which could be referenced in other plugins. If you are a plugin maintainer and reference Scalar, please update your plugin to use the correct input/output types. + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Minor Changes + +- [#9196](https://github.com/dotansimha/graphql-code-generator/pull/9196) [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96) Thanks [@beerose](https://github.com/beerose)! - Add `@defer` directive support + + When 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. + + ```jsx + // 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. + + ```tsx + // gql/graphql.ts + export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({ + __typename?: 'Query'; + } & { + ' $fragmentRefs'?: { OrdersFragment: Incremental }; + }); + ``` + + Apart from generating code that includes support for the `@defer` directive, the Codegen also exports a utility function called `isFragmentReady`. You can use it to conditionally render components based on whether the data for a deferred + fragment is available: + + ```jsx + const OrdersList = (props: { data: FragmentType }) => { + const data = useFragment(OrdersFragment, props.data); + return ( + // render orders list + ) + }; + + function App() { + const { data } = useQuery(GetUserQuery); + return ( + {data && ( + <> + {isFragmentReady(GetUserQuery, OrdersFragment, data) + && } + + )} + ); + } + export default App; + ``` + +- [#9339](https://github.com/dotansimha/graphql-code-generator/pull/9339) [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c) Thanks [@AaronMoat](https://github.com/AaronMoat)! - Add excludeTypes config to resolversNonOptionalTypename + + This disables the adding of `__typename` in resolver types for any specified typename. This could be useful e.g. if you're wanting to enable this for all new types going forward but not do a big migration. + + Usage example: + + ```typescript + const config: CodegenConfig = { + schema: 'src/schema/**/*.graphql', + generates: { + 'src/schema/types.ts': { + plugins: ['typescript', 'typescript-resolvers'], + config: { + resolversNonOptionalTypename: { + unionMember: true, + excludeTypes: ['MyType'], + }, + }, + }, + }, + }; + ``` + +- [#9229](https://github.com/dotansimha/graphql-code-generator/pull/9229) [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c) Thanks [@eddeee888](https://github.com/eddeee888)! - Use generic to simplify ResolversUnionTypes + + This follows the `ResolversInterfaceTypes`'s approach where the `RefType` generic is used to refer back to `ResolversTypes` or `ResolversParentTypes` in cases of nested Union types + +- [#9304](https://github.com/dotansimha/graphql-code-generator/pull/9304) [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823) Thanks [@esfomeado](https://github.com/esfomeado)! - Added support for disabling suffixes on Enums. + +- [#9229](https://github.com/dotansimha/graphql-code-generator/pull/9229) [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c) Thanks [@eddeee888](https://github.com/eddeee888)! - Extract interfaces to ResolversInterfaceTypes and add to resolversNonOptionalTypename + + 1. `ResolversInterfaceTypes` is a new type that keeps track of a GraphQL interface and its implementing types. + + For example, consider this schema: + + ```graphql + extend type Query { + character(id: ID!): CharacterNode + } + + interface CharacterNode { + id: ID! + } + + type Wizard implements CharacterNode { + id: ID! + screenName: String! + spells: [String!]! + } + + type Fighter implements CharacterNode { + id: ID! + screenName: String! + powerLevel: Int! + } + ``` + + The generated types will look like this: + + ```ts + export type ResolversInterfaceTypes> = { + CharacterNode: Fighter | Wizard; + }; + + export type ResolversTypes = { + // other types... + CharacterNode: ResolverTypeWrapper['CharacterNode']>; + Fighter: ResolverTypeWrapper; + Wizard: ResolverTypeWrapper; + // other types... + }; + + export type ResolversParentTypes = { + // other types... + CharacterNode: ResolversInterfaceTypes['CharacterNode']; + Fighter: Fighter; + Wizard: Wizard; + // other types... + }; + ``` + + The `RefType` generic is used to reference back to `ResolversTypes` and `ResolversParentTypes` in some cases such as field returning a Union. + + 2. `resolversNonOptionalTypename` also affects `ResolversInterfaceTypes` + + Using the schema above, if we use `resolversNonOptionalTypename` option: + + ```typescript + const config: CodegenConfig = { + schema: 'src/schema/**/*.graphql', + generates: { + 'src/schema/types.ts': { + plugins: ['typescript', 'typescript-resolvers'], + config: { + resolversNonOptionalTypename: true, // Or `resolversNonOptionalTypename: { interfaceImplementingType: true }` + }, + }, + }, + }; + ``` + + Then, the generated type looks like this: + + ```ts + export type ResolversInterfaceTypes> = { + CharacterNode: (Fighter & { __typename: 'Fighter' }) | (Wizard & { __typename: 'Wizard' }); + }; + + export type ResolversTypes = { + // other types... + CharacterNode: ResolverTypeWrapper['CharacterNode']>; + Fighter: ResolverTypeWrapper; + Wizard: ResolverTypeWrapper; + // other types... + }; + + export type ResolversParentTypes = { + // other types... + CharacterNode: ResolversInterfaceTypes['CharacterNode']; + Fighter: Fighter; + Wizard: Wizard; + // other types... + }; + ``` + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @graphql-codegen/plugin-helpers@5.0.0 + - @graphql-codegen/visitor-plugin-common@4.0.0 + - @graphql-codegen/typescript@4.0.0 + ## 3.2.1 ### Patch Changes diff --git a/packages/plugins/typescript/resolvers/package.json b/packages/plugins/typescript/resolvers/package.json index 063e11c8fcd..8bd60448400 100644 --- a/packages/plugins/typescript/resolvers/package.json +++ b/packages/plugins/typescript/resolvers/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/typescript-resolvers", - "version": "3.2.1", + "version": "4.0.0", "description": "GraphQL Code Generator plugin for generating TypeScript types for resolvers signature", "repository": { "type": "git", @@ -13,9 +13,9 @@ "test": "jest --no-watchman --config ../../../../jest.config.js" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.2.0", - "@graphql-codegen/typescript": "^3.0.4", - "@graphql-codegen/visitor-plugin-common": "3.1.1", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/typescript": "^4.0.0", + "@graphql-codegen/visitor-plugin-common": "4.0.0", "@graphql-tools/utils": "^10.0.0", "auto-bind": "~4.0.0", "tslib": "~2.5.0" diff --git a/packages/plugins/typescript/typed-document-node/CHANGELOG.md b/packages/plugins/typescript/typed-document-node/CHANGELOG.md index b934c47c865..a69bae6b39e 100644 --- a/packages/plugins/typescript/typed-document-node/CHANGELOG.md +++ b/packages/plugins/typescript/typed-document-node/CHANGELOG.md @@ -1,5 +1,83 @@ # @graphql-codegen/typed-document-node +## 5.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Minor Changes + +- [#9196](https://github.com/dotansimha/graphql-code-generator/pull/9196) [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96) Thanks [@beerose](https://github.com/beerose)! - Add `@defer` directive support + + When 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. + + ```jsx + // 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. + + ```tsx + // gql/graphql.ts + export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({ + __typename?: 'Query'; + } & { + ' $fragmentRefs'?: { OrdersFragment: Incremental }; + }); + ``` + + Apart from generating code that includes support for the `@defer` directive, the Codegen also exports a utility function called `isFragmentReady`. You can use it to conditionally render components based on whether the data for a deferred + fragment is available: + + ```jsx + const OrdersList = (props: { data: FragmentType }) => { + const data = useFragment(OrdersFragment, props.data); + return ( + // render orders list + ) + }; + + function App() { + const { data } = useQuery(GetUserQuery); + return ( + {data && ( + <> + {isFragmentReady(GetUserQuery, OrdersFragment, data) + && } + + )} + ); + } + export default App; + ``` + +### Patch Changes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @graphql-codegen/plugin-helpers@5.0.0 + - @graphql-codegen/visitor-plugin-common@4.0.0 + ## 4.0.1 ### Patch Changes diff --git a/packages/plugins/typescript/typed-document-node/package.json b/packages/plugins/typescript/typed-document-node/package.json index 868b5e9c6d1..06b2cadfad1 100644 --- a/packages/plugins/typescript/typed-document-node/package.json +++ b/packages/plugins/typescript/typed-document-node/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/typed-document-node", - "version": "4.0.1", + "version": "5.0.0", "description": "GraphQL Code Generator plugin for generating ready-to-use TypedDocumentNode based on GraphQL operations", "repository": { "type": "git", @@ -17,8 +17,8 @@ }, "dependencies": { "change-case-all": "1.0.15", - "@graphql-codegen/plugin-helpers": "^4.2.0", - "@graphql-codegen/visitor-plugin-common": "3.1.1", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/visitor-plugin-common": "4.0.0", "auto-bind": "~4.0.0", "tslib": "~2.5.0" }, diff --git a/packages/plugins/typescript/typescript/CHANGELOG.md b/packages/plugins/typescript/typescript/CHANGELOG.md index e44bc9c1255..7d72af164e9 100644 --- a/packages/plugins/typescript/typescript/CHANGELOG.md +++ b/packages/plugins/typescript/typescript/CHANGELOG.md @@ -1,5 +1,220 @@ # @graphql-codegen/typescript +## 4.0.0 + +### Major Changes + +- [#9375](https://github.com/dotansimha/graphql-code-generator/pull/9375) [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929) Thanks [@eddeee888](https://github.com/eddeee888)! - Implement Scalars with input/output types + + In GraphQL, Scalar types can be different for client and server. For example, given the native GraphQL ID: + + - A client may send `string` or `number` in the input + - A client receives `string` in its selection set (i.e output) + - A server receives `string` in the resolver (GraphQL parses `string` or `number` received from the client to `string`) + - A server may return `string` or `number` (GraphQL serializes the value to `string` before sending it to the client ) + + Currently, we represent every Scalar with only one type. This is what codegen generates as base type: + + ```ts + export type Scalars = { + ID: string; + }; + ``` + + Then, this is used in both input and output type e.g. + + ```ts + export type Book = { + __typename?: 'Book'; + id: Scalars['ID']; // Output's ID can be `string` 👍 + }; + + export type QueryBookArgs = { + id: Scalars['ID']; // Input's ID can be `string` or `number`. However, the type is only `string` here 👎 + }; + ``` + + This PR extends each Scalar to have input and output: + + ```ts + export type Scalars = { + ID: { + input: string | number; + output: string; + }; + }; + ``` + + Then, each input/output GraphQL type can correctly refer to the correct input/output scalar type: + + ```ts + export type Book = { + __typename?: 'Book'; + id: Scalars['ID']['output']; // Output's ID can be `string` 👍 + }; + + export type QueryBookArgs = { + id: Scalars['ID']['input']; // Input's ID can be `string` or `number` 👍 + }; + ``` + + Note that for `typescript-resolvers`, the type of ID needs to be inverted. However, the referenced types in GraphQL input/output types should still work correctly: + + ```ts + export type Scalars = { + ID: { + input: string; + output: string | number; + } + } + + export type Book = { + __typename?: "Book"; + id: Scalars["ID"]['output']; // Resolvers can return `string` or `number` in ID fields 👍 + }; + + export type QueryBookArgs = { + id: Scalars["ID"]['input']; // Resolvers receive `string` in ID fields 👍 + }; + + export type ResolversTypes = { + ID: ID: ResolverTypeWrapper; // Resolvers can return `string` or `number` in ID fields 👍 + } + + export type ResolversParentTypes = { + ID: Scalars['ID']['output']; // Resolvers receive `string` or `number` from parents 👍 + }; + ``` + + *** + + Config changes: + + 1. Scalars option can now take input/output types: + + ```ts + config: { + scalars: { + ID: { + input: 'string', + output: 'string | number' + } + } + } + ``` + + 2. If a string is given (instead of an object with input/output fields), it will be used as both input and output types: + + ```ts + config: { + scalars: { + ID: 'string'; // This means `string` will be used for both ID's input and output types + } + } + ``` + + 3. BREAKING CHANGE: External module Scalar types need to be an object with input/output fields + + ```ts + config: { + scalars: { + ID: './path/to/scalar-module'; + } + } + ``` + + If correctly, wired up, the following will be generated: + + ```ts + // Previously, imported `ID` type can be a primitive type, now it must be an object with input/output fields + import { ID } from './path/to/scalar-module'; + + export type Scalars = { + ID: { input: ID['input']; output: ID['output'] }; + }; + ``` + + *** + + BREAKING CHANGE: This changes Scalar types which could be referenced in other plugins. If you are a plugin maintainer and reference Scalar, please update your plugin to use the correct input/output types. + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Minor Changes + +- [#9196](https://github.com/dotansimha/graphql-code-generator/pull/9196) [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96) Thanks [@beerose](https://github.com/beerose)! - Add `@defer` directive support + + When 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. + + ```jsx + // 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. + + ```tsx + // gql/graphql.ts + export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({ + __typename?: 'Query'; + } & { + ' $fragmentRefs'?: { OrdersFragment: Incremental }; + }); + ``` + + Apart from generating code that includes support for the `@defer` directive, the Codegen also exports a utility function called `isFragmentReady`. You can use it to conditionally render components based on whether the data for a deferred + fragment is available: + + ```jsx + const OrdersList = (props: { data: FragmentType }) => { + const data = useFragment(OrdersFragment, props.data); + return ( + // render orders list + ) + }; + + function App() { + const { data } = useQuery(GetUserQuery); + return ( + {data && ( + <> + {isFragmentReady(GetUserQuery, OrdersFragment, data) + && } + + )} + ); + } + export default App; + ``` + +- [#9304](https://github.com/dotansimha/graphql-code-generator/pull/9304) [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823) Thanks [@esfomeado](https://github.com/esfomeado)! - Added support for disabling suffixes on Enums. + +### Patch Changes + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @graphql-codegen/plugin-helpers@5.0.0 + - @graphql-codegen/schema-ast@4.0.0 + - @graphql-codegen/visitor-plugin-common@4.0.0 + ## 3.0.4 ### Patch Changes diff --git a/packages/plugins/typescript/typescript/package.json b/packages/plugins/typescript/typescript/package.json index ce8c49681e4..1200d544f79 100644 --- a/packages/plugins/typescript/typescript/package.json +++ b/packages/plugins/typescript/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/typescript", - "version": "3.0.4", + "version": "4.0.0", "description": "GraphQL Code Generator plugin for generating TypeScript types", "repository": { "type": "git", @@ -13,9 +13,9 @@ "test": "jest --no-watchman --config ../../../../jest.config.js" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.2.0", - "@graphql-codegen/schema-ast": "^3.0.1", - "@graphql-codegen/visitor-plugin-common": "3.1.1", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/schema-ast": "^4.0.0", + "@graphql-codegen/visitor-plugin-common": "4.0.0", "auto-bind": "~4.0.0", "tslib": "~2.5.0" }, diff --git a/packages/presets/client/CHANGELOG.md b/packages/presets/client/CHANGELOG.md index 086fbd7e23f..8c797e3a1f8 100644 --- a/packages/presets/client/CHANGELOG.md +++ b/packages/presets/client/CHANGELOG.md @@ -1,5 +1,103 @@ # @graphql-codegen/client-preset +## 4.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Minor Changes + +- [#9196](https://github.com/dotansimha/graphql-code-generator/pull/9196) [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96) Thanks [@beerose](https://github.com/beerose)! - Add `@defer` directive support + + When 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. + + ```jsx + // 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. + + ```tsx + // gql/graphql.ts + export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({ + __typename?: 'Query'; + } & { + ' $fragmentRefs'?: { OrdersFragment: Incremental }; + }); + ``` + + Apart from generating code that includes support for the `@defer` directive, the Codegen also exports a utility function called `isFragmentReady`. You can use it to conditionally render components based on whether the data for a deferred + fragment is available: + + ```jsx + const OrdersList = (props: { data: FragmentType }) => { + const data = useFragment(OrdersFragment, props.data); + return ( + // render orders list + ) + }; + + function App() { + const { data } = useQuery(GetUserQuery); + return ( + {data && ( + <> + {isFragmentReady(GetUserQuery, OrdersFragment, data) + && } + + )} + ); + } + export default App; + ``` + +- [#9353](https://github.com/dotansimha/graphql-code-generator/pull/9353) [`d7e335b58`](https://github.com/dotansimha/graphql-code-generator/commit/d7e335b5874a821c9f609c66d554921ed8c6de19) Thanks [@charpeni](https://github.com/charpeni)! - Implement the ability the specify the hash algorithm used for persisted documents via `persistedDocuments.hashAlgorithm` + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + + - Updated dependency [`@graphql-tools/documents@^1.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/documents/v/1.0.0) (from `^0.1.0`, in `dependencies`) + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) + +- [#9315](https://github.com/dotansimha/graphql-code-generator/pull/9315) [`6d2de206a`](https://github.com/dotansimha/graphql-code-generator/commit/6d2de206abdcce9e176bbc157cd27b37a20b0f97) Thanks [@luvejo](https://github.com/luvejo)! - improve error message + +- [#9385](https://github.com/dotansimha/graphql-code-generator/pull/9385) [`a7dda3546`](https://github.com/dotansimha/graphql-code-generator/commit/a7dda3546567b5bb70015fc3ae197562231d7911) Thanks [@beerose](https://github.com/beerose)! - Improve isFragmentReady utility function to work with noUncheckedIndexedAccess TSC setting + +- [#9196](https://github.com/dotansimha/graphql-code-generator/pull/9196) [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96) Thanks [@beerose](https://github.com/beerose)! - Pass `emitLegacyCommonJSImports` and `isStringDocumentMode` to the client preset config + +- [#9414](https://github.com/dotansimha/graphql-code-generator/pull/9414) [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d) Thanks [@beerose](https://github.com/beerose)! - Include nested fragments in string documentMode + +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @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 + ## 3.0.1 ### Patch Changes diff --git a/packages/presets/client/package.json b/packages/presets/client/package.json index 375146d10cd..e0019bac45e 100644 --- a/packages/presets/client/package.json +++ b/packages/presets/client/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/client-preset", - "version": "3.0.1", + "version": "4.0.0", "description": "GraphQL Code Generator preset for client.", "repository": { "type": "git", @@ -19,13 +19,13 @@ "dependencies": { "@babel/helper-plugin-utils": "^7.20.2", "@babel/template": "^7.20.7", - "@graphql-codegen/add": "^4.0.1", - "@graphql-codegen/typed-document-node": "^4.0.1", - "@graphql-codegen/typescript": "^3.0.4", - "@graphql-codegen/typescript-operations": "^3.0.4", - "@graphql-codegen/gql-tag-operations": "3.0.1", - "@graphql-codegen/plugin-helpers": "^4.2.0", - "@graphql-codegen/visitor-plugin-common": "^3.1.1", + "@graphql-codegen/add": "^5.0.0", + "@graphql-codegen/typed-document-node": "^5.0.0", + "@graphql-codegen/typescript": "^4.0.0", + "@graphql-codegen/typescript-operations": "^4.0.0", + "@graphql-codegen/gql-tag-operations": "4.0.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/visitor-plugin-common": "^4.0.0", "@graphql-typed-document-node/core": "3.2.0", "@graphql-tools/documents": "^1.0.0", "@graphql-tools/utils": "^10.0.0", diff --git a/packages/presets/graphql-modules/CHANGELOG.md b/packages/presets/graphql-modules/CHANGELOG.md index ed25b962b5d..fd0d13f423c 100644 --- a/packages/presets/graphql-modules/CHANGELOG.md +++ b/packages/presets/graphql-modules/CHANGELOG.md @@ -1,5 +1,19 @@ # @graphql-codegen/graphql-modules-preset +## 4.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`3848a2b73`](https://github.com/dotansimha/graphql-code-generator/commit/3848a2b73339fe9f474b31647b71e75b9ca52a96), [`ba84a3a27`](https://github.com/dotansimha/graphql-code-generator/commit/ba84a3a2758d94dac27fcfbb1bafdf3ed7c32929), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`50471e651`](https://github.com/dotansimha/graphql-code-generator/commit/50471e6514557db827cd26157262401c6c600a8c), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c), [`ca02ad172`](https://github.com/dotansimha/graphql-code-generator/commit/ca02ad172a0e8f52570fdef4271ec286d883236d), [`e1dc75f3c`](https://github.com/dotansimha/graphql-code-generator/commit/e1dc75f3c598bf7f83138ca533619716fc73f823), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0), [`5950f5a68`](https://github.com/dotansimha/graphql-code-generator/commit/5950f5a6843cdd92b9d5b8ced3a97b68eadf9f30), [`5aa95aa96`](https://github.com/dotansimha/graphql-code-generator/commit/5aa95aa969993043ba5e9d5dabebd7127ea5e22c)]: + - @graphql-codegen/plugin-helpers@5.0.0 + - @graphql-codegen/visitor-plugin-common@4.0.0 + ## 3.1.3 ### Patch Changes diff --git a/packages/presets/graphql-modules/package.json b/packages/presets/graphql-modules/package.json index db1eadab1a6..7c761865468 100644 --- a/packages/presets/graphql-modules/package.json +++ b/packages/presets/graphql-modules/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/graphql-modules-preset", - "version": "3.1.3", + "version": "4.0.0", "description": "GraphQL Code Generator preset for modularized schema", "repository": { "type": "git", @@ -15,8 +15,8 @@ "@types/parse-filepath": "1.0.0" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.2.0", - "@graphql-codegen/visitor-plugin-common": "3.1.1", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/visitor-plugin-common": "4.0.0", "@graphql-tools/utils": "^10.0.0", "parse-filepath": "^1.0.2", "change-case-all": "1.0.15", diff --git a/packages/utils/graphql-codegen-testing/CHANGELOG.md b/packages/utils/graphql-codegen-testing/CHANGELOG.md index 72743493790..5f871cd2d0d 100644 --- a/packages/utils/graphql-codegen-testing/CHANGELOG.md +++ b/packages/utils/graphql-codegen-testing/CHANGELOG.md @@ -1,5 +1,18 @@ # @graphql-codegen/testing +## 3.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- [#9407](https://github.com/dotansimha/graphql-code-generator/pull/9407) [`bec804225`](https://github.com/dotansimha/graphql-code-generator/commit/bec8042256e1718e7867b9d5c038eb7d22e72774) Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates: + - Updated dependency [`nock@13.3.1` ↗︎](https://www.npmjs.com/package/nock/v/13.3.1) (from `13.3.0`, in `dependencies`) +- Updated dependencies [[`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2), [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2), [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4), [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0)]: + - @graphql-codegen/plugin-helpers@5.0.0 + ## 2.0.2 ### Patch Changes diff --git a/packages/utils/graphql-codegen-testing/package.json b/packages/utils/graphql-codegen-testing/package.json index 1b47238939f..54128f8be71 100644 --- a/packages/utils/graphql-codegen-testing/package.json +++ b/packages/utils/graphql-codegen-testing/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/testing", - "version": "2.0.2", + "version": "3.0.0", "description": "GraphQL Codegen Testing Utils", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", @@ -40,7 +40,7 @@ "typescript": ">=3.0.0" }, "dependencies": { - "@graphql-codegen/plugin-helpers": "^4.2.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", "common-tags": "^1.8.0", "lz-string": "^1.4.4", "graphql-helix": "1.13.0", diff --git a/packages/utils/plugins-helpers/CHANGELOG.md b/packages/utils/plugins-helpers/CHANGELOG.md index c457f898396..a527d2c9a1a 100644 --- a/packages/utils/plugins-helpers/CHANGELOG.md +++ b/packages/utils/plugins-helpers/CHANGELOG.md @@ -1,5 +1,21 @@ # @graphql-codegen/plugin-helpers +## 5.0.0 + +### Major Changes + +- [`bb66c2a31`](https://github.com/dotansimha/graphql-code-generator/commit/bb66c2a31985c1375912ccd6b2b02933f313c9c0) Thanks [@n1ru4l](https://github.com/n1ru4l)! - Require Node.js `>= 16`. Drop support for Node.js 14 + +### Patch Changes + +- [#9449](https://github.com/dotansimha/graphql-code-generator/pull/9449) [`4d9ea1a5a`](https://github.com/dotansimha/graphql-code-generator/commit/4d9ea1a5a94cd3458c1bd868ce1ab1cb806257f2) Thanks [@n1ru4l](https://github.com/n1ru4l)! - dependencies updates: + + - Updated dependency [`@graphql-tools/utils@^10.0.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.0.0) (from `^9.0.0`, in `dependencies`) + +- [#9332](https://github.com/dotansimha/graphql-code-generator/pull/9332) [`f46803a8c`](https://github.com/dotansimha/graphql-code-generator/commit/f46803a8c70840280529a52acbb111c865712af2) Thanks [@eddeee888](https://github.com/eddeee888)! - Update GitHub loader TypeScript type and usage docs + +- [#9360](https://github.com/dotansimha/graphql-code-generator/pull/9360) [`63827fabe`](https://github.com/dotansimha/graphql-code-generator/commit/63827fabede76b2380d40392aba2a3ccb099f0c4) Thanks [@beerose](https://github.com/beerose)! - Add handleAsSDL property to UrlSchemaOptions type + ## 4.2.0 ### Minor Changes diff --git a/packages/utils/plugins-helpers/package.json b/packages/utils/plugins-helpers/package.json index d11fb5df3fe..8632207dca1 100644 --- a/packages/utils/plugins-helpers/package.json +++ b/packages/utils/plugins-helpers/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/plugin-helpers", - "version": "4.2.0", + "version": "5.0.0", "description": "GraphQL Code Generator common utils and types", "repository": { "type": "git", diff --git a/website/package.json b/website/package.json index 8036b5f3e39..11e84024ff0 100644 --- a/website/package.json +++ b/website/package.json @@ -21,19 +21,19 @@ "prettier-plugin-tailwindcss": "0.2.8" }, "dependencies": { - "@graphql-codegen/add": "4.0.1", + "@graphql-codegen/add": "5.0.0", "@graphql-codegen/c-sharp": "4.3.1", "@graphql-codegen/c-sharp-operations": "2.3.1", - "@graphql-codegen/cli": "3.3.1", - "@graphql-codegen/core": "3.1.0", + "@graphql-codegen/cli": "4.0.0", + "@graphql-codegen/core": "4.0.0", "@graphql-codegen/flow": "2.3.6", "@graphql-codegen/flow-operations": "2.3.6", "@graphql-codegen/flow-resolvers": "2.4.4", "@graphql-codegen/flutter-freezed": "^3.0.1", - "@graphql-codegen/fragment-matcher": "4.0.1", + "@graphql-codegen/fragment-matcher": "5.0.0", "@graphql-codegen/hasura-allow-list": "2.0.0", "@graphql-codegen/import-types-preset": "2.2.6", - "@graphql-codegen/introspection": "3.0.1", + "@graphql-codegen/introspection": "4.0.0", "@graphql-codegen/java": "3.3.6", "@graphql-codegen/java-apollo-android": "2.3.6", "@graphql-codegen/java-resolvers": "2.3.6", @@ -41,10 +41,10 @@ "@graphql-codegen/kotlin": "2.3.6", "@graphql-codegen/named-operations-object": "2.3.1", "@graphql-codegen/near-operation-file-preset": "2.5.0", - "@graphql-codegen/schema-ast": "3.0.1", - "@graphql-codegen/time": "4.0.0", - "@graphql-codegen/typed-document-node": "4.0.1", - "@graphql-codegen/typescript": "3.0.4", + "@graphql-codegen/schema-ast": "4.0.0", + "@graphql-codegen/time": "5.0.0", + "@graphql-codegen/typed-document-node": "5.0.0", + "@graphql-codegen/typescript": "4.0.0", "@graphql-codegen/typescript-apollo-angular": "3.5.6", "@graphql-codegen/typescript-apollo-client-helpers": "2.2.6", "@graphql-codegen/typescript-generic-sdk": "3.1.0", @@ -52,10 +52,10 @@ "@graphql-codegen/typescript-graphql-request": "4.5.8", "@graphql-codegen/typescript-mongodb": "2.4.6", "@graphql-codegen/typescript-msw": "1.1.6", - "@graphql-codegen/typescript-operations": "3.0.4", + "@graphql-codegen/typescript-operations": "4.0.0", "@graphql-codegen/typescript-react-apollo": "3.3.7", "@graphql-codegen/typescript-react-query": "4.1.0", - "@graphql-codegen/typescript-resolvers": "3.2.1", + "@graphql-codegen/typescript-resolvers": "4.0.0", "@graphql-codegen/typescript-rtk-query": "2.4.1", "@graphql-codegen/typescript-stencil-apollo": "2.3.6", "@graphql-codegen/typescript-type-graphql": "2.3.6", @@ -65,7 +65,7 @@ "@graphql-codegen/typescript-vue-apollo-smart-ops": "2.3.6", "@graphql-codegen/typescript-vue-urql": "2.3.6", "@graphql-codegen/urql-introspection": "2.2.1", - "@graphql-codegen/client-preset": "3.0.1", + "@graphql-codegen/client-preset": "4.0.0", "@monaco-editor/react": "4.5.0", "@theguild/components": "4.5.12", "classnames": "2.3.2",