Skip to content

Commit 66182ce

Browse files
committed
fix graphql errors caused by faulty edges.node handling that had been masked when relation fields always returned
1 parent d018503 commit 66182ce

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ export class MongoStorageAdapter implements StorageAdapter {
670670
// We need to do this because in `mongoObjectToParseObject`, all 'Relation' fields
671671
// are copied over from schema without any filters. (either keep this filtering here
672672
// or pass keys into `mongoObjectToParseObject` via additional optional parameter)
673-
if (Array.isArray(keys)) {
673+
if (Array.isArray(keys) && keys.length > 0) {
674674
// set of string keys
675675
const keysSet = new Set(keys);
676676
const shouldIncludeField = (fieldName) => {

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
19271927
// We need to do this because in `postgresObjectToParseObject`, all 'Relation' fields
19281928
// are copied over from schema without any filters. (either keep this filtering here
19291929
// or pass keys into `postgresObjectToParseObject` via additional optional parameter)
1930-
if (selectedKeys) {
1930+
if (selectedKeys.length > 0) {
19311931
// set of string keys
19321932
const keysSet = new Set(selectedKeys);
19331933
const shouldIncludeField = (fieldName) => {

src/GraphQL/loaders/parseClassQueries.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
108108
selectedFields
109109
.filter(field => field.startsWith('edges.node.'))
110110
.map(field => field.replace('edges.node.', ''))
111+
.map(field => field.replace(/\.edges\.node/g, ''))
111112
.filter(field => field.indexOf('edges.node') < 0)
112113
);
113114
const parseOrder = order && order.join(',');

src/GraphQL/loaders/parseClassTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLCla
387387
selectedFields
388388
.filter(field => field.startsWith('edges.node.'))
389389
.map(field => field.replace('edges.node.', ''))
390+
.map(field => field.replace(/\.edges\.node/g, ''))
390391
.filter(field => field.indexOf('edges.node') < 0)
391392
);
392393
const parseOrder = order && order.join(',');

src/GraphQL/parseGraphQLUtils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ export function toGraphQLError(error) {
2020
}
2121

2222
export const extractKeysAndInclude = selectedFields => {
23-
selectedFields = selectedFields.filter(field => !field.includes('__typename'));
23+
selectedFields = selectedFields
24+
.filter(field => !field.includes('__typename'))
25+
// GraphQL relation connections expose data under `edges.node.*`. Those
26+
// segments do not correspond to actual Parse fields, so strip them to
27+
// ensure the root relation key remains in the keys list (e.g. convert
28+
// `users.edges.node.username` -> `users.username`). This preserves the
29+
// synthetic relation placeholders that Parse injects while still
30+
// respecting field projections.
31+
.map(field => field.replace(/\.edges\.node/g, ''));
2432
// Handles "id" field for both current and included objects
2533
selectedFields = selectedFields.map(field => {
2634
if (field === 'id') { return 'objectId'; }

0 commit comments

Comments
 (0)