GraphQL: Optimize queries, fixes some null returns (on object), fix stitched GraphQLUpload (#6709)
* Optimize query, fixes some null returns, fix stitched GraphQLUpload * Fix authData key selection * Prefer Iso string since other GraphQL solutions use this format * fix tests Co-authored-by: Antonio Davi Macedo Coelho de Castro <adavimacedo@gmail.com>
This commit is contained in:
@@ -22,13 +22,12 @@ export function toGraphQLError(error) {
|
||||
return new ApolloError(message, code);
|
||||
}
|
||||
|
||||
export const extractKeysAndInclude = selectedFields => {
|
||||
export const extractKeysAndInclude = (selectedFields) => {
|
||||
selectedFields = selectedFields.filter(
|
||||
field => !field.includes('__typename')
|
||||
(field) => !field.includes('__typename')
|
||||
);
|
||||
|
||||
// Handles "id" field for both current and included objects
|
||||
selectedFields = selectedFields.map(field => {
|
||||
selectedFields = selectedFields.map((field) => {
|
||||
if (field === 'id') return 'objectId';
|
||||
return field.endsWith('.id')
|
||||
? `${field.substring(0, field.lastIndexOf('.id'))}.objectId`
|
||||
@@ -36,25 +35,21 @@ export const extractKeysAndInclude = selectedFields => {
|
||||
});
|
||||
let keys = undefined;
|
||||
let include = undefined;
|
||||
|
||||
if (selectedFields.length > 0) {
|
||||
keys = selectedFields.join(',');
|
||||
include = selectedFields
|
||||
.reduce((fields, field) => {
|
||||
fields = fields.slice();
|
||||
let pointIndex = field.lastIndexOf('.');
|
||||
while (pointIndex > 0) {
|
||||
const lastField = field.slice(pointIndex + 1);
|
||||
field = field.slice(0, pointIndex);
|
||||
if (!fields.includes(field) && lastField !== 'objectId') {
|
||||
fields.push(field);
|
||||
}
|
||||
pointIndex = field.lastIndexOf('.');
|
||||
}
|
||||
return fields;
|
||||
}, [])
|
||||
.join(',');
|
||||
keys = [...new Set(selectedFields)].join(',');
|
||||
// We can use this shortcut since optimization is handled
|
||||
// later on RestQuery, avoid overhead here.
|
||||
include = keys;
|
||||
}
|
||||
return { keys, include };
|
||||
|
||||
return {
|
||||
// If authData is detected keys will not work properly
|
||||
// since authData has a special storage behavior
|
||||
// so we need to skip keys currently
|
||||
keys: keys && keys.indexOf('authData') === -1 ? keys : undefined,
|
||||
include,
|
||||
};
|
||||
};
|
||||
|
||||
export const getParseClassMutationConfig = function (parseClassConfig) {
|
||||
|
||||
Reference in New Issue
Block a user