Skip to content

Commit 8ee0445

Browse files
authored
fix: unable to use objectId size higher than 19 on GraphQL API (#7722)
1 parent 2923833 commit 8ee0445

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"follow-redirects": "1.14.2",
3636
"graphql": "15.6.0",
3737
"graphql-list-fields": "2.0.2",
38-
"graphql-relay": "0.9.0",
38+
"graphql-relay": "0.7.0",
3939
"graphql-tag": "2.12.5",
4040
"graphql-upload": "11.0.0",
4141
"intersect": "1.0.1",

spec/ParseGraphQLServer.spec.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -2284,8 +2284,7 @@ describe('ParseGraphQLServer', () => {
22842284
expect(nodeResult.data.node2.objectId).toBe(obj2.id);
22852285
expect(nodeResult.data.node2.someField).toBe('some value 2');
22862286
});
2287-
// TODO: (moumouls, davimacedo) Fix flaky test
2288-
xit('Id inputs should work either with global id or object id', async () => {
2287+
it('Id inputs should work either with global id or object id', async () => {
22892288
try {
22902289
await apolloClient.mutate({
22912290
mutation: gql`
@@ -2592,9 +2591,12 @@ describe('ParseGraphQLServer', () => {
25922591
.map(value => value.node.someField)
25932592
.sort()
25942593
).toEqual(['some value 22', 'some value 44']);
2595-
expect(
2596-
findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.id
2597-
).toBeLessThan(findSecondaryObjectsResult.data.secondaryObjects.edges[1].node.id);
2594+
// NOTE: Here @davimacedo tried to test RelayID order, but the test is wrong since
2595+
// "objectId1" < "objectId2" do not always keep the order when objectId is transformed
2596+
// to base64 by Relay
2597+
// "SecondaryObject:bBRgmzIRRM" < "SecondaryObject:nTMcuVbATY" true
2598+
// base64("SecondaryObject:bBRgmzIRRM"") < base64(""SecondaryObject:nTMcuVbATY"") false
2599+
// "U2Vjb25kYXJ5T2JqZWN0OmJCUmdteklSUk0=" < "U2Vjb25kYXJ5T2JqZWN0Om5UTWN1VmJBVFk=" false
25982600
expect(
25992601
findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.objectId
26002602
).toBeLessThan(
@@ -2760,6 +2762,23 @@ describe('ParseGraphQLServer', () => {
27602762
handleError(e);
27612763
}
27622764
});
2765+
it('Id inputs should work either with global id or object id with objectId higher than 19', async () => {
2766+
await reconfigureServer({ objectIdSize: 20 });
2767+
const obj = new Parse.Object('SomeClass');
2768+
await obj.save({ name: 'aname', type: 'robot' });
2769+
const result = await apolloClient.query({
2770+
query: gql`
2771+
query getSomeClass($id: ID!) {
2772+
someClass(id: $id) {
2773+
objectId
2774+
id
2775+
}
2776+
}
2777+
`,
2778+
variables: { id: obj.id },
2779+
});
2780+
expect(result.data.someClass.objectId).toEqual(obj.id);
2781+
});
27632782
});
27642783
});
27652784

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,13 @@ export class PostgresStorageAdapter implements StorageAdapter {
18071807
if (key === 'ACL') {
18081808
memo.push('_rperm');
18091809
memo.push('_wperm');
1810-
} else if (key.length > 0) {
1810+
} else if (
1811+
key.length > 0 &&
1812+
// Remove selected field not referenced in the schema
1813+
// Relation is not a column in postgres
1814+
// $score is a Parse special field and is also not a column
1815+
((schema.fields[key] && schema.fields[key].type !== 'Relation') || key === '$score')
1816+
) {
18111817
memo.push(key);
18121818
}
18131819
return memo;

0 commit comments

Comments
 (0)