Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL: Fix undefined Array #5926

Merged
merged 4 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5723,6 +5723,42 @@ describe('ParseGraphQLServer', () => {
expect(getResult.data.objects.someClasses.results.length).toEqual(2);
});

it('should support undefined array values', 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(
Array.isArray(getResult.data.objects.someClass.someArray)
).toBeTruthy();
expect(getResult.data.objects.someClass.someArray.length).toEqual(0);
});

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 [];
Moumouls marked this conversation as resolved.
Show resolved Hide resolved
return source[field].map(async elem => {
if (
elem.className &&
Expand Down