fix: unable to use objectId size higher than 19 on GraphQL API (#7722)

This commit is contained in:
Manuel
2021-11-27 13:36:49 +01:00
committed by GitHub
parent 2923833b25
commit 8ee0445c0a
4 changed files with 35 additions and 10 deletions

6
package-lock.json generated
View File

@@ -7496,9 +7496,9 @@
"integrity": "sha512-9TSAwcVA3KWw7JWYep5NCk2aw3wl1ayLtbMpmG7l26vh1FZ+gZexNPP+XJfUFyJa71UU0zcKSgtgpsrsA3Xv9Q==" "integrity": "sha512-9TSAwcVA3KWw7JWYep5NCk2aw3wl1ayLtbMpmG7l26vh1FZ+gZexNPP+XJfUFyJa71UU0zcKSgtgpsrsA3Xv9Q=="
}, },
"graphql-relay": { "graphql-relay": {
"version": "0.9.0", "version": "0.7.0",
"resolved": "https://registry.npmjs.org/graphql-relay/-/graphql-relay-0.9.0.tgz", "resolved": "https://registry.npmjs.org/graphql-relay/-/graphql-relay-0.7.0.tgz",
"integrity": "sha512-yNJLCqcjz0XpzpmmckRJCSK8a2ZLwTurwrQ09UyGftONh52PbrGpK1UO4yspvj0c7pC+jkN4ZUqVXG3LRrWkXQ==" "integrity": "sha512-P8eS3IbZRhbfbcfud1Q6VPrIru4hchkb15MuOij+WQo9r0chD5NBIxiVjuRE2iG2EMHxIOrZb8LnMe82+YdITA=="
}, },
"graphql-subscriptions": { "graphql-subscriptions": {
"version": "1.2.1", "version": "1.2.1",

View File

@@ -35,7 +35,7 @@
"follow-redirects": "1.14.2", "follow-redirects": "1.14.2",
"graphql": "15.6.0", "graphql": "15.6.0",
"graphql-list-fields": "2.0.2", "graphql-list-fields": "2.0.2",
"graphql-relay": "0.9.0", "graphql-relay": "0.7.0",
"graphql-tag": "2.12.5", "graphql-tag": "2.12.5",
"graphql-upload": "11.0.0", "graphql-upload": "11.0.0",
"intersect": "1.0.1", "intersect": "1.0.1",

View File

@@ -2284,8 +2284,7 @@ describe('ParseGraphQLServer', () => {
expect(nodeResult.data.node2.objectId).toBe(obj2.id); expect(nodeResult.data.node2.objectId).toBe(obj2.id);
expect(nodeResult.data.node2.someField).toBe('some value 2'); expect(nodeResult.data.node2.someField).toBe('some value 2');
}); });
// TODO: (moumouls, davimacedo) Fix flaky test it('Id inputs should work either with global id or object id', async () => {
xit('Id inputs should work either with global id or object id', async () => {
try { try {
await apolloClient.mutate({ await apolloClient.mutate({
mutation: gql` mutation: gql`
@@ -2592,9 +2591,12 @@ describe('ParseGraphQLServer', () => {
.map(value => value.node.someField) .map(value => value.node.someField)
.sort() .sort()
).toEqual(['some value 22', 'some value 44']); ).toEqual(['some value 22', 'some value 44']);
expect( // NOTE: Here @davimacedo tried to test RelayID order, but the test is wrong since
findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.id // "objectId1" < "objectId2" do not always keep the order when objectId is transformed
).toBeLessThan(findSecondaryObjectsResult.data.secondaryObjects.edges[1].node.id); // to base64 by Relay
// "SecondaryObject:bBRgmzIRRM" < "SecondaryObject:nTMcuVbATY" true
// base64("SecondaryObject:bBRgmzIRRM"") < base64(""SecondaryObject:nTMcuVbATY"") false
// "U2Vjb25kYXJ5T2JqZWN0OmJCUmdteklSUk0=" < "U2Vjb25kYXJ5T2JqZWN0Om5UTWN1VmJBVFk=" false
expect( expect(
findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.objectId findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.objectId
).toBeLessThan( ).toBeLessThan(
@@ -2760,6 +2762,23 @@ describe('ParseGraphQLServer', () => {
handleError(e); 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);
});
}); });
}); });

View File

@@ -1807,7 +1807,13 @@ export class PostgresStorageAdapter implements StorageAdapter {
if (key === 'ACL') { if (key === 'ACL') {
memo.push('_rperm'); memo.push('_rperm');
memo.push('_wperm'); 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
// $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); memo.push(key);
} }
return memo; return memo;