Skip to content

Commit d874bce

Browse files
committedMar 25, 2025·
Improve inference of multiple interfaces
1 parent 553edfe commit d874bce

File tree

16 files changed

+76
-37
lines changed

16 files changed

+76
-37
lines changed
 

‎.changeset/friendly-comics-bow.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@pothos/plugin-simple-objects": patch
3+
"@pothos/plugin-dataloader": patch
4+
"@pothos/plugin-federation": patch
5+
"@pothos/plugin-drizzle": patch
6+
"@pothos/plugin-prisma": patch
7+
"@pothos/plugin-relay": patch
8+
"@pothos/core": patch
9+
---
10+
11+
Improve inference of multiple interfaces

‎packages/core/src/builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class SchemaBuilder<Types extends SchemaTypes> {
143143
}
144144
}
145145

146-
objectType<Interfaces extends InterfaceParam<Types>[], Param extends ObjectParam<Types>>(
146+
objectType<const Interfaces extends InterfaceParam<Types>[], Param extends ObjectParam<Types>>(
147147
param: Param,
148148
options: ObjectTypeOptions<Types, Param, ParentShape<Types, Param>, Interfaces>,
149149
fields?: ObjectFieldsShape<Types, ParentShape<Types, Param>>,
@@ -367,7 +367,7 @@ export class SchemaBuilder<Types extends SchemaTypes> {
367367

368368
interfaceType<
369369
Param extends InterfaceParam<Types>,
370-
Interfaces extends InterfaceParam<Types>[],
370+
const Interfaces extends InterfaceParam<Types>[],
371371
ResolveType,
372372
>(
373373
param: Param,

‎packages/core/src/refs/interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ImplementableInterfaceRef<
3838
this.builder = builder;
3939
}
4040

41-
implement<Interfaces extends InterfaceParam<Types>[]>(
41+
implement<const Interfaces extends InterfaceParam<Types>[]>(
4242
options: InterfaceTypeOptions<
4343
Types,
4444
ImplementableInterfaceRef<Types, Shape, Parent>,

‎packages/core/src/refs/object.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class ImplementableObjectRef<
4646
this.builder = builder;
4747
}
4848

49-
implement<Interfaces extends InterfaceParam<Types>[]>(
49+
implement<const Interfaces extends InterfaceParam<Types>[]>(
5050
options: Omit<
5151
ObjectTypeOptions<Types, ImplementableObjectRef<Types, Shape, Parent>, Parent, Interfaces>,
5252
'name'

‎packages/plugin-dataloader/src/refs/interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class ImplementableLoadableInterfaceRef<
6262
typeof cacheResolved === 'function' ? cacheResolved : cacheResolved && toKey;
6363
}
6464

65-
override implement<Interfaces extends InterfaceParam<Types>[]>(
65+
override implement<const Interfaces extends InterfaceParam<Types>[]>(
6666
options: InterfaceTypeOptions<
6767
Types,
6868
ImplementableInterfaceRef<Types, RefShape, Shape>,

‎packages/plugin-dataloader/src/schema-builder.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ schemaBuilderProto.loadableNodeRef = function loadableNodeRef(name, options) {
3636
schemaBuilderProto.loadableObject = function loadableObject<
3737
LoadResult,
3838
Key extends DataloaderKey,
39-
Interfaces extends InterfaceParam<SchemaTypes>[],
39+
const Interfaces extends InterfaceParam<SchemaTypes>[],
4040
NameOrRef extends ObjectParam<SchemaTypes> | string,
4141
CacheKey = Key,
4242
Shape = ShapeFromLoadResult<LoadResult>,
@@ -75,7 +75,7 @@ schemaBuilderProto.loadableObject = function loadableObject<
7575
schemaBuilderProto.loadableInterface = function loadableInterface<
7676
LoadResult,
7777
Key extends DataloaderKey,
78-
Interfaces extends InterfaceParam<SchemaTypes>[],
78+
const Interfaces extends InterfaceParam<SchemaTypes>[],
7979
NameOrRef extends InterfaceParam<SchemaTypes> | string,
8080
CacheKey = Key,
8181
Shape = ShapeFromLoadResult<LoadResult>,
@@ -150,7 +150,7 @@ schemaBuilderProto.loadableNode = function loadableNode<
150150
LoadResult extends NameOrRef extends ObjectParam<SchemaTypes>
151151
? ShapeFromTypeParam<SchemaTypes, NameOrRef, false> | Error
152152
: unknown,
153-
Interfaces extends InterfaceParam<SchemaTypes>[],
153+
const Interfaces extends InterfaceParam<SchemaTypes>[],
154154
NameOrRef extends ObjectParam<SchemaTypes> | string,
155155
IDShape extends bigint | number | string = string,
156156
Key extends bigint | number | string = IDShape,

‎packages/plugin-drizzle/src/drizzle-field-builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ export class DrizzleObjectFieldBuilder<
8787
Field extends ListRelation<TableConfig>,
8888
Nullable extends boolean,
8989
Args extends InputFieldMap,
90-
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
91-
EdgeInterfaces extends InterfaceParam<Types>[] = [],
90+
const ConnectionInterfaces extends InterfaceParam<Types>[] = [],
91+
const EdgeInterfaces extends InterfaceParam<Types>[] = [],
9292
>(
9393
field: Field,
9494
...args: NormalizeArgs<

‎packages/plugin-drizzle/src/global-types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ declare global {
7373

7474
export interface SchemaBuilder<Types extends SchemaTypes> {
7575
drizzleObject: <
76-
Interfaces extends InterfaceParam<Types>[],
76+
const Interfaces extends InterfaceParam<Types>[],
7777
Table extends keyof Types['DrizzleRelationSchema'],
7878
Selection extends
7979
| DBQueryConfig<
@@ -94,7 +94,7 @@ declare global {
9494
) => DrizzleObjectRef<Types, Table, Shape>;
9595

9696
drizzleInterface: <
97-
Interfaces extends InterfaceParam<Types>[],
97+
const Interfaces extends InterfaceParam<Types>[],
9898
Table extends keyof Types['DrizzleRelationSchema'],
9999
Selection extends
100100
| DBQueryConfig<
@@ -116,7 +116,7 @@ declare global {
116116

117117
drizzleNode: 'relay' extends PluginName
118118
? <
119-
Interfaces extends InterfaceParam<Types>[],
119+
const Interfaces extends InterfaceParam<Types>[],
120120
Table extends keyof Types['DrizzleRelationSchema'],
121121
Selection extends
122122
| DBQueryConfig<
@@ -359,8 +359,8 @@ declare global {
359359
Types['DrizzleRelationSchema'][Type & keyof Types['DrizzleRelationSchema']],
360360
true
361361
>,
362-
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
363-
EdgeInterfaces extends InterfaceParam<Types>[] = [],
362+
const ConnectionInterfaces extends InterfaceParam<Types>[] = [],
363+
const EdgeInterfaces extends InterfaceParam<Types>[] = [],
364364
>(
365365
options: DrizzleConnectionFieldOptions<
366366
Types,

‎packages/plugin-federation/src/external-ref.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ExternalEntityRef<
5656
this.resolveReference = resolveReference;
5757
}
5858

59-
implement<Interfaces extends InterfaceParam<Types>[]>({
59+
implement<const Interfaces extends InterfaceParam<Types>[]>({
6060
fields,
6161
externalFields,
6262
directives,

‎packages/plugin-prisma/src/global-types.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ declare global {
107107
export interface SchemaBuilder<Types extends SchemaTypes> {
108108
prismaObject: <
109109
Name extends keyof Types['PrismaTypes'],
110-
Interfaces extends InterfaceParam<Types>[],
110+
const Interfaces extends InterfaceParam<Types>[],
111111
Model extends PrismaModelTypes & Types['PrismaTypes'][Name],
112112
Include = unknown,
113113
Select = unknown,
@@ -129,7 +129,7 @@ declare global {
129129

130130
prismaInterface: <
131131
Name extends keyof Types['PrismaTypes'],
132-
Interfaces extends InterfaceParam<Types>[],
132+
const Interfaces extends InterfaceParam<Types>[],
133133
Model extends PrismaModelTypes & Types['PrismaTypes'][Name],
134134
Include = unknown,
135135
Select = unknown,
@@ -304,8 +304,8 @@ declare global {
304304
: PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
305305
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
306306
Shape = Type extends PrismaRef<any, PrismaModelTypes, infer S> ? S : Model['Shape'],
307-
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
308-
EdgeInterfaces extends InterfaceParam<Types>[] = [],
307+
const ConnectionInterfaces extends InterfaceParam<Types>[] = [],
308+
const EdgeInterfaces extends InterfaceParam<Types>[] = [],
309309
>(
310310
options: PrismaConnectionFieldOptions<
311311
Types,

‎packages/plugin-prisma/src/prisma-field-builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export class PrismaObjectFieldBuilder<
122122
Field extends Model['ListRelations'],
123123
Nullable extends boolean,
124124
Args extends InputFieldMap,
125-
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
126-
EdgeInterfaces extends InterfaceParam<Types>[] = [],
125+
const ConnectionInterfaces extends InterfaceParam<Types>[] = [],
126+
const EdgeInterfaces extends InterfaceParam<Types>[] = [],
127127
>(
128128
field: Field,
129129
options: RelatedConnectionOptions<Types, Model, Field, Nullable, Args>,

‎packages/plugin-relay/src/global-types.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ declare global {
9595
) => Param extends string ? ImplementableNodeRef<Types, Shape, Shape, IDShape> : Param;
9696

9797
node: <
98-
Interfaces extends InterfaceParam<Types>[],
98+
const Interfaces extends InterfaceParam<Types>[],
9999
Param extends ObjectParam<Types>,
100100
IDShape = string,
101101
>(
@@ -118,7 +118,7 @@ declare global {
118118
Nullable extends boolean,
119119
ResolveShape,
120120
ResolveReturnShape,
121-
Interfaces extends InterfaceParam<Types>[],
121+
const Interfaces extends InterfaceParam<Types>[],
122122
InputName extends string = 'input',
123123
Args extends InputFieldMap = {},
124124
>(
@@ -147,8 +147,8 @@ declare global {
147147
ResolveReturnShape,
148148
EdgeNullability extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'],
149149
NodeNullability extends boolean = Types['DefaultNodeNullability'],
150-
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
151-
EdgeInterfaces extends InterfaceParam<Types>[] = [],
150+
const ConnectionInterfaces extends InterfaceParam<Types>[] = [],
151+
const EdgeInterfaces extends InterfaceParam<Types>[] = [],
152152
>(
153153
connectionOptions: ConnectionObjectOptions<
154154
Types,
@@ -190,7 +190,7 @@ declare global {
190190
Type extends OutputType<Types>,
191191
ResolveReturnShape,
192192
NodeNullability extends boolean = Types['DefaultNodeNullability'],
193-
Interfaces extends InterfaceParam<Types>[] = [],
193+
const Interfaces extends InterfaceParam<Types>[] = [],
194194
>(
195195
edgeOptions: ConnectionEdgeObjectOptions<
196196
Types,
@@ -298,8 +298,8 @@ declare global {
298298
ResolveReturnShape,
299299
EdgeNullability extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'],
300300
NodeNullability extends boolean = Types['DefaultNodeNullability'],
301-
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
302-
EdgeInterfaces extends InterfaceParam<Types>[] = [],
301+
const ConnectionInterfaces extends InterfaceParam<Types>[] = [],
302+
const EdgeInterfaces extends InterfaceParam<Types>[] = [],
303303
ConnectionResult extends ConnectionResultShape<
304304
Types,
305305
ShapeFromTypeParam<Types, Type, false>,

‎packages/plugin-simple-objects/src/global-types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare global {
2222
}
2323
export interface SchemaBuilder<Types extends SchemaTypes> {
2424
simpleObject: <
25-
Interfaces extends InterfaceParam<Types>[],
25+
const Interfaces extends InterfaceParam<Types>[],
2626
Fields extends FieldMap,
2727
Shape extends Normalize<
2828
OutputShapeFromFields<Fields> &
@@ -35,7 +35,7 @@ declare global {
3535
) => ObjectRef<Types, Shape>;
3636

3737
simpleInterface: <
38-
Interfaces extends InterfaceParam<Types>[],
38+
const Interfaces extends InterfaceParam<Types>[],
3939
Fields extends FieldMap,
4040
Shape extends Normalize<
4141
OutputShapeFromFields<Fields> &

‎packages/plugin-simple-objects/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const proto: PothosSchemaTypes.SchemaBuilder<SchemaTypes> =
2626
SchemaBuilder.prototype as PothosSchemaTypes.SchemaBuilder<SchemaTypes>;
2727

2828
proto.simpleObject = function simpleObject<
29-
Interfaces extends InterfaceParam<SchemaTypes>[],
29+
const Interfaces extends InterfaceParam<SchemaTypes>[],
3030
Fields extends FieldMap,
3131
Shape extends Normalize<
3232
OutputShapeFromFields<Fields> &
@@ -49,7 +49,7 @@ proto.simpleObject = function simpleObject<
4949
};
5050

5151
proto.simpleInterface = function simpleInterface<
52-
Interfaces extends InterfaceParam<SchemaTypes>[],
52+
const Interfaces extends InterfaceParam<SchemaTypes>[],
5353
Fields extends FieldMap,
5454
Shape extends Normalize<
5555
OutputShapeFromFields<Fields> &

‎packages/plugin-simple-objects/tests/__snapshots__/index.test.ts.snap

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,31 @@ interface Node {
1010
id: ID!
1111
}
1212
13+
interface Person implements Node & Timestamps {
14+
createdAt: String
15+
firstName: String
16+
id: ID!
17+
lastName: String
18+
updatedAt: String
19+
}
20+
1321
type Query {
1422
user(id: ID!): User
1523
}
1624
17-
type User implements Node {
25+
interface Timestamps {
26+
createdAt: String
27+
updatedAt: String
28+
}
29+
30+
type User implements Node & Person & Timestamps {
1831
contactInfo: ContactInfo!
32+
createdAt: String
1933
firstName: String
2034
fullName: String
2135
id: ID!
2236
lastName: String
37+
updatedAt: String
2338
}"
2439
`;
2540

‎packages/plugin-simple-objects/tests/examples/simple/schema/index.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,26 @@ const Node = builder.simpleInterface('Node', {
1919
}),
2020
});
2121

22+
const Timestamps = builder.simpleInterface('Timestamps', {
23+
fields: (t) => ({
24+
createdAt: t.string(),
25+
updatedAt: t.string(),
26+
}),
27+
});
28+
29+
const Person = builder.simpleInterface('Person', {
30+
interfaces: [Node, Timestamps],
31+
fields: (t) => ({
32+
firstName: t.string(),
33+
lastName: t.string(),
34+
}),
35+
});
36+
2237
const UserType = builder.simpleObject(
2338
'User',
2439
{
25-
interfaces: [Node],
40+
interfaces: [Node, Person, Timestamps],
2641
fields: (t) => ({
27-
firstName: t.string(),
28-
lastName: t.string(),
2942
contactInfo: t.field({
3043
type: ContactInfo,
3144
nullable: false,

0 commit comments

Comments
 (0)
Please sign in to comment.