Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/plugins/typescript/operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"tslib": "^2.8.0"
},
"devDependencies": {
"@graphql-codegen/near-operation-file-preset": "5.2.2",
"graphql-sock": "1.0.1"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

//@ts-ignore
export const MarkdownFragment = gql(/* GraphQL */ `
fragment MarkdownFragment on Markdown {
markdown
}
`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

//@ts-ignore
export const WidgetFragment = gql(/* GraphQL */ `
fragment WidgetFragment on Widget {
title {
...MarkdownFragment
}
}
`);

//@ts-ignore
export const PingQuery = gql(/* GraphQL */ `
query Ping {
ping {
...WidgetFragment
}
}
`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import path from 'path';
import { executeCodegen } from '@graphql-codegen/cli';
import * as nearOperationFilePreset from '@graphql-codegen/near-operation-file-preset';
import * as typescriptOperationsPlugin from '../src/index.js';

const fixturesDir = path.join(__dirname, 'fixtures/issue-11026');

const runCodegen = (omitOperationSuffix: boolean) =>
executeCodegen({
cwd: fixturesDir,
schema: /* GraphQL */ `
type Query {
ping: Widget
}

type Widget {
title: Markdown
}

type Markdown {
markdown: String
}
`,
documents: ['markdown.ts', 'op.ts'],
pluginLoader: async name => {
if (name === '@graphql-codegen/typescript-operations') {
return typescriptOperationsPlugin;
}
return import(name);
},
generates: {
'./': {
preset: nearOperationFilePreset,
presetConfig: {
extension: '.generated.ts',
baseTypesPath: 'globalTypes.ts',
},
plugins: ['typescript-operations'],
config: {
omitOperationSuffix,
inlineFragmentTypes: 'combine',
},
},
},
});

describe('TypeScript Operations Plugin - near-operation-file preset', () => {
it('Issue #11026 - imports fragment used by another fragment in the same file when omitOperationSuffix=true', async () => {
const { result } = await runCodegen(true);

const opFile = result.find(file => file.filename.endsWith('op.generated.ts'));
expect(opFile.content).toContain(
`export type WidgetFragment = { title: MarkdownFragment | null };`,
);
expect(opFile.content).toMatch(

Check failure on line 55 in packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Test on Node 24 (ubuntu-latest) and GraphQL v15

[typescript-operations] tests/ts-documents.near-operation-file.spec.ts > TypeScript Operations Plugin - near-operation-file preset > Issue #11026 - imports fragment used by another fragment in the same file when omitOperationSuffix=true

AssertionError: expected '/** Internal type. DO NOT USE DIRECTL…' to match /import (type )?\…/markdown\.generated'; - Expected: /import (type )?\{ MarkdownFragment \} from '\.\/markdown\.generated';/ + Received: "/** Internal type. DO NOT USE DIRECTLY. */ type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; /** Internal type. DO NOT USE DIRECTLY. */ export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; import * as Types from '../../../../../../../globalTypes'; export type WidgetFragment = { title: MarkdownFragment | null }; export type PingVariables = Exact<{ [key: string]: never; }>; export type Ping = { ping: WidgetFragment | null }; " ❯ tests/ts-documents.near-operation-file.spec.ts:55:28

Check failure on line 55 in packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Test on Node 22 (ubuntu-latest) and GraphQL v17

[typescript-operations] tests/ts-documents.near-operation-file.spec.ts > TypeScript Operations Plugin - near-operation-file preset > Issue #11026 - imports fragment used by another fragment in the same file when omitOperationSuffix=true

AssertionError: expected '/** Internal type. DO NOT USE DIRECTL…' to match /import (type )?\…/markdown\.generated'; - Expected: /import (type )?\{ MarkdownFragment \} from '\.\/markdown\.generated';/ + Received: "/** Internal type. DO NOT USE DIRECTLY. */ type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; /** Internal type. DO NOT USE DIRECTLY. */ export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; import * as Types from '../../../../../../../globalTypes'; export type WidgetFragment = { title: MarkdownFragment | null }; export type PingVariables = Exact<{ [key: string]: never; }>; export type Ping = { ping: WidgetFragment | null }; " ❯ tests/ts-documents.near-operation-file.spec.ts:55:28

Check failure on line 55 in packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Test on Node 22 (ubuntu-latest) and GraphQL v16

[typescript-operations] tests/ts-documents.near-operation-file.spec.ts > TypeScript Operations Plugin - near-operation-file preset > Issue #11026 - imports fragment used by another fragment in the same file when omitOperationSuffix=true

AssertionError: expected '/** Internal type. DO NOT USE DIRECTL…' to match /import (type )?\…/markdown\.generated'; - Expected: /import (type )?\{ MarkdownFragment \} from '\.\/markdown\.generated';/ + Received: "/** Internal type. DO NOT USE DIRECTLY. */ type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; /** Internal type. DO NOT USE DIRECTLY. */ export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; import * as Types from '../../../../../../../globalTypes'; export type WidgetFragment = { title: MarkdownFragment | null }; export type PingVariables = Exact<{ [key: string]: never; }>; export type Ping = { ping: WidgetFragment | null }; " ❯ tests/ts-documents.near-operation-file.spec.ts:55:28

Check failure on line 55 in packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Test on Node 24 (ubuntu-latest) and GraphQL v16

[typescript-operations] tests/ts-documents.near-operation-file.spec.ts > TypeScript Operations Plugin - near-operation-file preset > Issue #11026 - imports fragment used by another fragment in the same file when omitOperationSuffix=true

AssertionError: expected '/** Internal type. DO NOT USE DIRECTL…' to match /import (type )?\…/markdown\.generated'; - Expected: /import (type )?\{ MarkdownFragment \} from '\.\/markdown\.generated';/ + Received: "/** Internal type. DO NOT USE DIRECTLY. */ type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; /** Internal type. DO NOT USE DIRECTLY. */ export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; import * as Types from '../../../../../../../globalTypes'; export type WidgetFragment = { title: MarkdownFragment | null }; export type PingVariables = Exact<{ [key: string]: never; }>; export type Ping = { ping: WidgetFragment | null }; " ❯ tests/ts-documents.near-operation-file.spec.ts:55:28

Check failure on line 55 in packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Test on Node 22 (ubuntu-latest) and GraphQL v15

[typescript-operations] tests/ts-documents.near-operation-file.spec.ts > TypeScript Operations Plugin - near-operation-file preset > Issue #11026 - imports fragment used by another fragment in the same file when omitOperationSuffix=true

AssertionError: expected '/** Internal type. DO NOT USE DIRECTL…' to match /import (type )?\…/markdown\.generated'; - Expected: /import (type )?\{ MarkdownFragment \} from '\.\/markdown\.generated';/ + Received: "/** Internal type. DO NOT USE DIRECTLY. */ type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; /** Internal type. DO NOT USE DIRECTLY. */ export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; import * as Types from '../../../../../../../globalTypes'; export type WidgetFragment = { title: MarkdownFragment | null }; export type PingVariables = Exact<{ [key: string]: never; }>; export type Ping = { ping: WidgetFragment | null }; " ❯ tests/ts-documents.near-operation-file.spec.ts:55:28

Check failure on line 55 in packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Test on Node 24 (ubuntu-latest) and GraphQL v17

[typescript-operations] tests/ts-documents.near-operation-file.spec.ts > TypeScript Operations Plugin - near-operation-file preset > Issue #11026 - imports fragment used by another fragment in the same file when omitOperationSuffix=true

AssertionError: expected '/** Internal type. DO NOT USE DIRECTL…' to match /import (type )?\…/markdown\.generated'; - Expected: /import (type )?\{ MarkdownFragment \} from '\.\/markdown\.generated';/ + Received: "/** Internal type. DO NOT USE DIRECTLY. */ type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; /** Internal type. DO NOT USE DIRECTLY. */ export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; import * as Types from '../../../../../../../globalTypes'; export type WidgetFragment = { title: MarkdownFragment | null }; export type PingVariables = Exact<{ [key: string]: never; }>; export type Ping = { ping: WidgetFragment | null }; " ❯ tests/ts-documents.near-operation-file.spec.ts:55:28
/import (type )?\{ MarkdownFragment \} from '\.\/markdown\.generated';/,
);
});

it('control: imports fragment used by another fragment in the same file when omitOperationSuffix=false', async () => {
const { result } = await runCodegen(false);

const opFile = result.find(file => file.filename.endsWith('op.generated.ts'));
expect(opFile.content).toMatch(
/import (type )?\{ MarkdownFragmentFragment \} from '\.\/markdown\.generated';/,
);
});
});
Loading
Loading