1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var ID = 'id';
|
13 | var ID_TYPE = 'ID';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function mayImplement(schema, type, typeName) {
|
23 | var unmodifiedType = getRawType(type);
|
24 | return unmodifiedType.toString() === typeName || implementsInterface(unmodifiedType, typeName) || isAbstractType(unmodifiedType) && hasConcreteTypeThatImplements(schema, unmodifiedType, typeName);
|
25 | }
|
26 |
|
27 | function canHaveSelections(type) {
|
28 | return type instanceof require("graphql").GraphQLObjectType || type instanceof require("graphql").GraphQLInterfaceType;
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function hasID(schema, type) {
|
40 | var unmodifiedType = getRawType(type);
|
41 | !(unmodifiedType instanceof require("graphql").GraphQLObjectType || unmodifiedType instanceof require("graphql").GraphQLInterfaceType) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'GraphQLSchemaUtils.hasID(): Expected a concrete type or interface, ' + 'got type `%s`.', type) : require("fbjs/lib/invariant")(false) : void 0;
|
42 | var idType = schema.getType(ID_TYPE);
|
43 | var idField = unmodifiedType.getFields()[ID];
|
44 | return idField && getRawType(idField.type) === idType;
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function isAbstractType(type) {
|
56 | var rawType = getRawType(type);
|
57 | return rawType instanceof require("graphql").GraphQLInterfaceType || rawType instanceof require("graphql").GraphQLUnionType;
|
58 | }
|
59 |
|
60 | function isUnionType(type) {
|
61 | return type instanceof require("graphql").GraphQLUnionType;
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | function getRawType(type) {
|
69 | return require("./nullthrowsOSS")(require("graphql").getNamedType(type));
|
70 | }
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | function getSingularType(type) {
|
77 | var unmodifiedType = type;
|
78 |
|
79 | while (unmodifiedType instanceof require("graphql").GraphQLList) {
|
80 | unmodifiedType = unmodifiedType.ofType;
|
81 | }
|
82 |
|
83 | return unmodifiedType;
|
84 | }
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | function implementsInterface(type, interfaceName) {
|
91 | return getInterfaces(type).some(function (interfaceType) {
|
92 | return interfaceType.toString() === interfaceName;
|
93 | });
|
94 | }
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | function hasConcreteTypeThatImplements(schema, type, interfaceName) {
|
101 | return isAbstractType(type) && getConcreteTypes(schema, type).some(function (concreteType) {
|
102 | return implementsInterface(concreteType, interfaceName);
|
103 | });
|
104 | }
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | function getConcreteTypes(schema, type) {
|
111 | return schema.getPossibleTypes(require("graphql").assertAbstractType(type));
|
112 | }
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | function getInterfaces(type) {
|
119 | if (type instanceof require("graphql").GraphQLObjectType) {
|
120 | return type.getInterfaces();
|
121 | }
|
122 |
|
123 | return [];
|
124 | }
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | function isExecutableDefinitionAST(ast) {
|
133 | return ast.kind === 'FragmentDefinition' || ast.kind === 'OperationDefinition';
|
134 | }
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | function isSchemaDefinitionAST(ast) {
|
143 | return ast.kind === 'SchemaDefinition' || ast.kind === 'ScalarTypeDefinition' || ast.kind === 'ObjectTypeDefinition' || ast.kind === 'InterfaceTypeDefinition' || ast.kind === 'UnionTypeDefinition' || ast.kind === 'EnumTypeDefinition' || ast.kind === 'InputObjectTypeDefinition' || ast.kind === 'DirectiveDefinition' || ast.kind === 'ScalarTypeExtension' || ast.kind === 'ObjectTypeExtension' || ast.kind === 'InterfaceTypeExtension' || ast.kind === 'UnionTypeExtension' || ast.kind === 'EnumTypeExtension' || ast.kind === 'InputObjectTypeExtension';
|
144 | }
|
145 |
|
146 | function assertTypeWithFields(type) {
|
147 | !(type instanceof require("graphql").GraphQLObjectType || type instanceof require("graphql").GraphQLInterfaceType) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'GraphQLSchemaUtils: Expected type `%s` to be an object or interface type.', type) : require("fbjs/lib/invariant")(false) : void 0;
|
148 | return type;
|
149 | }
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | function getTypeFromAST(schema, ast) {
|
158 | var type = require("graphql").typeFromAST(schema, ast);
|
159 |
|
160 | !require("graphql").isType(type) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'GraphQLSchemaUtils: Unknown type `%s`.', require("graphql").print(ast)) : require("fbjs/lib/invariant")(false) : void 0;
|
161 | return type;
|
162 | }
|
163 |
|
164 | module.exports = {
|
165 | assertTypeWithFields: assertTypeWithFields,
|
166 | canHaveSelections: canHaveSelections,
|
167 | getNullableType: require("graphql").getNullableType,
|
168 | getRawType: getRawType,
|
169 | getSingularType: getSingularType,
|
170 | getTypeFromAST: getTypeFromAST,
|
171 | hasID: hasID,
|
172 | implementsInterface: implementsInterface,
|
173 | isAbstractType: isAbstractType,
|
174 | isUnionType: isUnionType,
|
175 | isExecutableDefinitionAST: isExecutableDefinitionAST,
|
176 | isSchemaDefinitionAST: isSchemaDefinitionAST,
|
177 | mayImplement: mayImplement
|
178 | }; |
\ | No newline at end of file |