GraphQL: Fix undefined Array (#5926)

* Add Spec

* Fix Undefined Array

* Nullability policy
This commit is contained in:
Antoine Cormouls
2019-08-16 20:12:29 +02:00
committed by Antonio Davi Macedo Coelho de Castro
parent 0fa315fc5b
commit cea1988ce9
2 changed files with 33 additions and 0 deletions

View File

@@ -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`

View File

@@ -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 &&