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*/
|
/* eslint-disable*/
|
||||||
const needToGetAllKeys = (fields, keys, parseClasses) =>
|
const needToGetAllKeys = (fields, keys, parseClasses) =>
|
||||||
keys
|
keys
|
||||||
? keys.split(',').some(keyName => {
|
? keys.split(',').some((keyName) => {
|
||||||
const key = keyName.split('.');
|
const key = keyName.split('.');
|
||||||
if (fields[key[0]]) {
|
if (fields[key[0]]) {
|
||||||
if (fields[key[0]].type === 'Pointer') {
|
if (fields[key[0]].type === 'Pointer') {
|
||||||
@@ -30,20 +30,6 @@ const needToGetAllKeys = (fields, keys, parseClasses) =>
|
|||||||
: true;
|
: true;
|
||||||
/* eslint-enable*/
|
/* 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 (
|
const getObject = async (
|
||||||
className,
|
className,
|
||||||
objectId,
|
objectId,
|
||||||
@@ -168,7 +154,7 @@ const findObjects = async (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
selectedFields.find(
|
selectedFields.find(
|
||||||
field => field.startsWith('edges.') || field.startsWith('pageInfo.')
|
(field) => field.startsWith('edges.') || field.startsWith('pageInfo.')
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
if (limit || limit === 0) {
|
if (limit || limit === 0) {
|
||||||
@@ -178,7 +164,7 @@ const findObjects = async (
|
|||||||
}
|
}
|
||||||
if (options.limit !== 0) {
|
if (options.limit !== 0) {
|
||||||
if (order) {
|
if (order) {
|
||||||
options.order = transformOrder(order);
|
options.order = order;
|
||||||
}
|
}
|
||||||
if (skip) {
|
if (skip) {
|
||||||
options.skip = skip;
|
options.skip = skip;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLControlle
|
|||||||
import { transformClassNameToGraphQL } from '../transformers/className';
|
import { transformClassNameToGraphQL } from '../transformers/className';
|
||||||
import { extractKeysAndInclude } from '../parseGraphQLUtils';
|
import { extractKeysAndInclude } from '../parseGraphQLUtils';
|
||||||
|
|
||||||
const getParseClassQueryConfig = function(
|
const getParseClassQueryConfig = function (
|
||||||
parseClassConfig: ?ParseGraphQLClassConfig
|
parseClassConfig: ?ParseGraphQLClassConfig
|
||||||
) {
|
) {
|
||||||
return (parseClassConfig && parseClassConfig.query) || {};
|
return (parseClassConfig && parseClassConfig.query) || {};
|
||||||
@@ -50,7 +50,7 @@ const getQuery = async (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const load = function(
|
const load = function (
|
||||||
parseGraphQLSchema,
|
parseGraphQLSchema,
|
||||||
parseClass,
|
parseClass,
|
||||||
parseClassConfig: ?ParseGraphQLClassConfig
|
parseClassConfig: ?ParseGraphQLClassConfig
|
||||||
@@ -136,14 +136,15 @@ const load = function(
|
|||||||
|
|
||||||
const { keys, include } = extractKeysAndInclude(
|
const { keys, include } = extractKeysAndInclude(
|
||||||
selectedFields
|
selectedFields
|
||||||
.filter(field => field.startsWith('edges.node.'))
|
.filter((field) => field.startsWith('edges.node.'))
|
||||||
.map(field => field.replace('edges.node.', ''))
|
.map((field) => field.replace('edges.node.', ''))
|
||||||
);
|
);
|
||||||
|
const parseOrder = order && order.join(',');
|
||||||
|
|
||||||
return await objectsQueries.findObjects(
|
return await objectsQueries.findObjects(
|
||||||
className,
|
className,
|
||||||
where,
|
where,
|
||||||
order,
|
parseOrder,
|
||||||
skip,
|
skip,
|
||||||
first,
|
first,
|
||||||
after,
|
after,
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ import {
|
|||||||
getParseClassMutationConfig,
|
getParseClassMutationConfig,
|
||||||
} from '../parseGraphQLUtils';
|
} from '../parseGraphQLUtils';
|
||||||
|
|
||||||
const getParseClassTypeConfig = function(
|
const getParseClassTypeConfig = function (
|
||||||
parseClassConfig: ?ParseGraphQLClassConfig
|
parseClassConfig: ?ParseGraphQLClassConfig
|
||||||
) {
|
) {
|
||||||
return (parseClassConfig && parseClassConfig.type) || {};
|
return (parseClassConfig && parseClassConfig.type) || {};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getInputFieldsAndConstraints = function(
|
const getInputFieldsAndConstraints = function (
|
||||||
parseClass,
|
parseClass,
|
||||||
parseClassConfig: ?ParseGraphQLClassConfig
|
parseClassConfig: ?ParseGraphQLClassConfig
|
||||||
) {
|
) {
|
||||||
@@ -51,7 +51,7 @@ const getInputFieldsAndConstraints = function(
|
|||||||
let classSortFields;
|
let classSortFields;
|
||||||
|
|
||||||
// All allowed customs fields
|
// All allowed customs fields
|
||||||
const classCustomFields = classFields.filter(field => {
|
const classCustomFields = classFields.filter((field) => {
|
||||||
return (
|
return (
|
||||||
!Object.keys(defaultGraphQLTypes.PARSE_OBJECT_FIELDS).includes(field) &&
|
!Object.keys(defaultGraphQLTypes.PARSE_OBJECT_FIELDS).includes(field) &&
|
||||||
field !== 'id'
|
field !== 'id'
|
||||||
@@ -59,14 +59,14 @@ const getInputFieldsAndConstraints = function(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (allowedInputFields && allowedInputFields.create) {
|
if (allowedInputFields && allowedInputFields.create) {
|
||||||
classCreateFields = classCustomFields.filter(field => {
|
classCreateFields = classCustomFields.filter((field) => {
|
||||||
return allowedInputFields.create.includes(field);
|
return allowedInputFields.create.includes(field);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
classCreateFields = classCustomFields;
|
classCreateFields = classCustomFields;
|
||||||
}
|
}
|
||||||
if (allowedInputFields && allowedInputFields.update) {
|
if (allowedInputFields && allowedInputFields.update) {
|
||||||
classUpdateFields = classCustomFields.filter(field => {
|
classUpdateFields = classCustomFields.filter((field) => {
|
||||||
return allowedInputFields.update.includes(field);
|
return allowedInputFields.update.includes(field);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -74,7 +74,7 @@ const getInputFieldsAndConstraints = function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (allowedOutputFields) {
|
if (allowedOutputFields) {
|
||||||
classOutputFields = classCustomFields.filter(field => {
|
classOutputFields = classCustomFields.filter((field) => {
|
||||||
return allowedOutputFields.includes(field);
|
return allowedOutputFields.includes(field);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -83,12 +83,12 @@ const getInputFieldsAndConstraints = function(
|
|||||||
// Filters the "password" field from class _User
|
// Filters the "password" field from class _User
|
||||||
if (parseClass.className === '_User') {
|
if (parseClass.className === '_User') {
|
||||||
classOutputFields = classOutputFields.filter(
|
classOutputFields = classOutputFields.filter(
|
||||||
outputField => outputField !== 'password'
|
(outputField) => outputField !== 'password'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allowedConstraintFields) {
|
if (allowedConstraintFields) {
|
||||||
classConstraintFields = classCustomFields.filter(field => {
|
classConstraintFields = classCustomFields.filter((field) => {
|
||||||
return allowedConstraintFields.includes(field);
|
return allowedConstraintFields.includes(field);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -107,7 +107,7 @@ const getInputFieldsAndConstraints = function(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
classSortFields = classFields.map(field => {
|
classSortFields = classFields.map((field) => {
|
||||||
return { field, asc: true, desc: true };
|
return { field, asc: true, desc: true };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -347,11 +347,12 @@ const load = (
|
|||||||
const updatedSortFields = {
|
const updatedSortFields = {
|
||||||
...sortFields,
|
...sortFields,
|
||||||
};
|
};
|
||||||
|
const value = field === 'id' ? 'objectId' : field;
|
||||||
if (asc) {
|
if (asc) {
|
||||||
updatedSortFields[`${field}_ASC`] = {};
|
updatedSortFields[`${field}_ASC`] = { value };
|
||||||
}
|
}
|
||||||
if (desc) {
|
if (desc) {
|
||||||
updatedSortFields[`${field}_DESC`] = {};
|
updatedSortFields[`${field}_DESC`] = { value: `-${value}` };
|
||||||
}
|
}
|
||||||
return updatedSortFields;
|
return updatedSortFields;
|
||||||
}, {}),
|
}, {}),
|
||||||
@@ -382,7 +383,7 @@ const load = (
|
|||||||
parseGraphQLSchema.relayNodeInterface,
|
parseGraphQLSchema.relayNodeInterface,
|
||||||
];
|
];
|
||||||
const parseObjectFields = {
|
const parseObjectFields = {
|
||||||
id: globalIdField(className, obj => obj.objectId),
|
id: globalIdField(className, (obj) => obj.objectId),
|
||||||
...defaultGraphQLTypes.PARSE_OBJECT_FIELDS,
|
...defaultGraphQLTypes.PARSE_OBJECT_FIELDS,
|
||||||
};
|
};
|
||||||
const outputFields = () => {
|
const outputFields = () => {
|
||||||
@@ -430,9 +431,10 @@ const load = (
|
|||||||
|
|
||||||
const { keys, include } = extractKeysAndInclude(
|
const { keys, include } = extractKeysAndInclude(
|
||||||
selectedFields
|
selectedFields
|
||||||
.filter(field => field.startsWith('edges.node.'))
|
.filter((field) => field.startsWith('edges.node.'))
|
||||||
.map(field => field.replace('edges.node.', ''))
|
.map((field) => field.replace('edges.node.', ''))
|
||||||
);
|
);
|
||||||
|
const parseOrder = order && order.join(',');
|
||||||
|
|
||||||
return objectsQueries.findObjects(
|
return objectsQueries.findObjects(
|
||||||
source[field].className,
|
source[field].className,
|
||||||
@@ -447,7 +449,7 @@ const load = (
|
|||||||
},
|
},
|
||||||
...(where || {}),
|
...(where || {}),
|
||||||
},
|
},
|
||||||
order,
|
parseOrder,
|
||||||
skip,
|
skip,
|
||||||
first,
|
first,
|
||||||
after,
|
after,
|
||||||
@@ -481,7 +483,7 @@ const load = (
|
|||||||
: type,
|
: type,
|
||||||
async resolve(source) {
|
async resolve(source) {
|
||||||
if (source[field] && source[field].coordinates) {
|
if (source[field] && source[field].coordinates) {
|
||||||
return source[field].coordinates.map(coordinate => ({
|
return source[field].coordinates.map((coordinate) => ({
|
||||||
latitude: coordinate[0],
|
latitude: coordinate[0],
|
||||||
longitude: coordinate[1],
|
longitude: coordinate[1],
|
||||||
}));
|
}));
|
||||||
@@ -501,7 +503,7 @@ const load = (
|
|||||||
: type,
|
: type,
|
||||||
async resolve(source) {
|
async resolve(source) {
|
||||||
if (!source[field]) return null;
|
if (!source[field]) return null;
|
||||||
return source[field].map(async elem => {
|
return source[field].map(async (elem) => {
|
||||||
if (
|
if (
|
||||||
elem.className &&
|
elem.className &&
|
||||||
elem.objectId &&
|
elem.objectId &&
|
||||||
|
|||||||
Reference in New Issue
Block a user