Skip to content

Commit b7e46e0

Browse files
committed
wip: Tests
1 parent f1facb1 commit b7e46e0

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

spec/ParseGraphQLServer.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,8 @@ describe('ParseGraphQLServer', () => {
21912191
results
21922192
}
21932193
${className.charAt(0).toLowerCase() +
2194-
className.slice(1)} {
2194+
className.slice(1) +
2195+
's'} {
21952196
results {
21962197
objectId
21972198
someField
@@ -2211,7 +2212,9 @@ describe('ParseGraphQLServer', () => {
22112212
const genericFindResults = result.data.objects.find.results;
22122213
const specificFindResults =
22132214
result.data.objects[
2214-
`${className.charAt(0).toLowerCase() + className.slice(1)}`
2215+
`${className.charAt(0).toLowerCase() +
2216+
className.slice(1) +
2217+
's'}`
22152218
].results;
22162219
genericFindResults.forEach(({ objectId, someField }) => {
22172220
expect(
@@ -2819,7 +2822,6 @@ describe('ParseGraphQLServer', () => {
28192822
},
28202823
},
28212824
});
2822-
28232825
expect(
28242826
result1.data.objects.find.results[0].pointerToUser.username
28252827
).toBeUndefined();

src/GraphQL/loaders/parseClassTypes.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import getFieldNames from 'graphql-list-fields';
1414
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
1515
import * as objectsQueries from './objectsQueries';
1616
import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLController';
17-
import { transformClassNameToGraphQL } from '../transformers/className';
17+
import {
18+
transformClassNameToGraphQL,
19+
transformClassNameToParse,
20+
} from '../transformers/className';
1821

1922
const mapInputType = (parseType, targetClass, parseClassTypes) => {
2023
switch (parseType) {
@@ -58,6 +61,7 @@ const mapInputType = (parseType, targetClass, parseClassTypes) => {
5861
};
5962

6063
const mapOutputType = (parseType, targetClass, parseClassTypes) => {
64+
targetClass = transformClassNameToGraphQL(targetClass);
6165
switch (parseType) {
6266
case 'String':
6367
return GraphQLString;
@@ -268,7 +272,7 @@ const load = (
268272
if (typeof value === 'string') {
269273
return {
270274
__type: 'Pointer',
271-
className,
275+
className: transformClassNameToParse(className),
272276
objectId: value,
273277
};
274278
} else if (
@@ -277,7 +281,7 @@ const load = (
277281
value.className === className &&
278282
typeof value.objectId === 'string'
279283
) {
280-
return value;
284+
return { ...value, className: transformClassNameToParse(className) };
281285
}
282286

283287
throw new defaultGraphQLTypes.TypeValidationError(
@@ -295,7 +299,7 @@ const load = (
295299
} else if (
296300
typeof value === 'object' &&
297301
value.__type === 'Pointer' &&
298-
value.className === className &&
302+
transformClassNameToGraphQL(value.className) === className &&
299303
typeof value.objectId === 'string'
300304
) {
301305
return value.objectId;
@@ -539,7 +543,7 @@ const load = (
539543
if (parseClass.fields[field].type === 'Relation') {
540544
const targetParseClassTypes =
541545
parseGraphQLSchema.parseClassTypes[
542-
parseClass.fields[field].targetClass
546+
transformClassNameToGraphQL(parseClass.fields[field].targetClass)
543547
];
544548
const args = targetParseClassTypes
545549
? targetParseClassTypes.classGraphQLFindArgs
@@ -569,14 +573,14 @@ const load = (
569573
.filter(field => field.includes('.'))
570574
.map(field => field.slice(field.indexOf('.') + 1))
571575
);
572-
576+
console.log(source[field].className);
573577
return await objectsQueries.findObjects(
574578
source[field].className,
575579
{
576580
_relatedTo: {
577581
object: {
578582
__type: 'Pointer',
579-
className,
583+
className: transformClassNameToParse(className),
580584
objectId: source.objectId,
581585
},
582586
key: field,

0 commit comments

Comments
 (0)