Skip to content

Commit 8c50b89

Browse files
committed
Optimize query, fixes some null returns, fix stitched GraphQLUpload
1 parent f56049b commit 8c50b89

File tree

6 files changed

+65
-35
lines changed

6 files changed

+65
-35
lines changed

package-lock.json

Lines changed: 41 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"license": "BSD-3-Clause",
2121
"dependencies": {
2222
"@apollographql/graphql-playground-html": "1.6.24",
23+
"@graphql-tools/links": "^6.0.0",
2324
"@graphql-tools/stitch": "^6.0.0",
2425
"@graphql-tools/utils": "^6.0.0",
2526
"@parse/fs-files-adapter": "1.0.1",
@@ -37,7 +38,7 @@
3738
"graphql": "15.0.0",
3839
"graphql-list-fields": "2.0.2",
3940
"graphql-relay": "^0.6.0",
40-
"graphql-upload": "11.0.0",
41+
"graphql-upload": "^11.0.0",
4142
"intersect": "1.0.1",
4243
"jsonwebtoken": "8.5.1",
4344
"jwks-rsa": "1.8.0",

src/GraphQL/helpers/objectsQueries.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ const needToGetAllKeys = (fields, keys, parseClasses) =>
1919
// Current sub key is not custom
2020
return false;
2121
}
22-
} else if (!key[1]) {
22+
} else if (
23+
!key[1] ||
24+
fields[key[0]].type === 'Array' ||
25+
fields[key[0]].type === 'Object'
26+
) {
2327
// current key is not custom
2428
return false;
2529
}

src/GraphQL/loaders/defaultGraphQLTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
GraphQLUnionType,
1616
} from 'graphql';
1717
import { toGlobalId } from 'graphql-relay';
18-
import { GraphQLUpload } from 'graphql-upload';
18+
import { GraphQLUpload } from '@graphql-tools/links';
1919

2020
class TypeValidationError extends Error {
2121
constructor(value, type) {

src/GraphQL/loaders/filesMutations.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GraphQLNonNull } from 'graphql';
22
import { mutationWithClientMutationId } from 'graphql-relay';
3-
import { GraphQLUpload } from 'graphql-upload';
3+
import { GraphQLUpload } from '@graphql-tools/links';
44
import Parse from 'parse/node';
55
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
66
import logger from '../../logger';
@@ -14,7 +14,7 @@ const handleUpload = async (upload, config) => {
1414
const chunks = [];
1515
stream
1616
.on('error', reject)
17-
.on('data', chunk => chunks.push(chunk))
17+
.on('data', (chunk) => chunks.push(chunk))
1818
.on('end', () => resolve(Buffer.concat(chunks)));
1919
});
2020
}
@@ -52,7 +52,7 @@ const handleUpload = async (upload, config) => {
5252
}
5353
};
5454

55-
const load = parseGraphQLSchema => {
55+
const load = (parseGraphQLSchema) => {
5656
const createMutation = mutationWithClientMutationId({
5757
name: 'CreateFile',
5858
description:

src/GraphQL/parseGraphQLUtils.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,32 @@ export function toGraphQLError(error) {
2222
return new ApolloError(message, code);
2323
}
2424

25-
export const extractKeysAndInclude = selectedFields => {
25+
export const extractKeysAndInclude = (selectedFields) => {
2626
selectedFields = selectedFields.filter(
27-
field => !field.includes('__typename')
28-
);
27+
(field) => !field.includes('__typename')
28+
); // Handles "id" field for both current and included objects
2929

30-
// Handles "id" field for both current and included objects
31-
selectedFields = selectedFields.map(field => {
30+
selectedFields = selectedFields.map((field) => {
3231
if (field === 'id') return 'objectId';
3332
return field.endsWith('.id')
3433
? `${field.substring(0, field.lastIndexOf('.id'))}.objectId`
3534
: field;
3635
});
3736
let keys = undefined;
3837
let include = undefined;
38+
3939
if (selectedFields.length > 0) {
4040
keys = selectedFields.join(',');
41-
include = selectedFields
42-
.reduce((fields, field) => {
43-
fields = fields.slice();
44-
let pointIndex = field.lastIndexOf('.');
45-
while (pointIndex > 0) {
46-
const lastField = field.slice(pointIndex + 1);
47-
field = field.slice(0, pointIndex);
48-
if (!fields.includes(field) && lastField !== 'objectId') {
49-
fields.push(field);
50-
}
51-
pointIndex = field.lastIndexOf('.');
52-
}
53-
return fields;
54-
}, [])
55-
.join(',');
41+
// We can use this shortcut since optimization is handled
42+
// later on RestQuery, avoid overhead here.
43+
include = keys;
5644
}
57-
return { keys, include };
45+
return {
46+
keys,
47+
include,
48+
};
5849
};
5950

60-
export const getParseClassMutationConfig = function(parseClassConfig) {
51+
export const getParseClassMutationConfig = function (parseClassConfig) {
6152
return (parseClassConfig && parseClassConfig.mutation) || {};
6253
};

0 commit comments

Comments
 (0)