1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.GraphQLList = GraphQLList;
|
7 | exports.GraphQLNonNull = GraphQLNonNull;
|
8 |
|
9 | var _definition = require('./definition');
|
10 |
|
11 | // eslint-disable-next-line no-redeclare
|
12 |
|
13 |
|
14 | /**
|
15 | * List Type Wrapper
|
16 | *
|
17 | * A list is a wrapping type which points to another type.
|
18 | * Lists are often created within the context of defining the fields of
|
19 | * an object type.
|
20 | *
|
21 | * Example:
|
22 | *
|
23 | * const PersonType = new GraphQLObjectType({
|
24 | * name: 'Person',
|
25 | * fields: () => ({
|
26 | * parents: { type: GraphQLList(PersonType) },
|
27 | * children: { type: GraphQLList(PersonType) },
|
28 | * })
|
29 | * })
|
30 | *
|
31 | */
|
32 | function GraphQLList(ofType) {
|
33 | if (this instanceof GraphQLList) {
|
34 | this.ofType = (0, _definition.assertType)(ofType);
|
35 | } else {
|
36 | return new GraphQLList(ofType);
|
37 | }
|
38 | }
|
39 |
|
40 | // Also provide toJSON and inspect aliases for toString.
|
41 | /**
|
42 | * Copyright (c) 2015-present, Facebook, Inc.
|
43 | *
|
44 | * This source code is licensed under the MIT license found in the
|
45 | * LICENSE file in the root directory of this source tree.
|
46 | *
|
47 | *
|
48 | */
|
49 |
|
50 | var listProto = GraphQLList.prototype;
|
51 | listProto.toString = listProto.toJSON = listProto.inspect = function toString() {
|
52 | return '[' + String(this.ofType) + ']';
|
53 | };
|
54 |
|
55 | /**
|
56 | * Non-Null Type Wrapper
|
57 | *
|
58 | * A non-null is a wrapping type which points to another type.
|
59 | * Non-null types enforce that their values are never null and can ensure
|
60 | * an error is raised if this ever occurs during a request. It is useful for
|
61 | * fields which you can make a strong guarantee on non-nullability, for example
|
62 | * usually the id field of a database row will never be null.
|
63 | *
|
64 | * Example:
|
65 | *
|
66 | * const RowType = new GraphQLObjectType({
|
67 | * name: 'Row',
|
68 | * fields: () => ({
|
69 | * id: { type: GraphQLNonNull(GraphQLString) },
|
70 | * })
|
71 | * })
|
72 | *
|
73 | * Note: the enforcement of non-nullability occurs within the executor.
|
74 | */
|
75 |
|
76 | // eslint-disable-next-line no-redeclare
|
77 | function GraphQLNonNull(ofType) {
|
78 | if (this instanceof GraphQLNonNull) {
|
79 | this.ofType = (0, _definition.assertNullableType)(ofType);
|
80 | } else {
|
81 | return new GraphQLNonNull(ofType);
|
82 | }
|
83 | }
|
84 |
|
85 | // Also provide toJSON and inspect aliases for toString.
|
86 | var nonNullProto = GraphQLNonNull.prototype;
|
87 | nonNullProto.toString = nonNullProto.toJSON = nonNullProto.inspect = function toString() {
|
88 | return String(this.ofType) + '!';
|
89 | }; |
\ | No newline at end of file |