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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-codegen/typescript-operations": patch
---
dependencies updates:
- Added dependency [`@graphql-codegen/schema-ast@^5.0.0` ↗︎](https://www.npmjs.com/package/@graphql-codegen/schema-ast/v/5.0.0) (to `dependencies`)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as Types from './_base.generated';
import type * as Types from './_base.generated.js';

type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/typescript/operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@graphql-codegen/plugin-helpers": "^6.1.0",
"@graphql-codegen/schema-ast": "^5.0.0",
"@graphql-codegen/typescript": "^5.0.7",
"@graphql-codegen/visitor-plugin-common": "6.2.2",
"auto-bind": "~4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/typescript/operations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const plugin: PluginFunction<TypeScriptDocumentsPluginConfig, Types.Compl
};
};

export { TypeScriptDocumentsVisitor };
export { TypeScriptDocumentsVisitor, type TypeScriptDocumentsPluginConfig };

const semanticToStrict = async (schema: GraphQLSchema): Promise<GraphQLSchema> => {
try {
Expand Down
8 changes: 6 additions & 2 deletions packages/plugins/typescript/operations/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getNodeComment,
wrapTypeWithModifiers,
} from '@graphql-codegen/visitor-plugin-common';
import { normalizeImportExtension } from '@graphql-codegen/plugin-helpers';
import autoBind from 'auto-bind';
import {
type DocumentNode,
Expand Down Expand Up @@ -370,8 +371,11 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
identifiers: [],
},
typesImport: true,
// FIXME: rebase with master for the new extension
emitLegacyCommonJSImports: true,
emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
importExtension: normalizeImportExtension({
emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
importExtension: this.config.importExtension,
}),
}),
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { mergeOutputs, Types } from '@graphql-codegen/plugin-helpers';
import { validateTs } from '@graphql-codegen/testing';
import { buildSchema, parse } from 'graphql';
import { plugin as tsPlugin } from '../../typescript/src/index.js';
import { plugin, TypeScriptDocumentsPluginConfig } from '../src/index.js';
import { plugin, type TypeScriptDocumentsPluginConfig } from '../src/index.js';

describe('extractAllFieldsToTypes: true', () => {
const validate = async (content: Types.PluginOutput, config: any = {}, pluginSchema) => {
const m = mergeOutputs([await tsPlugin(pluginSchema, [], config, { outputFile: '' }), content]);
const validate = async (content: Types.PluginOutput) => {
const m = mergeOutputs([content]);
validateTs(m, undefined, undefined, undefined, []);

return m;
Expand Down Expand Up @@ -197,7 +196,7 @@ describe('extractAllFieldsToTypes: true', () => {
"
`);

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

const complexTestSchemaWithUnionsAndInterfaces = buildSchema(/* GraphQL */ `
Expand Down Expand Up @@ -551,7 +550,7 @@ describe('extractAllFieldsToTypes: true', () => {
"
`);

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

it('should extract types from multiple fragments (mergeFragmentTypes: true)', async () => {
Expand Down Expand Up @@ -725,7 +724,7 @@ describe('extractAllFieldsToTypes: true', () => {
"
`);

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

it("should extract types from multiple fragments (inlineFragmentTypes: 'combine')", async () => {
Expand Down Expand Up @@ -968,7 +967,7 @@ describe('extractAllFieldsToTypes: true', () => {
"
`);

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

it("should extract types from multiple fragments (inlineFragmentTypes: 'mask')", async () => {
Expand Down Expand Up @@ -1209,7 +1208,7 @@ describe('extractAllFieldsToTypes: true', () => {
"
`);

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

it('fields with shared types and no fragments should use the shared type interface name', async () => {
Expand Down Expand Up @@ -1302,7 +1301,7 @@ describe('extractAllFieldsToTypes: true', () => {
"
`);

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

// Exception case for Issue #10502 - shared schema for fragment tests
Expand Down Expand Up @@ -1411,7 +1410,7 @@ describe('extractAllFieldsToTypes: true', () => {
export type GetNotificationsQuery = GetNotificationsQuery_Query;
"
`);
await validate(content, config, notificationSchema);
await validate(content);
});

it('named fragments should use their name and not parent type name', async () => {
Expand Down Expand Up @@ -1492,6 +1491,6 @@ describe('extractAllFieldsToTypes: true', () => {
export type GetNotificationsQuery = GetNotificationsQuery_Query;
"
`);
await validate(content, config, notificationSchema);
await validate(content);
});
});