GraphQL: Fix undefined Array (#5926)
* Add Spec * Fix Undefined Array * Nullability policy
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
0fa315fc5b
commit
cea1988ce9
@@ -5723,6 +5723,38 @@ describe('ParseGraphQLServer', () => {
|
|||||||
expect(getResult.data.objects.someClasses.results.length).toEqual(2);
|
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 () => {
|
it('should support null values', async () => {
|
||||||
const createResult = await apolloClient.mutate({
|
const createResult = await apolloClient.mutate({
|
||||||
mutation: gql`
|
mutation: gql`
|
||||||
|
|||||||
@@ -639,6 +639,7 @@ const load = (
|
|||||||
description: `Use Inline Fragment on Array to get results: https://graphql.org/learn/queries/#inline-fragments`,
|
description: `Use Inline Fragment on Array to get results: https://graphql.org/learn/queries/#inline-fragments`,
|
||||||
type,
|
type,
|
||||||
async resolve(source) {
|
async resolve(source) {
|
||||||
|
if (!source[field]) return null;
|
||||||
return source[field].map(async elem => {
|
return source[field].map(async elem => {
|
||||||
if (
|
if (
|
||||||
elem.className &&
|
elem.className &&
|
||||||
|
|||||||
Reference in New Issue
Block a user