Skip to content

Commit 40373ae

Browse files
Moumoulsdavimacedo
authored andcommitted
GraphQL: Fix undefined Array (parse-community#5926)
* Add Spec * Fix Undefined Array * Nullability policy
1 parent 6b0e5a7 commit 40373ae

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

spec/ParseGraphQLServer.spec.js

+32
Original file line numberDiff line numberDiff line change
@@ -5723,6 +5723,38 @@ describe('ParseGraphQLServer', () => {
57235723
expect(getResult.data.objects.someClasses.results.length).toEqual(2);
57245724
});
57255725

5726+
it('should support undefined array', async () => {
5727+
const schema = await new Parse.Schema('SomeClass');
5728+
schema.addArray('someArray');
5729+
await schema.save();
5730+
5731+
const obj = new Parse.Object('SomeClass');
5732+
await obj.save();
5733+
5734+
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
5735+
5736+
const getResult = await apolloClient.query({
5737+
query: gql`
5738+
query GetSomeObject($objectId: ID!) {
5739+
objects {
5740+
someClass(objectId: $objectId) {
5741+
objectId
5742+
someArray {
5743+
... on Element {
5744+
value
5745+
}
5746+
}
5747+
}
5748+
}
5749+
}
5750+
`,
5751+
variables: {
5752+
objectId: obj.id,
5753+
},
5754+
});
5755+
expect(getResult.data.objects.someClass.someArray).toEqual(null);
5756+
});
5757+
57265758
it('should support null values', async () => {
57275759
const createResult = await apolloClient.mutate({
57285760
mutation: gql`

src/GraphQL/loaders/parseClassTypes.js

+1
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ const load = (
639639
description: `Use Inline Fragment on Array to get results: https://graphql.org/learn/queries/#inline-fragments`,
640640
type,
641641
async resolve(source) {
642+
if (!source[field]) return null;
642643
return source[field].map(async elem => {
643644
if (
644645
elem.className &&

0 commit comments

Comments
 (0)