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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.avoidOptionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.excludeQueryAlpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.excludeQueryBeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.globallyAvailable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.immutableTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.preResolveTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.skipSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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
10 changes: 10 additions & 0 deletions dev-test/star-wars/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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,21 +41,24 @@ 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: [
...visitor.getImports(),
...visitor.getGlobalDeclarations(visitor.config.noExport),
'type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };',
],
content: content.join('\n'),
content,
};
};

Expand Down
Loading
Loading