GraphQL: Handle properly keys for pointer fields (#6499)
* Fix Unknow type bug on overloaded types * check args too * Additional fix to detect custom fields on pointer
This commit is contained in:
@@ -3,10 +3,32 @@ import { offsetToCursor, cursorToOffset } from 'graphql-relay';
|
|||||||
import rest from '../../rest';
|
import rest from '../../rest';
|
||||||
import { transformQueryInputToParse } from '../transformers/query';
|
import { transformQueryInputToParse } from '../transformers/query';
|
||||||
|
|
||||||
const needToGetAllKeys = (fields, keys) =>
|
// Eslint/Prettier conflict
|
||||||
|
/* eslint-disable*/
|
||||||
|
const needToGetAllKeys = (fields, keys, parseClasses) =>
|
||||||
keys
|
keys
|
||||||
? !!keys.split(',').find(keyName => !fields[keyName.split('.')[0]])
|
? keys.split(',').some(keyName => {
|
||||||
|
const key = keyName.split('.');
|
||||||
|
if (fields[key[0]]) {
|
||||||
|
if (fields[key[0]].type === 'Pointer') {
|
||||||
|
const subClass = parseClasses.find(
|
||||||
|
({ className: parseClassName }) =>
|
||||||
|
fields[key[0]].targetClass === parseClassName
|
||||||
|
);
|
||||||
|
if (subClass && subClass.fields[key[1]]) {
|
||||||
|
// Current sub key is not custom
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!key[1]) {
|
||||||
|
// current key is not custom
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Key not found into Parse Schema so it's custom
|
||||||
|
return true;
|
||||||
|
})
|
||||||
: true;
|
: true;
|
||||||
|
/* eslint-enable*/
|
||||||
|
|
||||||
const transformOrder = order =>
|
const transformOrder = order =>
|
||||||
order
|
order
|
||||||
@@ -32,11 +54,23 @@ const getObject = async (
|
|||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
info,
|
info,
|
||||||
parseClass
|
parseClasses
|
||||||
) => {
|
) => {
|
||||||
const options = {};
|
const options = {};
|
||||||
if (!needToGetAllKeys(parseClass.fields, keys)) {
|
try {
|
||||||
options.keys = keys;
|
if (
|
||||||
|
!needToGetAllKeys(
|
||||||
|
parseClasses.find(
|
||||||
|
({ className: parseClassName }) => className === parseClassName
|
||||||
|
).fields,
|
||||||
|
keys,
|
||||||
|
parseClasses
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
options.keys = keys;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
}
|
}
|
||||||
if (include) {
|
if (include) {
|
||||||
options.include = include;
|
options.include = include;
|
||||||
@@ -158,7 +192,8 @@ const findObjects = async (
|
|||||||
parseClasses.find(
|
parseClasses.find(
|
||||||
({ className: parseClassName }) => className === parseClassName
|
({ className: parseClassName }) => className === parseClassName
|
||||||
).fields,
|
).fields,
|
||||||
keys
|
keys,
|
||||||
|
parseClasses
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
options.keys = keys;
|
options.keys = keys;
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ const load = parseGraphQLSchema => {
|
|||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
info,
|
info,
|
||||||
parseGraphQLSchema.parseClasses.find(
|
parseGraphQLSchema.parseClasses
|
||||||
({ className }) => type === className
|
|
||||||
)
|
|
||||||
)),
|
)),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -114,7 +114,8 @@ const load = function(
|
|||||||
);
|
);
|
||||||
const needToGetAllKeys = objectsQueries.needToGetAllKeys(
|
const needToGetAllKeys = objectsQueries.needToGetAllKeys(
|
||||||
parseClass.fields,
|
parseClass.fields,
|
||||||
keys
|
keys,
|
||||||
|
parseGraphQLSchema.parseClasses
|
||||||
);
|
);
|
||||||
let optimizedObject = {};
|
let optimizedObject = {};
|
||||||
if (needGet && !needToGetAllKeys) {
|
if (needGet && !needToGetAllKeys) {
|
||||||
@@ -128,7 +129,7 @@ const load = function(
|
|||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
info,
|
info,
|
||||||
parseClass
|
parseGraphQLSchema.parseClasses
|
||||||
);
|
);
|
||||||
} else if (needToGetAllKeys) {
|
} else if (needToGetAllKeys) {
|
||||||
optimizedObject = await objectsQueries.getObject(
|
optimizedObject = await objectsQueries.getObject(
|
||||||
@@ -141,7 +142,7 @@ const load = function(
|
|||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
info,
|
info,
|
||||||
parseClass
|
parseGraphQLSchema.parseClasses
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -232,7 +233,8 @@ const load = function(
|
|||||||
);
|
);
|
||||||
const needToGetAllKeys = objectsQueries.needToGetAllKeys(
|
const needToGetAllKeys = objectsQueries.needToGetAllKeys(
|
||||||
parseClass.fields,
|
parseClass.fields,
|
||||||
keys
|
keys,
|
||||||
|
parseGraphQLSchema.parseClasses
|
||||||
);
|
);
|
||||||
let optimizedObject = {};
|
let optimizedObject = {};
|
||||||
if (needGet && !needToGetAllKeys) {
|
if (needGet && !needToGetAllKeys) {
|
||||||
@@ -246,7 +248,7 @@ const load = function(
|
|||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
info,
|
info,
|
||||||
parseClass
|
parseGraphQLSchema.parseClasses
|
||||||
);
|
);
|
||||||
} else if (needToGetAllKeys) {
|
} else if (needToGetAllKeys) {
|
||||||
optimizedObject = await objectsQueries.getObject(
|
optimizedObject = await objectsQueries.getObject(
|
||||||
@@ -259,7 +261,7 @@ const load = function(
|
|||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
info,
|
info,
|
||||||
parseClass
|
parseGraphQLSchema.parseClasses
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -337,7 +339,7 @@ const load = function(
|
|||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
info,
|
info,
|
||||||
parseClass
|
parseGraphQLSchema.parseClasses
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await objectsMutations.deleteObject(
|
await objectsMutations.deleteObject(
|
||||||
|
|||||||
@@ -14,7 +14,14 @@ const getParseClassQueryConfig = function(
|
|||||||
return (parseClassConfig && parseClassConfig.query) || {};
|
return (parseClassConfig && parseClassConfig.query) || {};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getQuery = async (parseClass, _source, args, context, queryInfo) => {
|
const getQuery = async (
|
||||||
|
parseClass,
|
||||||
|
_source,
|
||||||
|
args,
|
||||||
|
context,
|
||||||
|
queryInfo,
|
||||||
|
parseClasses
|
||||||
|
) => {
|
||||||
let { id } = args;
|
let { id } = args;
|
||||||
const { options } = args;
|
const { options } = args;
|
||||||
const { readPreference, includeReadPreference } = options || {};
|
const { readPreference, includeReadPreference } = options || {};
|
||||||
@@ -39,7 +46,7 @@ const getQuery = async (parseClass, _source, args, context, queryInfo) => {
|
|||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
info,
|
info,
|
||||||
parseClass
|
parseClasses
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,7 +87,14 @@ const load = function(
|
|||||||
),
|
),
|
||||||
async resolve(_source, args, context, queryInfo) {
|
async resolve(_source, args, context, queryInfo) {
|
||||||
try {
|
try {
|
||||||
return await getQuery(parseClass, _source, args, context, queryInfo);
|
return await getQuery(
|
||||||
|
parseClass,
|
||||||
|
_source,
|
||||||
|
args,
|
||||||
|
context,
|
||||||
|
queryInfo,
|
||||||
|
parseGraphQLSchema.parseClasses
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
parseGraphQLSchema.handleError(e);
|
parseGraphQLSchema.handleError(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user