diff --git a/CHANGELOG.md b/CHANGELOG.md index c876810e6b..f4bef1fb40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/spec/ParseGraphQLServer.spec.js b/spec/ParseGraphQLServer.spec.js index 9f75b94210..02176ae092 100644 --- a/spec/ParseGraphQLServer.spec.js +++ b/spec/ParseGraphQLServer.spec.js @@ -8321,6 +8321,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'); diff --git a/src/GraphQL/loaders/parseClassTypes.js b/src/GraphQL/loaders/parseClassTypes.js index df4ed791ea..4be50337ee 100644 --- a/src/GraphQL/loaders/parseClassTypes.js +++ b/src/GraphQL/loaders/parseClassTypes.js @@ -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'] = { diff --git a/src/GraphQL/transformers/mutation.js b/src/GraphQL/transformers/mutation.js index 583d330620..486911b0b9 100644 --- a/src/GraphQL/transformers/mutation.js +++ b/src/GraphQL/transformers/mutation.js @@ -224,6 +224,9 @@ const transformers = { objectId, }; } + if (value.unlink) { + return { __op: 'Delete' }; + } }, };