Skip to content

Commit f5d7fab

Browse files
authored
Merge pull request #237 from proto-graphql/izumin5210/fix-input-ref-type
fix(protoc-gen-pothos): tweak input type definition for avoiding type error
2 parents e733111 + b9945c8 commit f5d7fab

File tree

8 files changed

+131
-130
lines changed

8 files changed

+131
-130
lines changed

.changeset/itchy-dolphins-cry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@proto-graphql/codegen-core": patch
3+
"@testapis/proto": patch
4+
"protoc-gen-pothos": patch
5+
---
6+
7+
tweak input type definition for avoiding type error

packages/@proto-graphql/codegen-core/src/types/InputObjectType.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import { InputObjectField } from "./InputObjectField";
55
import { ScalarType } from "./ScalarType";
66
import { TypeBase } from "./TypeBase";
77
import { getInputObjectFieldType } from "./types";
8-
import { createProtoFullName, FullName, gqlTypeName, isIgnoredField, isOutputOnlyField } from "./util";
8+
import {
9+
createProtoFullName,
10+
FullName,
11+
gqlTypeName,
12+
isIgnoredField,
13+
isOutputOnlyField,
14+
modulesWithUniqueImportAlias,
15+
} from "./util";
916

1017
export class InputObjectType extends TypeBase<ProtoMessage> {
1118
/**
@@ -32,7 +39,11 @@ export class InputObjectType extends TypeBase<ProtoMessage> {
3239
* @override
3340
*/
3441
override get importModules(): { alias: string; module: string; type: "namespace" | "named" }[] {
35-
return [...super.importModules, ...this.fields.flatMap((f) => f.importModules)];
42+
const modules = [...super.importModules, ...this.fields.flatMap((f) => f.importModules)];
43+
if (this.options.dsl === "pothos") {
44+
modules.push(...modulesWithUniqueImportAlias(["@pothos/core"]));
45+
}
46+
return modules;
3647
}
3748

3849
public hasPartialInput(): boolean {

packages/protoc-gen-pothos/src/__tests__/__snapshots__/customTypes.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`custom types generates pothos DSLs: custom_types/date.pb.pothos.ts 1`]
66
77
/* eslint-disable */
88
9+
import * as $$pothos$core from \\"@pothos/core\\";
910
import { builder } from \\"../../builder\\";
1011
import * as _$testapis$custom_types$date from \\"./testapis/custom_types/date\\";
1112
export const Date$Ref = builder.objectRef<_$testapis$custom_types$date.Date>(\\"Date\\");
@@ -61,8 +62,7 @@ export type DateInput$Shape = {
6162
month: _$testapis$custom_types$date.Date[\\"month\\"];
6263
day: _$testapis$custom_types$date.Date[\\"day\\"];
6364
};
64-
export const DateInput$Ref = builder.inputRef<DateInput$Shape>(\\"DateInput\\");
65-
DateInput$Ref.implement({
65+
export const DateInput$Ref: $$pothos$core.InputObjectRef<DateInput$Shape> = builder.inputRef<DateInput$Shape>(\\"DateInput\\").implement({
6666
fields: t => ({
6767
year: t.field({
6868
type: \\"Int\\",
@@ -112,6 +112,7 @@ exports[`custom types generates pothos DSLs: custom_types/post.pb.pothos.ts 1`]
112112
113113
/* eslint-disable */
114114
115+
import * as $$pothos$core from \\"@pothos/core\\";
115116
import { builder } from \\"../../builder\\";
116117
import * as _$testapis$custom_types$post from \\"./testapis/custom_types/post\\";
117118
export const Post$Ref = builder.objectRef<_$testapis$custom_types$post.Post>(\\"Post\\");
@@ -158,8 +159,7 @@ export type PostInput$Shape = {
158159
title: _$testapis$custom_types$post.Post[\\"title\\"];
159160
publishedDate?: _$testapis$custom_types$post.Post[\\"publishedDate\\"] | null;
160161
};
161-
export const PostInput$Ref = builder.inputRef<PostInput$Shape>(\\"PostInput\\");
162-
PostInput$Ref.implement({
162+
export const PostInput$Ref: $$pothos$core.InputObjectRef<PostInput$Shape> = builder.inputRef<PostInput$Shape>(\\"PostInput\\").implement({
163163
fields: t => ({
164164
title: t.field({
165165
type: \\"String\\",

packages/protoc-gen-pothos/src/__tests__/__snapshots__/edgecases.test.ts.snap

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`import squashed union with ts-proto generates pothos DSLs: edgecases/im
66
77
/* eslint-disable */
88
9+
import * as $$pothos$core from \\"@pothos/core\\";
910
import { builder } from \\"../../../../builder\\";
1011
import * as _$testapis$edgecases$import_squashed_union$pkg1$types from \\"./testapis/edgecases/import_squashed_union/pkg1/types\\";
1112
export const OneofMessage1$Ref = builder.objectRef<_$testapis$edgecases$import_squashed_union$pkg1$types.OneofMessage1>(\\"OneofMessage1\\");
@@ -39,8 +40,7 @@ builder.objectType(OneofMessage1$Ref, {
3940
export type OneofMessage1Input$Shape = {
4041
body: _$testapis$edgecases$import_squashed_union$pkg1$types.OneofMessage1[\\"body\\"];
4142
};
42-
export const OneofMessage1Input$Ref = builder.inputRef<OneofMessage1Input$Shape>(\\"OneofMessage1Input\\");
43-
OneofMessage1Input$Ref.implement({
43+
export const OneofMessage1Input$Ref: $$pothos$core.InputObjectRef<OneofMessage1Input$Shape> = builder.inputRef<OneofMessage1Input$Shape>(\\"OneofMessage1Input\\").implement({
4444
fields: t => ({
4545
body: t.field({
4646
type: \\"String\\",
@@ -64,8 +64,7 @@ OneofMessage1Input$Ref.implement({
6464
export type SquashedOneofInput$Shape = {
6565
msg1?: OneofMessage1Input$Shape | null;
6666
};
67-
export const SquashedOneofInput$Ref = builder.inputRef<SquashedOneofInput$Shape>(\\"SquashedOneofInput\\");
68-
SquashedOneofInput$Ref.implement({
67+
export const SquashedOneofInput$Ref: $$pothos$core.InputObjectRef<SquashedOneofInput$Shape> = builder.inputRef<SquashedOneofInput$Shape>(\\"SquashedOneofInput\\").implement({
6968
fields: t => ({
7069
msg1: t.field({
7170
type: OneofMessage1Input$Ref,
@@ -113,6 +112,7 @@ exports[`import squashed union with ts-proto generates pothos DSLs: edgecases/im
113112
114113
/* eslint-disable */
115114
115+
import * as $$pothos$core from \\"@pothos/core\\";
116116
import { builder } from \\"../../../../builder\\";
117117
import * as __$pkg1$types_pb_pothos from \\"../pkg1/types.pb.pothos\\";
118118
import { SquashedOneof$Ref } from \\"../pkg1/types.pb.pothos\\";
@@ -155,8 +155,7 @@ builder.objectType(Message$Ref, {
155155
export type MessageInput$Shape = {
156156
msg?: SquashedOneofInput$Shape | null;
157157
};
158-
export const MessageInput$Ref = builder.inputRef<MessageInput$Shape>(\\"MessageInput\\");
159-
MessageInput$Ref.implement({
158+
export const MessageInput$Ref: $$pothos$core.InputObjectRef<MessageInput$Shape> = builder.inputRef<MessageInput$Shape>(\\"MessageInput\\").implement({
160159
fields: t => ({
161160
msg: t.field({
162161
type: SquashedOneofInput$Ref,

packages/protoc-gen-pothos/src/__tests__/__snapshots__/extensions.test.ts.snap

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`field_nullability generates pothos DSLs with partial inputs: extensions
66
77
/* eslint-disable */
88
9+
import * as $$pothos$core from \\"@pothos/core\\";
910
import { builder } from \\"../../../builder\\";
1011
import * as _$testapis$extensions$field_nullability$nullability from \\"./testapis/extensions/field_nullability/nullability\\";
1112
export const Message$Ref = builder.objectRef<_$testapis$extensions$field_nullability$nullability.Message>(\\"Message\\");
@@ -70,8 +71,7 @@ export type MessageInput$Shape = {
7071
body: _$testapis$extensions$field_nullability$nullability.Message[\\"body\\"];
7172
status?: _$testapis$extensions$field_nullability$nullability.Message[\\"status\\"] | null;
7273
};
73-
export const MessageInput$Ref = builder.inputRef<MessageInput$Shape>(\\"MessageInput\\");
74-
MessageInput$Ref.implement({
74+
export const MessageInput$Ref: $$pothos$core.InputObjectRef<MessageInput$Shape> = builder.inputRef<MessageInput$Shape>(\\"MessageInput\\").implement({
7575
fields: t => ({
7676
userId: t.field({
7777
type: \\"String\\",
@@ -120,8 +120,7 @@ export type MessagePartialInput$Shape = {
120120
body?: _$testapis$extensions$field_nullability$nullability.Message[\\"body\\"] | null;
121121
status?: _$testapis$extensions$field_nullability$nullability.Message[\\"status\\"] | null;
122122
};
123-
export const MessagePartialInput$Ref = builder.inputRef<MessagePartialInput$Shape>(\\"MessagePartialInput\\");
124-
MessagePartialInput$Ref.implement({
123+
export const MessagePartialInput$Ref: $$pothos$core.InputObjectRef<MessagePartialInput$Shape> = builder.inputRef<MessagePartialInput$Shape>(\\"MessagePartialInput\\").implement({
125124
fields: t => ({
126125
userId: t.field({
127126
type: \\"String\\",
@@ -201,6 +200,7 @@ exports[`no_partial generates pothos DSLs with partial inputs: extensions/no_par
201200
202201
/* eslint-disable */
203202
203+
import * as $$pothos$core from \\"@pothos/core\\";
204204
import { builder } from \\"../../../builder\\";
205205
import * as _$testapis$extensions$no_partial$no_partial from \\"./testapis/extensions/no_partial/no_partial\\";
206206
export const ParentMessage$Ref = builder.objectRef<_$testapis$extensions$no_partial$no_partial.ParentMessage>(\\"ParentMessage\\");
@@ -333,8 +333,7 @@ export type ParentMessageInput$Shape = {
333333
partialableInputMessage: PartialableInputMessageInput$Shape;
334334
noPartialInputMessage: NoPartialInputMessageInput$Shape;
335335
};
336-
export const ParentMessageInput$Ref = builder.inputRef<ParentMessageInput$Shape>(\\"ParentMessageInput\\");
337-
ParentMessageInput$Ref.implement({
336+
export const ParentMessageInput$Ref: $$pothos$core.InputObjectRef<ParentMessageInput$Shape> = builder.inputRef<ParentMessageInput$Shape>(\\"ParentMessageInput\\").implement({
338337
fields: t => ({
339338
partialableInputMessage: t.field({
340339
type: PartialableInputMessageInput$Ref,
@@ -371,8 +370,7 @@ export type ParentMessagePartialInput$Shape = {
371370
partialableInputMessage?: PartialableInputMessagePartialInput$Shape | null;
372371
noPartialInputMessage?: NoPartialInputMessageInput$Shape | null;
373372
};
374-
export const ParentMessagePartialInput$Ref = builder.inputRef<ParentMessagePartialInput$Shape>(\\"ParentMessagePartialInput\\");
375-
ParentMessagePartialInput$Ref.implement({
373+
export const ParentMessagePartialInput$Ref: $$pothos$core.InputObjectRef<ParentMessagePartialInput$Shape> = builder.inputRef<ParentMessagePartialInput$Shape>(\\"ParentMessagePartialInput\\").implement({
376374
fields: t => ({
377375
partialableInputMessage: t.field({
378376
type: PartialableInputMessagePartialInput$Ref,
@@ -409,8 +407,7 @@ export type PartialableInputMessageInput$Shape = {
409407
id: _$testapis$extensions$no_partial$no_partial.PartialableInputMessage[\\"id\\"];
410408
body: _$testapis$extensions$no_partial$no_partial.PartialableInputMessage[\\"body\\"];
411409
};
412-
export const PartialableInputMessageInput$Ref = builder.inputRef<PartialableInputMessageInput$Shape>(\\"PartialableInputMessageInput\\");
413-
PartialableInputMessageInput$Ref.implement({
410+
export const PartialableInputMessageInput$Ref: $$pothos$core.InputObjectRef<PartialableInputMessageInput$Shape> = builder.inputRef<PartialableInputMessageInput$Shape>(\\"PartialableInputMessageInput\\").implement({
414411
fields: t => ({
415412
id: t.field({
416413
type: \\"String\\",
@@ -447,8 +444,7 @@ export type PartialableInputMessagePartialInput$Shape = {
447444
id?: _$testapis$extensions$no_partial$no_partial.PartialableInputMessage[\\"id\\"] | null;
448445
body?: _$testapis$extensions$no_partial$no_partial.PartialableInputMessage[\\"body\\"] | null;
449446
};
450-
export const PartialableInputMessagePartialInput$Ref = builder.inputRef<PartialableInputMessagePartialInput$Shape>(\\"PartialableInputMessagePartialInput\\");
451-
PartialableInputMessagePartialInput$Ref.implement({
447+
export const PartialableInputMessagePartialInput$Ref: $$pothos$core.InputObjectRef<PartialableInputMessagePartialInput$Shape> = builder.inputRef<PartialableInputMessagePartialInput$Shape>(\\"PartialableInputMessagePartialInput\\").implement({
452448
fields: t => ({
453449
id: t.field({
454450
type: \\"String\\",
@@ -485,8 +481,7 @@ export type NoPartialInputMessageInput$Shape = {
485481
id: _$testapis$extensions$no_partial$no_partial.NoPartialInputMessage[\\"id\\"];
486482
body: _$testapis$extensions$no_partial$no_partial.NoPartialInputMessage[\\"body\\"];
487483
};
488-
export const NoPartialInputMessageInput$Ref = builder.inputRef<NoPartialInputMessageInput$Shape>(\\"NoPartialInputMessageInput\\");
489-
NoPartialInputMessageInput$Ref.implement({
484+
export const NoPartialInputMessageInput$Ref: $$pothos$core.InputObjectRef<NoPartialInputMessageInput$Shape> = builder.inputRef<NoPartialInputMessageInput$Shape>(\\"NoPartialInputMessageInput\\").implement({
490485
fields: t => ({
491486
id: t.field({
492487
type: \\"String\\",

0 commit comments

Comments
 (0)