Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ___
## Breaking Changes
- (none)
## Features
- (none)
- Allow a pointer to be removed using GraphQL (Chris Bland) [#7517](https://github.com/parse-community/parse-server/issues/7517)
## Bug Fixes
- (none)

Expand Down
67 changes: 67 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8324,6 +8324,73 @@ describe('ParseGraphQLServer', () => {
expect(result.company.name).toEqual('imACompany2');
});

it('should support removing pointer on update', async () => {
const company = new Parse.Object('Company');
company.set('name', 'imACompany1');
await company.save();

const country = new Parse.Object('Country');
country.set('name', 'imACountry');
country.set('company', company);
await country.save();

await parseGraphQLServer.parseGraphQLSchema.schemaCache.clear();

const {
data: {
updateCountry: { country: result },
},
} = await apolloClient.mutate({
mutation: gql`
mutation Update($id: ID!, $fields: UpdateCountryFieldsInput) {
updateCountry(input: { id: $id, fields: $fields }) {
country {
id
objectId
company {
id
objectId
name
}
}
}
}
`,
variables: {
id: country.id,
fields: {
company: { unlink: true },
},
},
});

expect(result.id).toBeDefined();
expect(result.company).toBeNull();

const {
data: { country: result1 },
} = await apolloClient.query({
query: gql`
query getCountry($id: ID!) {
country(id: $id) {
id
objectId
company {
id
objectId
name
}
}
}
`,
variables: {
id: country.id,
},
});

expect(result1.countries).toBeNull();
});

it_only_db('mongo')('should support relation and nested relation on create', async () => {
const company = new Parse.Object('Company');
company.set('name', 'imACompany1');
Expand Down
4 changes: 4 additions & 0 deletions src/GraphQL/loaders/parseClassTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLCla
description: `Link an existing object from ${graphQLClassName} class. You can use either the global or the object id.`,
type: GraphQLID,
},
unlink: {
description: `Unlink an existing object from ${graphQLClassName} class.`,
type: GraphQLBoolean,
},
};
if (isCreateEnabled) {
fields['createAndLink'] = {
Expand Down
3 changes: 3 additions & 0 deletions src/GraphQL/transformers/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ const transformers = {
objectId,
};
}
if (value.unlink) {
return { __op: 'Delete' };
}
},
};

Expand Down