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.3",
"@graphql-codegen/typescript": "5.0.5",
"@graphql-codegen/typescript-operations": "5.0.5",
"@graphql-codegen/typescript-resolvers": "5.1.3",
"@graphql-codegen/typed-document-node": "6.1.4",
"@graphql-codegen/typescript": "5.0.6",
"@graphql-codegen/typescript-operations": "5.0.6",
"@graphql-codegen/typescript-resolvers": "5.1.4",
"@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.0",
"@graphql-codegen/typescript": "5.0.5",
"@graphql-codegen/typescript-resolvers": "5.1.3"
"@graphql-codegen/typescript": "5.0.6",
"@graphql-codegen/typescript-resolvers": "5.1.4"
},
"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.1

### Patch Changes

- [#10503](https://github.com/dotansimha/graphql-code-generator/pull/10503) [`b995ed1`](https://github.com/dotansimha/graphql-code-generator/commit/b995ed13a49379ea05e0e313fac68b557527523a) Thanks [@Georgegriff](https://github.com/Georgegriff)! - Use parent type name on interface types without fragments

## 6.2.0

### Minor 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.0",
"version": "6.2.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,24 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
protected buildParentFieldName(typeName: string, parentName: string): string {
// queries/mutations/fragments are guaranteed to be unique type names,
// so we can skip affixing the field names with typeName
return operationTypes.includes(typeName) ? parentName : `${parentName}_${typeName}`;
if (operationTypes.includes(typeName)) {
return parentName;
}

// When the parent schema type is an interface, use the interface name instead of the concrete type
// BUT only if we're not inside a fragment (fragments explicitly target specific types)
const schemaType = this._schema.getType(typeName);
const isInFragment = parentName.includes('Fragment');
if (
isObjectType(schemaType) &&
this._parentSchemaType &&
isInterfaceType(this._parentSchemaType) &&
!isInFragment
) {
return `${parentName}_${this._parentSchemaType.name}`;
}

return `${parentName}_${typeName}`;
}
}

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.6

### Patch Changes

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

## 5.0.5

### 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.5",
"version": "5.0.6",
"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.0",
"@graphql-codegen/visitor-plugin-common": "6.2.1",
"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.1

### Patch Changes

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

## 5.1.0

### Minor 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.0",
"version": "5.1.1",
"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.0",
"@graphql-codegen/visitor-plugin-common": "6.2.1",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/typescript/operations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @graphql-codegen/typescript-operations

## 5.0.6

### Patch Changes

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

## 5.0.5

### 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.5",
"version": "5.0.6",
"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.5",
"@graphql-codegen/visitor-plugin-common": "6.2.0",
"@graphql-codegen/typescript": "^5.0.6",
"@graphql-codegen/visitor-plugin-common": "6.2.1",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,4 +1462,97 @@ describe('extractAllFieldsToTypes: true', () => {

await validate(content, config, complexTestSchemaWithUnionsAndInterfaces);
});
it('should handle interfaces without fragments', async () => {
const nestedInterfacesSchema = buildSchema(/* GraphQL */ `
type Query {
animals: [Animal!]
}

interface Animal {
name: String!
owner: Person!
}

type Cat implements Animal {
name: String!
owner: Person!
}

type Dog implements Animal {
name: String!
owner: Person!
}

interface Person {
name: String!
}

type Trainer implements Person {
name: String!
}

type Veterinarian implements Person {
name: String!
}
`);

const nestedInterfacesQuery = parse(/* GraphQL */ `
query GetAnimals {
animals {
name
owner {
name
}
}
}
`);

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

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

// Issue #10502: When nested interfaces have the same fields, extractAllFieldsToTypes
// We need to use the interface name for the nested type name.

expect(content).toMatchInlineSnapshot(`
"export type GetAnimalsQuery_animals_Animal_owner_Trainer = { __typename: 'Trainer', name: string };

export type GetAnimalsQuery_animals_Animal_owner_Veterinarian = { __typename: 'Veterinarian', name: string };

export type GetAnimalsQuery_animals_Animal_owner =
| GetAnimalsQuery_animals_Animal_owner_Trainer
| GetAnimalsQuery_animals_Animal_owner_Veterinarian
;

export type GetAnimalsQuery_animals_Cat = { __typename: 'Cat', name: string, owner: GetAnimalsQuery_animals_Animal_owner };

export type GetAnimalsQuery_animals_Dog = { __typename: 'Dog', name: string, owner: GetAnimalsQuery_animals_Animal_owner };

export type GetAnimalsQuery_animals =
| GetAnimalsQuery_animals_Cat
| GetAnimalsQuery_animals_Dog
;

export type GetAnimalsQuery_Query = { __typename: 'Query', animals?: Array<GetAnimalsQuery_animals> | null };


export type GetAnimalsQueryVariables = Exact<{ [key: string]: never; }>;


export type GetAnimalsQuery = GetAnimalsQuery_Query;
"
`);

await validate(content, config, nestedInterfacesSchema);
});
});
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.4

### Patch Changes

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

## 5.1.3

### 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.3",
"version": "5.1.4",
"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.5",
"@graphql-codegen/visitor-plugin-common": "6.2.0",
"@graphql-codegen/typescript": "^5.0.6",
"@graphql-codegen/visitor-plugin-common": "6.2.1",
"@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.4

### Patch Changes

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

## 6.1.3

### 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.3",
"version": "6.1.4",
"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.0",
"@graphql-codegen/visitor-plugin-common": "6.2.1",
"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.6

### Patch Changes

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

## 5.0.5

### 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.5",
"version": "5.0.6",
"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.0",
"@graphql-codegen/visitor-plugin-common": "6.2.1",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/presets/client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @graphql-codegen/client-preset

## 5.2.1

### Patch Changes

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

## 5.2.0

### Minor Changes
Expand Down
12 changes: 6 additions & 6 deletions packages/presets/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/client-preset",
"version": "5.2.0",
"version": "5.2.1",
"description": "GraphQL Code Generator preset for client.",
"repository": {
"type": "git",
Expand All @@ -21,12 +21,12 @@
"@babel/helper-plugin-utils": "^7.20.2",
"@babel/template": "^7.20.7",
"@graphql-codegen/add": "^6.0.0",
"@graphql-codegen/typed-document-node": "^6.1.3",
"@graphql-codegen/typescript": "^5.0.5",
"@graphql-codegen/typescript-operations": "^5.0.5",
"@graphql-codegen/gql-tag-operations": "5.1.0",
"@graphql-codegen/typed-document-node": "^6.1.4",
"@graphql-codegen/typescript": "^5.0.6",
"@graphql-codegen/typescript-operations": "^5.0.6",
"@graphql-codegen/gql-tag-operations": "5.1.1",
"@graphql-codegen/plugin-helpers": "^6.1.0",
"@graphql-codegen/visitor-plugin-common": "^6.2.0",
"@graphql-codegen/visitor-plugin-common": "^6.2.1",
"@graphql-typed-document-node/core": "3.2.0",
"@graphql-tools/documents": "^1.0.0",
"@graphql-tools/utils": "^10.0.0",
Expand Down
Loading
Loading