@@ -230,15 +230,19 @@ export class SchemaBuilder<Types extends SchemaTypes> {
230
230
) : QueryRef < Types > {
231
231
const [ options = { } , fields ] = args ;
232
232
233
- const ref = new QueryRef < Types > ( 'Query' , {
233
+ const ref = new QueryRef < Types > ( options . name ?? 'Query' , {
234
234
kind : 'Query' ,
235
235
graphqlKind : 'Object' ,
236
- name : 'Query' ,
236
+ name : options . name ?? 'Query' ,
237
237
description : options . description ,
238
238
pothosOptions : options as unknown as PothosSchemaTypes . QueryTypeOptions ,
239
239
extensions : options . extensions ,
240
240
} ) ;
241
241
242
+ if ( ref . name !== 'Query' ) {
243
+ this . configStore . associateParamWithRef ( 'Query' , ref ) ;
244
+ }
245
+
242
246
this . configStore . addTypeRef ( ref ) ;
243
247
244
248
if ( fields ) {
@@ -270,17 +274,21 @@ export class SchemaBuilder<Types extends SchemaTypes> {
270
274
) {
271
275
const [ options = { } , fields ] = args ;
272
276
273
- const ref = new MutationRef < Types > ( 'Mutation' , {
277
+ const ref = new MutationRef < Types > ( options . name ?? 'Mutation' , {
274
278
kind : 'Mutation' ,
275
279
graphqlKind : 'Object' ,
276
- name : 'Mutation' ,
280
+ name : options . name ?? 'Mutation' ,
277
281
description : options . description ,
278
282
pothosOptions : options as unknown as PothosSchemaTypes . MutationTypeOptions ,
279
283
extensions : options . extensions ,
280
284
} ) ;
281
285
282
286
this . configStore . addTypeRef ( ref ) ;
283
287
288
+ if ( ref . name !== 'Mutation' ) {
289
+ this . configStore . associateParamWithRef ( 'Mutation' , ref ) ;
290
+ }
291
+
284
292
if ( fields ) {
285
293
this . configStore . addFields ( 'Mutation' , ( ) => fields ( new MutationFieldBuilder ( this ) ) ) ;
286
294
}
@@ -313,17 +321,21 @@ export class SchemaBuilder<Types extends SchemaTypes> {
313
321
) {
314
322
const [ options = { } , fields ] = args ;
315
323
316
- const ref = new SubscriptionRef < Types > ( 'Subscription' , {
324
+ const ref = new SubscriptionRef < Types > ( options . name ?? 'Subscription' , {
317
325
kind : 'Subscription' ,
318
326
graphqlKind : 'Object' ,
319
- name : 'Subscription' ,
327
+ name : options . name ?? 'Subscription' ,
320
328
description : options . description ,
321
329
pothosOptions : options as unknown as PothosSchemaTypes . SubscriptionTypeOptions ,
322
330
extensions : options . extensions ,
323
331
} ) ;
324
332
325
333
this . configStore . addTypeRef ( ref ) ;
326
334
335
+ if ( ref . name !== 'Subscription' ) {
336
+ this . configStore . associateParamWithRef ( 'Subscription' , ref ) ;
337
+ }
338
+
327
339
if ( fields ) {
328
340
this . configStore . addFields ( 'Subscription' , ( ) => fields ( new SubscriptionFieldBuilder ( this ) ) ) ;
329
341
}
@@ -671,10 +683,20 @@ export class SchemaBuilder<Types extends SchemaTypes> {
671
683
672
684
const builtTypes = [ ...buildCache . types . values ( ) ] ;
673
685
686
+ const queryName = this . configStore . hasConfig ( 'Query' )
687
+ ? this . configStore . getTypeConfig ( 'Query' ) . name
688
+ : 'Query' ;
689
+ const mutationName = this . configStore . hasConfig ( 'Mutation' )
690
+ ? this . configStore . getTypeConfig ( 'Mutation' ) . name
691
+ : 'Mutation' ;
692
+ const subscriptionName = this . configStore . hasConfig ( 'Subscription' )
693
+ ? this . configStore . getTypeConfig ( 'Subscription' ) . name
694
+ : 'Subscription' ;
695
+
674
696
const schema = new GraphQLSchema ( {
675
- query : buildCache . types . get ( 'Query' ) as GraphQLObjectType | undefined ,
676
- mutation : buildCache . types . get ( 'Mutation' ) as GraphQLObjectType | undefined ,
677
- subscription : buildCache . types . get ( 'Subscription' ) as GraphQLObjectType | undefined ,
697
+ query : buildCache . types . get ( queryName ) as GraphQLObjectType | undefined ,
698
+ mutation : buildCache . types . get ( mutationName ) as GraphQLObjectType | undefined ,
699
+ subscription : buildCache . types . get ( subscriptionName ) as GraphQLObjectType | undefined ,
678
700
extensions : extensions ?? { } ,
679
701
directives : directives as GraphQLDirective [ ] ,
680
702
types : builtTypes ,
0 commit comments