Graphql tools v5 (#6611)
* Add test case for order option when extending the schema * Remove fit * upgrade to graphql-tools v5 revert #6515 Co-authored-by: Antonio Davi Macedo Coelho de Castro <adavimacedo@gmail.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@ import { transformQueryInputToParse } from '../transformers/query';
|
||||
/* eslint-disable*/
|
||||
const needToGetAllKeys = (fields, keys, parseClasses) =>
|
||||
keys
|
||||
? keys.split(',').some(keyName => {
|
||||
? keys.split(',').some((keyName) => {
|
||||
const key = keyName.split('.');
|
||||
if (fields[key[0]]) {
|
||||
if (fields[key[0]].type === 'Pointer') {
|
||||
@@ -30,20 +30,6 @@ const needToGetAllKeys = (fields, keys, parseClasses) =>
|
||||
: true;
|
||||
/* eslint-enable*/
|
||||
|
||||
const transformOrder = order =>
|
||||
order
|
||||
.map(o => {
|
||||
const direction = o.indexOf('_ASC') > 0 ? '_ASC' : '_DESC';
|
||||
let field = o.replace(direction, '');
|
||||
field = field === 'id' ? 'objectId' : field;
|
||||
if (direction === '_ASC') {
|
||||
return `${field}`;
|
||||
} else {
|
||||
return `-${field}`;
|
||||
}
|
||||
})
|
||||
.join(',');
|
||||
|
||||
const getObject = async (
|
||||
className,
|
||||
objectId,
|
||||
@@ -168,7 +154,7 @@ const findObjects = async (
|
||||
|
||||
if (
|
||||
selectedFields.find(
|
||||
field => field.startsWith('edges.') || field.startsWith('pageInfo.')
|
||||
(field) => field.startsWith('edges.') || field.startsWith('pageInfo.')
|
||||
)
|
||||
) {
|
||||
if (limit || limit === 0) {
|
||||
@@ -178,7 +164,7 @@ const findObjects = async (
|
||||
}
|
||||
if (options.limit !== 0) {
|
||||
if (order) {
|
||||
options.order = transformOrder(order);
|
||||
options.order = order;
|
||||
}
|
||||
if (skip) {
|
||||
options.skip = skip;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLControlle
|
||||
import { transformClassNameToGraphQL } from '../transformers/className';
|
||||
import { extractKeysAndInclude } from '../parseGraphQLUtils';
|
||||
|
||||
const getParseClassQueryConfig = function(
|
||||
const getParseClassQueryConfig = function (
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) {
|
||||
return (parseClassConfig && parseClassConfig.query) || {};
|
||||
@@ -50,7 +50,7 @@ const getQuery = async (
|
||||
);
|
||||
};
|
||||
|
||||
const load = function(
|
||||
const load = function (
|
||||
parseGraphQLSchema,
|
||||
parseClass,
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
@@ -136,14 +136,15 @@ const load = function(
|
||||
|
||||
const { keys, include } = extractKeysAndInclude(
|
||||
selectedFields
|
||||
.filter(field => field.startsWith('edges.node.'))
|
||||
.map(field => field.replace('edges.node.', ''))
|
||||
.filter((field) => field.startsWith('edges.node.'))
|
||||
.map((field) => field.replace('edges.node.', ''))
|
||||
);
|
||||
const parseOrder = order && order.join(',');
|
||||
|
||||
return await objectsQueries.findObjects(
|
||||
className,
|
||||
where,
|
||||
order,
|
||||
parseOrder,
|
||||
skip,
|
||||
first,
|
||||
after,
|
||||
|
||||
@@ -26,13 +26,13 @@ import {
|
||||
getParseClassMutationConfig,
|
||||
} from '../parseGraphQLUtils';
|
||||
|
||||
const getParseClassTypeConfig = function(
|
||||
const getParseClassTypeConfig = function (
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) {
|
||||
return (parseClassConfig && parseClassConfig.type) || {};
|
||||
};
|
||||
|
||||
const getInputFieldsAndConstraints = function(
|
||||
const getInputFieldsAndConstraints = function (
|
||||
parseClass,
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) {
|
||||
@@ -51,7 +51,7 @@ const getInputFieldsAndConstraints = function(
|
||||
let classSortFields;
|
||||
|
||||
// All allowed customs fields
|
||||
const classCustomFields = classFields.filter(field => {
|
||||
const classCustomFields = classFields.filter((field) => {
|
||||
return (
|
||||
!Object.keys(defaultGraphQLTypes.PARSE_OBJECT_FIELDS).includes(field) &&
|
||||
field !== 'id'
|
||||
@@ -59,14 +59,14 @@ const getInputFieldsAndConstraints = function(
|
||||
});
|
||||
|
||||
if (allowedInputFields && allowedInputFields.create) {
|
||||
classCreateFields = classCustomFields.filter(field => {
|
||||
classCreateFields = classCustomFields.filter((field) => {
|
||||
return allowedInputFields.create.includes(field);
|
||||
});
|
||||
} else {
|
||||
classCreateFields = classCustomFields;
|
||||
}
|
||||
if (allowedInputFields && allowedInputFields.update) {
|
||||
classUpdateFields = classCustomFields.filter(field => {
|
||||
classUpdateFields = classCustomFields.filter((field) => {
|
||||
return allowedInputFields.update.includes(field);
|
||||
});
|
||||
} else {
|
||||
@@ -74,7 +74,7 @@ const getInputFieldsAndConstraints = function(
|
||||
}
|
||||
|
||||
if (allowedOutputFields) {
|
||||
classOutputFields = classCustomFields.filter(field => {
|
||||
classOutputFields = classCustomFields.filter((field) => {
|
||||
return allowedOutputFields.includes(field);
|
||||
});
|
||||
} else {
|
||||
@@ -83,12 +83,12 @@ const getInputFieldsAndConstraints = function(
|
||||
// Filters the "password" field from class _User
|
||||
if (parseClass.className === '_User') {
|
||||
classOutputFields = classOutputFields.filter(
|
||||
outputField => outputField !== 'password'
|
||||
(outputField) => outputField !== 'password'
|
||||
);
|
||||
}
|
||||
|
||||
if (allowedConstraintFields) {
|
||||
classConstraintFields = classCustomFields.filter(field => {
|
||||
classConstraintFields = classCustomFields.filter((field) => {
|
||||
return allowedConstraintFields.includes(field);
|
||||
});
|
||||
} else {
|
||||
@@ -107,7 +107,7 @@ const getInputFieldsAndConstraints = function(
|
||||
});
|
||||
}
|
||||
} else {
|
||||
classSortFields = classFields.map(field => {
|
||||
classSortFields = classFields.map((field) => {
|
||||
return { field, asc: true, desc: true };
|
||||
});
|
||||
}
|
||||
@@ -347,11 +347,12 @@ const load = (
|
||||
const updatedSortFields = {
|
||||
...sortFields,
|
||||
};
|
||||
const value = field === 'id' ? 'objectId' : field;
|
||||
if (asc) {
|
||||
updatedSortFields[`${field}_ASC`] = {};
|
||||
updatedSortFields[`${field}_ASC`] = { value };
|
||||
}
|
||||
if (desc) {
|
||||
updatedSortFields[`${field}_DESC`] = {};
|
||||
updatedSortFields[`${field}_DESC`] = { value: `-${value}` };
|
||||
}
|
||||
return updatedSortFields;
|
||||
}, {}),
|
||||
@@ -382,7 +383,7 @@ const load = (
|
||||
parseGraphQLSchema.relayNodeInterface,
|
||||
];
|
||||
const parseObjectFields = {
|
||||
id: globalIdField(className, obj => obj.objectId),
|
||||
id: globalIdField(className, (obj) => obj.objectId),
|
||||
...defaultGraphQLTypes.PARSE_OBJECT_FIELDS,
|
||||
};
|
||||
const outputFields = () => {
|
||||
@@ -430,9 +431,10 @@ const load = (
|
||||
|
||||
const { keys, include } = extractKeysAndInclude(
|
||||
selectedFields
|
||||
.filter(field => field.startsWith('edges.node.'))
|
||||
.map(field => field.replace('edges.node.', ''))
|
||||
.filter((field) => field.startsWith('edges.node.'))
|
||||
.map((field) => field.replace('edges.node.', ''))
|
||||
);
|
||||
const parseOrder = order && order.join(',');
|
||||
|
||||
return objectsQueries.findObjects(
|
||||
source[field].className,
|
||||
@@ -447,7 +449,7 @@ const load = (
|
||||
},
|
||||
...(where || {}),
|
||||
},
|
||||
order,
|
||||
parseOrder,
|
||||
skip,
|
||||
first,
|
||||
after,
|
||||
@@ -481,7 +483,7 @@ const load = (
|
||||
: type,
|
||||
async resolve(source) {
|
||||
if (source[field] && source[field].coordinates) {
|
||||
return source[field].coordinates.map(coordinate => ({
|
||||
return source[field].coordinates.map((coordinate) => ({
|
||||
latitude: coordinate[0],
|
||||
longitude: coordinate[1],
|
||||
}));
|
||||
@@ -501,7 +503,7 @@ const load = (
|
||||
: type,
|
||||
async resolve(source) {
|
||||
if (!source[field]) return null;
|
||||
return source[field].map(async elem => {
|
||||
return source[field].map(async (elem) => {
|
||||
if (
|
||||
elem.className &&
|
||||
elem.objectId &&
|
||||
|
||||
Reference in New Issue
Block a user