Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/programmatic-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"dependencies": {
"@graphql-codegen/core": "5.0.0",
"@graphql-codegen/plugin-helpers": "6.1.0",
"@graphql-codegen/typed-document-node": "6.1.5",
"@graphql-codegen/typescript": "5.0.7",
"@graphql-codegen/typescript-operations": "5.0.7",
"@graphql-codegen/typescript-resolvers": "5.1.5",
"@graphql-codegen/typed-document-node": "6.1.6",
"@graphql-codegen/typescript": "5.0.8",
"@graphql-codegen/typescript-operations": "5.0.8",
"@graphql-codegen/typescript-resolvers": "5.1.6",
"@graphql-tools/graphql-file-loader": "8.0.1",
"@graphql-tools/load": "8.1.0",
"@graphql-tools/schema": "10.0.6",
Expand Down
4 changes: 2 additions & 2 deletions examples/typescript-resolvers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"devDependencies": {
"@graphql-codegen/cli": "6.1.1",
"@graphql-codegen/typescript": "5.0.7",
"@graphql-codegen/typescript-resolvers": "5.1.5"
"@graphql-codegen/typescript": "5.0.8",
"@graphql-codegen/typescript-resolvers": "5.1.6"
},
"dependencies": {
"graphql": "16.9.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/plugins/other/visitor-plugin-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @graphql-codegen/visitor-plugin-common

## 6.2.3

### Patch Changes

- [#10580](https://github.com/dotansimha/graphql-code-generator/pull/10580) [`6038634`](https://github.com/dotansimha/graphql-code-generator/commit/60386344081917f2884db933309821603a2be2bf) Thanks [@Georgegriff](https://github.com/Georgegriff)! - fixed invalid extracted concrete type name on shared interface

## 6.2.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/other/visitor-plugin-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/visitor-plugin-common",
"version": "6.2.2",
"version": "6.2.3",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,17 +964,36 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD

const schemaType = this._schema.getType(typeName);

// Check if current selection set has fragments (e.g., "... AppNotificationFragment" or "... on AppNotification")
const hasFragment =
this._selectionSet?.selections?.some(
selection => selection.kind === Kind.INLINE_FRAGMENT || selection.kind === Kind.FRAGMENT_SPREAD
) ?? false;
// Check if current selection set has type-narrowing fragments.
// - Inline fragments are always type-narrowing
// - Fragment spreads are only type-narrowing if they are on a different type than the current parent schema type
// (e.g. spreading `fragment Foo on Pet` while processing `Pet` is not type-narrowing).
const hasTypeNarrowingFragments =
this._selectionSet?.selections?.some(selection => {
if (selection.kind === Kind.INLINE_FRAGMENT) {
return true;
}

if (selection.kind === Kind.FRAGMENT_SPREAD) {
const spreadFragment = this._loadedFragments.find(lf => lf.name === selection.name.value);
// If we can't resolve fragment metadata (or the current parent type), treat it as type-narrowing.
// This avoids incorrectly using interface-rooted names in cases that are actually concrete-targeting.
return !spreadFragment || !this._parentSchemaType || spreadFragment.onType !== this._parentSchemaType.name;
}

return false;
}) ?? false;

// When the parent schema type is an interface:
// - If we're processing inline fragments, use the concrete type name
// - If we're processing the interface directly, use the interface name
// - If we're in a named fragment, always use the concrete type name
if (isObjectType(schemaType) && this._parentSchemaType && isInterfaceType(this._parentSchemaType) && !hasFragment) {
if (
isObjectType(schemaType) &&
this._parentSchemaType &&
isInterfaceType(this._parentSchemaType) &&
!hasTypeNarrowingFragments
) {
return `${parentName}_${this._parentSchemaType.name}`;
}

Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/typescript/document-nodes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @graphql-codegen/typescript-document-nodes

## 5.0.8

### Patch Changes

- Updated dependencies [[`6038634`](https://github.com/dotansimha/graphql-code-generator/commit/60386344081917f2884db933309821603a2be2bf)]:
- @graphql-codegen/[email protected]

## 5.0.7

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/typescript/document-nodes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/typescript-document-nodes",
"version": "5.0.7",
"version": "5.0.8",
"description": "GraphQL Code Generator plugin for generating TypeScript modules with embedded GraphQL document nodes",
"repository": {
"type": "git",
Expand All @@ -14,7 +14,7 @@
},
"dependencies": {
"@graphql-codegen/plugin-helpers": "^6.1.0",
"@graphql-codegen/visitor-plugin-common": "6.2.2",
"@graphql-codegen/visitor-plugin-common": "6.2.3",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/typescript/gql-tag-operations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @graphql-codegen/gql-tag-operations

## 5.1.3

### Patch Changes

- Updated dependencies [[`6038634`](https://github.com/dotansimha/graphql-code-generator/commit/60386344081917f2884db933309821603a2be2bf)]:
- @graphql-codegen/[email protected]

## 5.1.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/typescript/gql-tag-operations/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/gql-tag-operations",
"version": "5.1.2",
"version": "5.1.3",
"description": "GraphQL Code Generator plugin for generating a typed gql tag function",
"repository": {
"type": "git",
Expand All @@ -18,7 +18,7 @@
"dependencies": {
"@graphql-tools/utils": "^10.0.0",
"@graphql-codegen/plugin-helpers": "^6.1.0",
"@graphql-codegen/visitor-plugin-common": "6.2.2",
"@graphql-codegen/visitor-plugin-common": "6.2.3",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/plugins/typescript/operations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @graphql-codegen/typescript-operations

## 5.0.8

### Patch Changes

- [#10580](https://github.com/dotansimha/graphql-code-generator/pull/10580) [`6038634`](https://github.com/dotansimha/graphql-code-generator/commit/60386344081917f2884db933309821603a2be2bf) Thanks [@Georgegriff](https://github.com/Georgegriff)! - fixed invalid extracted concrete type name on shared interface

- Updated dependencies [[`6038634`](https://github.com/dotansimha/graphql-code-generator/commit/60386344081917f2884db933309821603a2be2bf)]:
- @graphql-codegen/[email protected]
- @graphql-codegen/[email protected]

## 5.0.7

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/typescript/operations/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/typescript-operations",
"version": "5.0.7",
"version": "5.0.8",
"description": "GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments",
"repository": {
"type": "git",
Expand All @@ -14,8 +14,8 @@
},
"dependencies": {
"@graphql-codegen/plugin-helpers": "^6.1.0",
"@graphql-codegen/typescript": "^5.0.7",
"@graphql-codegen/visitor-plugin-common": "6.2.2",
"@graphql-codegen/typescript": "^5.0.8",
"@graphql-codegen/visitor-plugin-common": "6.2.3",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Expand Down
107 changes: 107 additions & 0 deletions packages/plugins/typescript/operations/tests/extract-all-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,113 @@ describe('extractAllFieldsToTypes: true', () => {
await validate(content, config, nestedInterfacesSchema);
});

it('fragment spreads on the same interface should not force concrete parent type names (regression #10502)', async () => {
const interfaceFragmentSchema = buildSchema(/* GraphQL */ `
schema {
query: Query
}

type Query {
pet(petId: ID!): Pet
}

interface Pet {
id: ID!
home: Home
}

type Dog implements Pet {
id: ID!
home: Home
}

type Cat implements Pet {
id: ID!
home: Home
}

interface Home {
id: ID!
}

type House implements Home {
id: ID!
}
`);

const interfaceFragmentDoc = parse(/* GraphQL */ `
fragment GetFragmentPet on Pet {
id
home {
id
}
}

query GetPetData($petId: ID!) {
pet(petId: $petId) {
id
home {
id
}
...GetFragmentPet
}
}
`);

const config: TypeScriptDocumentsPluginConfig = {
preResolveTypes: true,
extractAllFieldsToTypes: true,
nonOptionalTypename: true,
dedupeOperationSuffix: true,
};

const { content } = await plugin(
interfaceFragmentSchema,
[{ location: 'test-file.ts', document: interfaceFragmentDoc }],
config,
{ outputFile: '' }
);

// Edge case: a fragment spread on the same interface should not cause extracted types
// for interface fields to be rooted to the first concrete parent (e.g. Cat).
expect(content).toMatchInlineSnapshot(`
"export type GetFragmentPetFragment_Pet_home_House = { __typename: 'House', id: string };

type GetFragmentPet_Dog_Fragment = { __typename: 'Dog', id: string, home?: GetFragmentPetFragment_Pet_home_House | null };

type GetFragmentPet_Cat_Fragment = { __typename: 'Cat', id: string, home?: GetFragmentPetFragment_Pet_home_House | null };

export type GetFragmentPetFragment =
| GetFragmentPet_Dog_Fragment
| GetFragmentPet_Cat_Fragment
;

export type GetPetDataQuery_pet_Pet_home_House = { __typename: 'House', id: string };

export type GetPetDataQuery_pet_Dog = { __typename: 'Dog', id: string, home?: GetPetDataQuery_pet_Pet_home_House | null };

export type GetPetDataQuery_pet_Cat = { __typename: 'Cat', id: string, home?: GetPetDataQuery_pet_Pet_home_House | null };

export type GetPetDataQuery_pet =
| GetPetDataQuery_pet_Dog
| GetPetDataQuery_pet_Cat
;

export type GetPetDataQuery_Query = { __typename: 'Query', pet?: GetPetDataQuery_pet | null };


export type GetPetDataQueryVariables = Exact<{
petId: Scalars['ID']['input'];
}>;


export type GetPetDataQuery = GetPetDataQuery_Query;
"
`);

await validate(content, config, interfaceFragmentSchema);
});

// Exception case for Issue #10502 - shared schema for fragment tests
const notificationSchema = buildSchema(/* GraphQL */ `
type Query {
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/typescript/resolvers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @graphql-codegen/typescript-resolvers

## 5.1.6

### Patch Changes

- Updated dependencies [[`6038634`](https://github.com/dotansimha/graphql-code-generator/commit/60386344081917f2884db933309821603a2be2bf)]:
- @graphql-codegen/[email protected]
- @graphql-codegen/[email protected]

## 5.1.5

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/typescript/resolvers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/typescript-resolvers",
"version": "5.1.5",
"version": "5.1.6",
"description": "GraphQL Code Generator plugin for generating TypeScript types for resolvers signature",
"repository": {
"type": "git",
Expand All @@ -14,8 +14,8 @@
},
"dependencies": {
"@graphql-codegen/plugin-helpers": "^6.1.0",
"@graphql-codegen/typescript": "^5.0.7",
"@graphql-codegen/visitor-plugin-common": "6.2.2",
"@graphql-codegen/typescript": "^5.0.8",
"@graphql-codegen/visitor-plugin-common": "6.2.3",
"@graphql-tools/utils": "^10.0.0",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/typescript/typed-document-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @graphql-codegen/typed-document-node

## 6.1.6

### Patch Changes

- Updated dependencies [[`6038634`](https://github.com/dotansimha/graphql-code-generator/commit/60386344081917f2884db933309821603a2be2bf)]:
- @graphql-codegen/[email protected]

## 6.1.5

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/typescript/typed-document-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/typed-document-node",
"version": "6.1.5",
"version": "6.1.6",
"description": "GraphQL Code Generator plugin for generating ready-to-use TypedDocumentNode based on GraphQL operations",
"repository": {
"type": "git",
Expand All @@ -18,7 +18,7 @@
"dependencies": {
"change-case-all": "1.0.15",
"@graphql-codegen/plugin-helpers": "^6.1.0",
"@graphql-codegen/visitor-plugin-common": "6.2.2",
"@graphql-codegen/visitor-plugin-common": "6.2.3",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/typescript/typescript/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @graphql-codegen/typescript

## 5.0.8

### Patch Changes

- Updated dependencies [[`6038634`](https://github.com/dotansimha/graphql-code-generator/commit/60386344081917f2884db933309821603a2be2bf)]:
- @graphql-codegen/[email protected]

## 5.0.7

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/typescript/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/typescript",
"version": "5.0.7",
"version": "5.0.8",
"description": "GraphQL Code Generator plugin for generating TypeScript types",
"repository": {
"type": "git",
Expand All @@ -15,7 +15,7 @@
"dependencies": {
"@graphql-codegen/plugin-helpers": "^6.1.0",
"@graphql-codegen/schema-ast": "^5.0.0",
"@graphql-codegen/visitor-plugin-common": "6.2.2",
"@graphql-codegen/visitor-plugin-common": "6.2.3",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Expand Down
Loading
Loading