|
1 | 1 | import {
|
2 |
| - Kind, |
3 | 2 | GraphQLID,
|
4 | 3 | GraphQLObjectType,
|
5 | 4 | GraphQLString,
|
6 | 5 | GraphQLList,
|
7 | 6 | GraphQLInputObjectType,
|
8 | 7 | GraphQLNonNull,
|
9 |
| - GraphQLScalarType, |
10 | 8 | GraphQLEnumType,
|
11 | 9 | } from 'graphql';
|
12 | 10 | import getFieldNames from 'graphql-list-fields';
|
@@ -138,86 +136,6 @@ const load = (
|
138 | 136 | update: isUpdateEnabled = true,
|
139 | 137 | } = getParseClassMutationConfig(parseClassConfig);
|
140 | 138 |
|
141 |
| - const classGraphQLScalarTypeName = `${graphQLClassName}Pointer`; |
142 |
| - const parseScalarValue = value => { |
143 |
| - if (typeof value === 'string') { |
144 |
| - return { |
145 |
| - __type: 'Pointer', |
146 |
| - className: className, |
147 |
| - objectId: value, |
148 |
| - }; |
149 |
| - } else if ( |
150 |
| - typeof value === 'object' && |
151 |
| - value.__type === 'Pointer' && |
152 |
| - value.className === className && |
153 |
| - typeof value.objectId === 'string' |
154 |
| - ) { |
155 |
| - return { ...value, className }; |
156 |
| - } |
157 |
| - |
158 |
| - throw new defaultGraphQLTypes.TypeValidationError( |
159 |
| - value, |
160 |
| - classGraphQLScalarTypeName |
161 |
| - ); |
162 |
| - }; |
163 |
| - let classGraphQLScalarType = new GraphQLScalarType({ |
164 |
| - name: classGraphQLScalarTypeName, |
165 |
| - description: `The ${classGraphQLScalarTypeName} is used in operations that involve ${graphQLClassName} pointers.`, |
166 |
| - parseValue: parseScalarValue, |
167 |
| - serialize(value) { |
168 |
| - if (typeof value === 'string') { |
169 |
| - return value; |
170 |
| - } else if ( |
171 |
| - typeof value === 'object' && |
172 |
| - value.__type === 'Pointer' && |
173 |
| - value.className === className && |
174 |
| - typeof value.objectId === 'string' |
175 |
| - ) { |
176 |
| - return value.objectId; |
177 |
| - } |
178 |
| - |
179 |
| - throw new defaultGraphQLTypes.TypeValidationError( |
180 |
| - value, |
181 |
| - classGraphQLScalarTypeName |
182 |
| - ); |
183 |
| - }, |
184 |
| - parseLiteral(ast) { |
185 |
| - if (ast.kind === Kind.STRING) { |
186 |
| - return parseScalarValue(ast.value); |
187 |
| - } else if (ast.kind === Kind.OBJECT) { |
188 |
| - const __type = ast.fields.find(field => field.name.value === '__type'); |
189 |
| - const className = ast.fields.find( |
190 |
| - field => field.name.value === 'className' |
191 |
| - ); |
192 |
| - const objectId = ast.fields.find( |
193 |
| - field => field.name.value === 'objectId' |
194 |
| - ); |
195 |
| - if ( |
196 |
| - __type && |
197 |
| - __type.value && |
198 |
| - className && |
199 |
| - className.value && |
200 |
| - objectId && |
201 |
| - objectId.value |
202 |
| - ) { |
203 |
| - return parseScalarValue({ |
204 |
| - __type: __type.value.value, |
205 |
| - className: className.value.value, |
206 |
| - objectId: objectId.value.value, |
207 |
| - }); |
208 |
| - } |
209 |
| - } |
210 |
| - |
211 |
| - throw new defaultGraphQLTypes.TypeValidationError( |
212 |
| - ast.kind, |
213 |
| - classGraphQLScalarTypeName |
214 |
| - ); |
215 |
| - }, |
216 |
| - }); |
217 |
| - classGraphQLScalarType = |
218 |
| - parseGraphQLSchema.addGraphQLType(classGraphQLScalarType) || |
219 |
| - defaultGraphQLTypes.OBJECT; |
220 |
| - |
221 | 139 | const classGraphQLCreateTypeName = `Create${graphQLClassName}FieldsInput`;
|
222 | 140 | let classGraphQLCreateType = new GraphQLInputObjectType({
|
223 | 141 | name: classGraphQLCreateTypeName,
|
@@ -341,10 +259,10 @@ const load = (
|
341 | 259 | name: classGraphQLConstraintTypeName,
|
342 | 260 | description: `The ${classGraphQLConstraintTypeName} input type is used in operations that involve filtering objects by a pointer field to ${graphQLClassName} class.`,
|
343 | 261 | fields: {
|
344 |
| - equalTo: defaultGraphQLTypes.equalTo(classGraphQLScalarType), |
345 |
| - notEqualTo: defaultGraphQLTypes.notEqualTo(classGraphQLScalarType), |
346 |
| - in: defaultGraphQLTypes.inOp(classGraphQLScalarType), |
347 |
| - notIn: defaultGraphQLTypes.notIn(classGraphQLScalarType), |
| 262 | + equalTo: defaultGraphQLTypes.equalTo(GraphQLID), |
| 263 | + notEqualTo: defaultGraphQLTypes.notEqualTo(GraphQLID), |
| 264 | + in: defaultGraphQLTypes.inOp(defaultGraphQLTypes.OBJECT_ID), |
| 265 | + notIn: defaultGraphQLTypes.notIn(defaultGraphQLTypes.OBJECT_ID), |
348 | 266 | exists: defaultGraphQLTypes.exists,
|
349 | 267 | inQueryKey: defaultGraphQLTypes.inQueryKey,
|
350 | 268 | notInQueryKey: defaultGraphQLTypes.notInQueryKey,
|
@@ -519,7 +437,8 @@ const load = (
|
519 | 437 | config,
|
520 | 438 | auth,
|
521 | 439 | info,
|
522 |
| - selectedFields.map(field => field.split('.', 1)[0]) |
| 440 | + selectedFields.map(field => field.split('.', 1)[0]), |
| 441 | + parseClass.fields |
523 | 442 | );
|
524 | 443 | } catch (e) {
|
525 | 444 | parseGraphQLSchema.handleError(e);
|
@@ -615,7 +534,6 @@ const load = (
|
615 | 534 | parseGraphQLSchema.parseClassTypes[className] = {
|
616 | 535 | classGraphQLPointerType,
|
617 | 536 | classGraphQLRelationType,
|
618 |
| - classGraphQLScalarType, |
619 | 537 | classGraphQLCreateType,
|
620 | 538 | classGraphQLUpdateType,
|
621 | 539 | classGraphQLConstraintType,
|
|
0 commit comments