Skip to content
Open
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
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.avoidOptionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export type StarshipLengthArgs = {
unit?: InputMaybe<LengthUnit>;
};

/** The input object sent when passing a color */
export type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
export type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -249,6 +256,16 @@ export type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
export type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

export type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.excludeQueryAlpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export type StarshipLengthArgs = {
unit?: InputMaybe<LengthUnit>;
};

/** The input object sent when passing a color */
export type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
export type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -249,6 +256,16 @@ export type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
export type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

export type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.excludeQueryBeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export type StarshipLengthArgs = {
unit?: InputMaybe<LengthUnit>;
};

/** The input object sent when passing a color */
export type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
export type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -249,6 +256,16 @@ export type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
export type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

export type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.globallyAvailable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ type StarshipLengthArgs = {
unit?: InputMaybe<LengthUnit>;
};

/** The input object sent when passing a color */
type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -247,6 +254,16 @@ type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.immutableTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export type StarshipLengthArgs = {
unit?: InputMaybe<LengthUnit>;
};

/** The input object sent when passing a color */
export type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
export type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -249,6 +256,16 @@ export type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
export type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

export type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export type ReviewInput = {
stars: Scalars['Int']['input'];
};

/** The input object sent when passing a color */
export type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
export type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -58,6 +65,16 @@ export type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
export type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

export type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.preResolveTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export type StarshipLengthArgs = {
unit?: InputMaybe<LengthUnit>;
};

/** The input object sent when passing a color */
export type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
export type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -249,6 +256,16 @@ export type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
export type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

export type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.skipSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export type StarshipLengthArgs = {
unit?: InputMaybe<LengthUnit>;
};

/** The input object sent when passing a color */
export type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
export type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -249,6 +256,16 @@ export type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
export type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

export type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
17 changes: 17 additions & 0 deletions dev-test/star-wars/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export type StarshipLengthArgs = {
unit?: InputMaybe<LengthUnit>;
};

/** The input object sent when passing a color */
export type ColorInput = {
blue: number;
green: number;
red: number;
};

/** The episodes in the Star Wars trilogy */
export type Episode =
/** Star Wars Episode V: The Empire Strikes Back, released in 1980. */
Expand All @@ -249,6 +256,16 @@ export type Episode =
/** Star Wars Episode IV: A New Hope, released in 1977. */
| 'NEWHOPE';

/** The input object sent when someone is creating a new review */
export type ReviewInput = {
/** Comment about the movie, optional */
commentary: string;
/** Favorite color, optional */
favoriteColor: ColorInput;
/** 0-5 stars */
stars: number;
};

export type CreateReviewForEpisodeMutationVariables = Exact<{
episode: Episode;
review: ReviewInput;
Expand Down
30 changes: 11 additions & 19 deletions packages/plugins/typescript/operations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,14 @@ export const plugin: PluginFunction<TypeScriptDocumentsPluginConfig, Types.Compl

const operationsResult = oldVisit(allAst, { leave: visitor });

let operationsContent = operationsResult.definitions.join('\n');
const operationsDefinitions = operationsResult.definitions;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rearranged/simplified the code here - please check.


if (config.addOperationExport) {
const exportConsts = [];

for (const d of allAst.definitions) {
if ('name' in d) {
exportConsts.push(`export declare const ${d.name.value}: import("graphql").DocumentNode;`);
operationsDefinitions.push(`export declare const ${d.name.value}: import("graphql").DocumentNode;`);
}
}

operationsContent = operationsResult.definitions.concat(exportConsts).join('\n');
}

if (config.globalNamespace) {
Copy link
Author

@ikusakov2 ikusakov2 Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this block to the end - to include all the generated code.

operationsContent = `
declare global {
${operationsContent}
}`;
}

const schemaTypes = oldVisit(transformSchemaAST(schema, config).ast, { leave: visitor });
Expand All @@ -52,13 +41,16 @@ export const plugin: PluginFunction<TypeScriptDocumentsPluginConfig, Types.Compl
// It will leave the node as an object.
// Here, we filter in nodes that have been turned into strings, i.e. they have been transformed
// This way, we do not have to explicitly declare a method for every node type to convert them to null
const schemaTypesContent = schemaTypes.definitions.filter(def => typeof def === 'string').join('\n');
const schemaTypesDefinitions = schemaTypes.definitions.filter(def => typeof def === 'string');

let content = [...schemaTypesDefinitions, ...operationsDefinitions].join('\n');

const content: string[] = [];
if (schemaTypesContent) {
content.push(schemaTypesContent);
if (config.globalNamespace) {
content = `
declare global {
${content}
}`;
}
content.push(operationsContent);

return {
prepend: [
Expand All @@ -67,7 +59,7 @@ export const plugin: PluginFunction<TypeScriptDocumentsPluginConfig, Types.Compl
...visitor.getGlobalDeclarations(visitor.config.noExport),
visitor.getExactUtilityType(),
],
content: content.join('\n'),
content,
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TypeScriptOperationVariablesToObject as TSOperationVariablesToObject } from '@graphql-codegen/typescript';

const SCALARS = {
export const SCALARS = {
ID: 'string | number',
String: 'string',
Int: 'number',
Expand Down
Loading