Skip to content

Commit

Permalink
GraphQL: Fix undefined Array (parse-community#5926)
Browse files Browse the repository at this point in the history
* Add Spec

* Fix Undefined Array

* Nullability policy
  • Loading branch information
Moumouls authored and davimacedo committed Aug 16, 2019
1 parent 6b0e5a7 commit 40373ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5723,6 +5723,38 @@ describe('ParseGraphQLServer', () => {
expect(getResult.data.objects.someClasses.results.length).toEqual(2);
});

it('should support undefined array', async () => {
const schema = await new Parse.Schema('SomeClass');
schema.addArray('someArray');
await schema.save();

const obj = new Parse.Object('SomeClass');
await obj.save();

await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();

const getResult = await apolloClient.query({
query: gql`
query GetSomeObject($objectId: ID!) {
objects {
someClass(objectId: $objectId) {
objectId
someArray {
... on Element {
value
}
}
}
}
}
`,
variables: {
objectId: obj.id,
},
});
expect(getResult.data.objects.someClass.someArray).toEqual(null);
});

it('should support null values', async () => {
const createResult = await apolloClient.mutate({
mutation: gql`
Expand Down
1 change: 1 addition & 0 deletions src/GraphQL/loaders/parseClassTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ const load = (
description: `Use Inline Fragment on Array to get results: https://graphql.org/learn/queries/#inline-fragments`,
type,
async resolve(source) {
if (!source[field]) return null;
return source[field].map(async elem => {
if (
elem.className &&
Expand Down

0 comments on commit 40373ae

Please sign in to comment.