From 0c84df853b7ed263ab5642edac13b1e0bd18e905 Mon Sep 17 00:00:00 2001 From: Christopher Bland Date: Mon, 23 Aug 2021 21:21:19 -0400 Subject: [PATCH 1/4] #7517: Allow removing a pointer from a field --- spec/ParseGraphQLServer.spec.js | 44 ++++++++++++++++++++++++++ src/GraphQL/loaders/parseClassTypes.js | 4 +++ src/GraphQL/transformers/mutation.js | 3 ++ 3 files changed, 51 insertions(+) diff --git a/spec/ParseGraphQLServer.spec.js b/spec/ParseGraphQLServer.spec.js index b8673cbe22..c01f2b389a 100644 --- a/spec/ParseGraphQLServer.spec.js +++ b/spec/ParseGraphQLServer.spec.js @@ -8323,6 +8323,50 @@ 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(); + }); + 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..7bd18cdb80 100644 --- a/src/GraphQL/transformers/mutation.js +++ b/src/GraphQL/transformers/mutation.js @@ -224,6 +224,9 @@ const transformers = { objectId, }; } + if (value.unlink) { + return null; + } }, }; From cea7c62e6b07203bfb5e0e14c932c4075fa21412 Mon Sep 17 00:00:00 2001 From: Christopher Bland Date: Thu, 26 Aug 2021 19:35:37 -0400 Subject: [PATCH 2/4] Added entry referencing fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d96ee3d959..c7eed56b59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,6 +144,7 @@ ___ - Added runtime deprecation warnings (Manuel Trezza) [#7451](https://github.com/parse-community/parse-server/pull/7451) - Add ability to pass context of an object via a header, X-Parse-Cloud-Context, for Cloud Code triggers. The header addition allows client SDK's to add context without injecting _context in the body of JSON objects (Corey Baker) [#7437](https://github.com/parse-community/parse-server/pull/7437) - Add CI check to add changelog entry (Manuel Trezza) [#7512](https://github.com/parse-community/parse-server/pull/7512) +- Allow a pointer to be removed using GraphQL (Chris Bland) [#7517](https://github.com/parse-community/parse-server/issues/7517) ## 4.10.2 [Full Changelog](https://github.com/parse-community/parse-server/compare/4.10.1...4.10.2) From b70c6a92dc9429070a692dada10a4184974be0b9 Mon Sep 17 00:00:00 2001 From: Christopher Bland Date: Sat, 16 Oct 2021 13:35:38 -0400 Subject: [PATCH 3/4] Returning delete operation instead of null, added extra check in test --- spec/ParseGraphQLServer.spec.js | 23 +++++++++++++++++++++++ src/GraphQL/transformers/mutation.js | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/ParseGraphQLServer.spec.js b/spec/ParseGraphQLServer.spec.js index c01f2b389a..14f33a020f 100644 --- a/spec/ParseGraphQLServer.spec.js +++ b/spec/ParseGraphQLServer.spec.js @@ -8365,6 +8365,29 @@ describe('ParseGraphQLServer', () => { 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 () => { diff --git a/src/GraphQL/transformers/mutation.js b/src/GraphQL/transformers/mutation.js index 7bd18cdb80..486911b0b9 100644 --- a/src/GraphQL/transformers/mutation.js +++ b/src/GraphQL/transformers/mutation.js @@ -225,7 +225,7 @@ const transformers = { }; } if (value.unlink) { - return null; + return { __op: 'Delete' }; } }, }; From 1e69ecdf28315d4549191c0c8b8625620a79782a Mon Sep 17 00:00:00 2001 From: Christopher Bland Date: Sun, 17 Oct 2021 14:57:33 -0400 Subject: [PATCH 4/4] Moved message under unreleased changes section --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 768379ff81..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) @@ -174,7 +174,6 @@ ___ - refactor: deprecate `Parse.Cloud.httpRequest`; it is recommended to use a HTTP library instead. (Daniel Blyth) [#7595](https://github.com/parse-community/parse-server/pull/7595) - refactor: Modernize HTTPRequest tests (brandongregoryscott) [#7604](https://github.com/parse-community/parse-server/pull/7604) - Allow liveQuery on Session class (Daniel Blyth) [#7554](https://github.com/parse-community/parse-server/pull/7554) -- Allow a pointer to be removed using GraphQL (Chris Bland) [#7517](https://github.com/parse-community/parse-server/issues/7517) # 4.10.4 [Full Changelog](https://github.com/parse-community/parse-server/compare/4.10.3...4.10.4)