@@ -32,7 +32,6 @@ import type {
32
32
} from '../language/ast' ;
33
33
import type { GraphQLSchema } from './schema' ;
34
34
import type { MaybePromise } from '../jsutils/MaybePromise' ;
35
- import { GraphQLList , GraphQLNonNull } from './wrappers' ;
36
35
37
36
// Predicates & Assertions
38
37
@@ -315,6 +314,86 @@ export function assertAbstractType(type: mixed): GraphQLAbstractType {
315
314
return type ;
316
315
}
317
316
317
+ /**
318
+ * List Type Wrapper
319
+ *
320
+ * A list is a wrapping type which points to another type.
321
+ * Lists are often created within the context of defining the fields of
322
+ * an object type.
323
+ *
324
+ * Example:
325
+ *
326
+ * const PersonType = new GraphQLObjectType({
327
+ * name : 'Person' ,
328
+ * fields : ( ) = > ( {
329
+ * parents : { type : GraphQLList ( PersonType ) } ,
330
+ * children : { type : GraphQLList ( PersonType ) } ,
331
+ * } )
332
+ * } )
333
+ *
334
+ * /
335
+ declare class GraphQLList < + T : GraphQLType > {
336
+ + ofType : T ;
337
+ static < T > ( ofType : T ) : GraphQLList < T > ;
338
+ // Note: constructors cannot be used for covariant types. Drop the "new".
339
+ constructor ( ofType : any ) : void ;
340
+ }
341
+ // eslint-disable-next-line no-redeclare
342
+ export function GraphQLList ( ofType ) {
343
+ if ( this instanceof GraphQLList ) {
344
+ this . ofType = assertType ( ofType ) ;
345
+ } else {
346
+ return new GraphQLList ( ofType ) ;
347
+ }
348
+ }
349
+
350
+ // Also provide toJSON and inspect aliases for toString.
351
+ const listProto : any = GraphQLList . prototype ;
352
+ listProto . toString = listProto . toJSON = listProto . inspect = function toString ( ) {
353
+ return '[' + String ( this . ofType ) + ']' ;
354
+ } ;
355
+
356
+ /**
357
+ * Non-Null Type Wrapper
358
+ *
359
+ * A non-null is a wrapping type which points to another type.
360
+ * Non-null types enforce that their values are never null and can ensure
361
+ * an error is raised if this ever occurs during a request. It is useful for
362
+ * fields which you can make a strong guarantee on non-nullability, for example
363
+ * usually the id field of a database row will never be null.
364
+ *
365
+ * Example:
366
+ *
367
+ * const RowType = new GraphQLObjectType({
368
+ * name: 'Row',
369
+ * fields: () => ({
370
+ * id: { type: GraphQLNonNull(GraphQLString) },
371
+ * })
372
+ * })
373
+ *
374
+ * Note: the enforcement of non-nullability occurs within the executor.
375
+ */
376
+ declare class GraphQLNonNull < + T : GraphQLNullableType > {
377
+ + ofType : T ;
378
+ static < T > ( ofType : T ) : GraphQLNonNull < T > ;
379
+ // Note: constructors cannot be used for covariant types. Drop the "new".
380
+ constructor ( ofType : any ) : void ;
381
+ }
382
+ // eslint-disable-next-line no-redeclare
383
+ export function GraphQLNonNull ( ofType ) {
384
+ if ( this instanceof GraphQLNonNull ) {
385
+ this . ofType = assertNullableType ( ofType ) ;
386
+ } else {
387
+ return new GraphQLNonNull ( ofType ) ;
388
+ }
389
+ }
390
+
391
+ // Also provide toJSON and inspect aliases for toString.
392
+ const nonNullProto : any = GraphQLNonNull . prototype ;
393
+ nonNullProto . toString = nonNullProto . toJSON = nonNullProto . inspect = function toString ( ) {
394
+ return String ( this . ofType ) + '!' ;
395
+ } ;
396
+
318
397
/**
319
398
* These types wrap and modify other types
320
399
*/
0 commit comments