From 36ad734412e20c7c6664944ab0382ba88b0a0048 Mon Sep 17 00:00:00 2001 From: Antoine Cormouls Date: Thu, 14 Oct 2021 14:28:33 +0200 Subject: [PATCH 1/5] fix: unable to use objectId size higher than 19 on GraphQL API --- CHANGELOG.md | 1 + package-lock.json | 6 +++--- package.json | 2 +- spec/ParseGraphQLServer.spec.js | 29 ++++++++++++++++++++++++----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c876810e6b..b20e78277b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,6 +128,7 @@ ___ - Add REST API endpoint `/loginAs` to create session of any user with master key; allows to impersonate another user. (GormanFletcher) [#7406](https://github.com/parse-community/parse-server/pull/7406) - Add official support for MongoDB 5.0 (Manuel Trezza) [#7469](https://github.com/parse-community/parse-server/pull/7469) - Added Parse Server Configuration `enforcePrivateUsers`, which will remove public access by default on new Parse.Users (dblythy) [#7319](https://github.com/parse-community/parse-server/pull/7319) +- Downgrade GraphQL Relay to 0.7.0 to allow usage of objectId size higher than `19` on GraphQL API (Moumouls) [#7622](https://github.com/parse-community/parse-server/issues/7622) ## Other Changes - Support native mongodb syntax in aggregation pipelines (Raschid JF Rafeally) [#7339](https://github.com/parse-community/parse-server/pull/7339) diff --git a/package-lock.json b/package-lock.json index 633260b688..08083bbe10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6490,9 +6490,9 @@ "integrity": "sha512-9TSAwcVA3KWw7JWYep5NCk2aw3wl1ayLtbMpmG7l26vh1FZ+gZexNPP+XJfUFyJa71UU0zcKSgtgpsrsA3Xv9Q==" }, "graphql-relay": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/graphql-relay/-/graphql-relay-0.9.0.tgz", - "integrity": "sha512-yNJLCqcjz0XpzpmmckRJCSK8a2ZLwTurwrQ09UyGftONh52PbrGpK1UO4yspvj0c7pC+jkN4ZUqVXG3LRrWkXQ==" + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/graphql-relay/-/graphql-relay-0.7.0.tgz", + "integrity": "sha512-P8eS3IbZRhbfbcfud1Q6VPrIru4hchkb15MuOij+WQo9r0chD5NBIxiVjuRE2iG2EMHxIOrZb8LnMe82+YdITA==" }, "graphql-subscriptions": { "version": "1.2.1", diff --git a/package.json b/package.json index 5a6db0d388..92282dd113 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "follow-redirects": "1.14.1", "graphql": "15.6.0", "graphql-list-fields": "2.0.2", - "graphql-relay": "0.9.0", + "graphql-relay": "0.7.0", "graphql-tag": "2.12.5", "graphql-upload": "11.0.0", "intersect": "1.0.1", diff --git a/spec/ParseGraphQLServer.spec.js b/spec/ParseGraphQLServer.spec.js index 6d401cb3c4..42cf1dd879 100644 --- a/spec/ParseGraphQLServer.spec.js +++ b/spec/ParseGraphQLServer.spec.js @@ -2284,8 +2284,7 @@ describe('ParseGraphQLServer', () => { expect(nodeResult.data.node2.objectId).toBe(obj2.id); expect(nodeResult.data.node2.someField).toBe('some value 2'); }); - // TODO: (moumouls, davimacedo) Fix flaky test - xit('Id inputs should work either with global id or object id', async () => { + it('Id inputs should work either with global id or object id', async () => { try { await apolloClient.mutate({ mutation: gql` @@ -2592,9 +2591,12 @@ describe('ParseGraphQLServer', () => { .map(value => value.node.someField) .sort() ).toEqual(['some value 22', 'some value 44']); - expect( - findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.id - ).toBeLessThan(findSecondaryObjectsResult.data.secondaryObjects.edges[1].node.id); + // NOTE: Here @davimacedo tried to test RelayID order, but the test is wrong since + // "objectId1" < "objectId2" do not always keep the order when objectId is transformed + // to base64 by Relay + // "SecondaryObject:bBRgmzIRRM" < "SecondaryObject:nTMcuVbATY" true + // base64("SecondaryObject:bBRgmzIRRM"") < base64(""SecondaryObject:nTMcuVbATY"") false + // "U2Vjb25kYXJ5T2JqZWN0OmJCUmdteklSUk0=" < "U2Vjb25kYXJ5T2JqZWN0Om5UTWN1VmJBVFk=" false expect( findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.objectId ).toBeLessThan( @@ -2760,6 +2762,23 @@ describe('ParseGraphQLServer', () => { handleError(e); } }); + it('Id inputs should work either with global id or object id with objectId higher than 19', async () => { + await reconfigureServer({ objectIdSize: 20 }); + const obj = new Parse.Object('SomeClass'); + await obj.save({ name: 'aname', type: 'robot' }); + const result = await apolloClient.query({ + query: gql` + query getSomeClass($id: ID!) { + someClass(id: $id) { + objectId + id + } + } + `, + variables: { id: obj.id }, + }); + expect(result.data.someClass.objectId).toEqual(obj.id); + }); }); }); From 3b11658d8af4205641ebb3785a3af8f1bd7af458 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Mon, 18 Oct 2021 16:55:01 +0200 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b20e78277b..249c9ea2a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,7 +105,7 @@ ___ ## Features - (none) ## Bug Fixes - - (none) +- Downgrade GraphQL Relay to 0.7.0 to allow usage of objectId size higher than `19` on GraphQL API (Moumouls) [#7622](https://github.com/parse-community/parse-server/issues/7622) # [5.0.0-alpha.1](https://github.com/parse-community/parse-server/compare/4.10.4...5.0.0-alpha.1) (2021-10-12) @@ -128,7 +128,6 @@ ___ - Add REST API endpoint `/loginAs` to create session of any user with master key; allows to impersonate another user. (GormanFletcher) [#7406](https://github.com/parse-community/parse-server/pull/7406) - Add official support for MongoDB 5.0 (Manuel Trezza) [#7469](https://github.com/parse-community/parse-server/pull/7469) - Added Parse Server Configuration `enforcePrivateUsers`, which will remove public access by default on new Parse.Users (dblythy) [#7319](https://github.com/parse-community/parse-server/pull/7319) -- Downgrade GraphQL Relay to 0.7.0 to allow usage of objectId size higher than `19` on GraphQL API (Moumouls) [#7622](https://github.com/parse-community/parse-server/issues/7622) ## Other Changes - Support native mongodb syntax in aggregation pipelines (Raschid JF Rafeally) [#7339](https://github.com/parse-community/parse-server/pull/7339) From 562456f88012a7b9b2d18724f0eb6996a4c72018 Mon Sep 17 00:00:00 2001 From: Antoine Cormouls Date: Tue, 19 Oct 2021 19:45:17 +0200 Subject: [PATCH 3/5] fix: filter selected fields on postgres --- src/Adapters/Storage/Postgres/PostgresStorageAdapter.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 5d0e211ab4..bd89879e64 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -1797,7 +1797,12 @@ export class PostgresStorageAdapter implements StorageAdapter { if (key === 'ACL') { memo.push('_rperm'); memo.push('_wperm'); - } else if (key.length > 0) { + } else if ( + key.length > 0 && + // Remove selected field not referenced in the schema + // Relation is not a column in postgres + ((schema.fields[key] && schema.fields[key]?.type !== 'Relation') || key === '$score') + ) { memo.push(key); } return memo; From 6ed2dafe03e70f2f44b8db1ed5ee55891a359f4d Mon Sep 17 00:00:00 2001 From: Antoine Cormouls Date: Tue, 19 Oct 2021 19:48:03 +0200 Subject: [PATCH 4/5] style: remove chain --- src/Adapters/Storage/Postgres/PostgresStorageAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index bd89879e64..4d917d7dea 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -1801,7 +1801,7 @@ export class PostgresStorageAdapter implements StorageAdapter { key.length > 0 && // Remove selected field not referenced in the schema // Relation is not a column in postgres - ((schema.fields[key] && schema.fields[key]?.type !== 'Relation') || key === '$score') + ((schema.fields[key] && schema.fields[key].type !== 'Relation') || key === '$score') ) { memo.push(key); } From 0d1f3214199f0a6c856c9b4657b0e9981ab4c9b1 Mon Sep 17 00:00:00 2001 From: Antoine Cormouls Date: Thu, 21 Oct 2021 19:19:40 +0200 Subject: [PATCH 5/5] docs: add $score comment --- src/Adapters/Storage/Postgres/PostgresStorageAdapter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 4d917d7dea..eee5bf2fc8 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -1801,6 +1801,7 @@ export class PostgresStorageAdapter implements StorageAdapter { key.length > 0 && // Remove selected field not referenced in the schema // Relation is not a column in postgres + // $score is a Parse special field and is also not a column ((schema.fields[key] && schema.fields[key].type !== 'Relation') || key === '$score') ) { memo.push(key);