Fix Prettier (#7066)
This commit is contained in:
@@ -5,40 +5,17 @@ const createObject = async (className, fields, config, auth, info) => {
|
||||
fields = {};
|
||||
}
|
||||
|
||||
return (
|
||||
await rest.create(
|
||||
config,
|
||||
auth,
|
||||
className,
|
||||
fields,
|
||||
info.clientSDK,
|
||||
info.context
|
||||
)
|
||||
).response;
|
||||
return (await rest.create(config, auth, className, fields, info.clientSDK, info.context))
|
||||
.response;
|
||||
};
|
||||
|
||||
const updateObject = async (
|
||||
className,
|
||||
objectId,
|
||||
fields,
|
||||
config,
|
||||
auth,
|
||||
info
|
||||
) => {
|
||||
const updateObject = async (className, objectId, fields, config, auth, info) => {
|
||||
if (!fields) {
|
||||
fields = {};
|
||||
}
|
||||
|
||||
return (
|
||||
await rest.update(
|
||||
config,
|
||||
auth,
|
||||
className,
|
||||
{ objectId },
|
||||
fields,
|
||||
info.clientSDK,
|
||||
info.context
|
||||
)
|
||||
await rest.update(config, auth, className, { objectId }, fields, info.clientSDK, info.context)
|
||||
).response;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ const load = parseGraphQLSchema => {
|
||||
parseGraphQLSchema.addGraphQLQuery(
|
||||
'health',
|
||||
{
|
||||
description:
|
||||
'The health query can be used to check if the server is up and running.',
|
||||
description: 'The health query can be used to check if the server is up and running.',
|
||||
type: new GraphQLNonNull(GraphQLBoolean),
|
||||
resolve: () => true,
|
||||
},
|
||||
|
||||
@@ -23,7 +23,7 @@ class TypeValidationError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
const parseStringValue = (value) => {
|
||||
const parseStringValue = value => {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ const parseStringValue = (value) => {
|
||||
throw new TypeValidationError(value, 'String');
|
||||
};
|
||||
|
||||
const parseIntValue = (value) => {
|
||||
const parseIntValue = value => {
|
||||
if (typeof value === 'string') {
|
||||
const int = Number(value);
|
||||
if (Number.isInteger(int)) {
|
||||
@@ -42,7 +42,7 @@ const parseIntValue = (value) => {
|
||||
throw new TypeValidationError(value, 'Int');
|
||||
};
|
||||
|
||||
const parseFloatValue = (value) => {
|
||||
const parseFloatValue = value => {
|
||||
if (typeof value === 'string') {
|
||||
const float = Number(value);
|
||||
if (!isNaN(float)) {
|
||||
@@ -53,7 +53,7 @@ const parseFloatValue = (value) => {
|
||||
throw new TypeValidationError(value, 'Float');
|
||||
};
|
||||
|
||||
const parseBooleanValue = (value) => {
|
||||
const parseBooleanValue = value => {
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ const parseBooleanValue = (value) => {
|
||||
throw new TypeValidationError(value, 'Boolean');
|
||||
};
|
||||
|
||||
const parseValue = (value) => {
|
||||
const parseValue = value => {
|
||||
switch (value.kind) {
|
||||
case Kind.STRING:
|
||||
return parseStringValue(value.value);
|
||||
@@ -86,15 +86,15 @@ const parseValue = (value) => {
|
||||
}
|
||||
};
|
||||
|
||||
const parseListValues = (values) => {
|
||||
const parseListValues = values => {
|
||||
if (Array.isArray(values)) {
|
||||
return values.map((value) => parseValue(value));
|
||||
return values.map(value => parseValue(value));
|
||||
}
|
||||
|
||||
throw new TypeValidationError(values, 'List');
|
||||
};
|
||||
|
||||
const parseObjectFields = (fields) => {
|
||||
const parseObjectFields = fields => {
|
||||
if (Array.isArray(fields)) {
|
||||
return fields.reduce(
|
||||
(object, field) => ({
|
||||
@@ -112,15 +112,14 @@ const ANY = new GraphQLScalarType({
|
||||
name: 'Any',
|
||||
description:
|
||||
'The Any scalar type is used in operations and types that involve any type of value.',
|
||||
parseValue: (value) => value,
|
||||
serialize: (value) => value,
|
||||
parseLiteral: (ast) => parseValue(ast),
|
||||
parseValue: value => value,
|
||||
serialize: value => value,
|
||||
parseLiteral: ast => parseValue(ast),
|
||||
});
|
||||
|
||||
const OBJECT = new GraphQLScalarType({
|
||||
name: 'Object',
|
||||
description:
|
||||
'The Object scalar type is used in operations and types that involve objects.',
|
||||
description: 'The Object scalar type is used in operations and types that involve objects.',
|
||||
parseValue(value) {
|
||||
if (typeof value === 'object') {
|
||||
return value;
|
||||
@@ -144,7 +143,7 @@ const OBJECT = new GraphQLScalarType({
|
||||
},
|
||||
});
|
||||
|
||||
const parseDateIsoValue = (value) => {
|
||||
const parseDateIsoValue = value => {
|
||||
if (typeof value === 'string') {
|
||||
const date = new Date(value);
|
||||
if (!isNaN(date)) {
|
||||
@@ -157,7 +156,7 @@ const parseDateIsoValue = (value) => {
|
||||
throw new TypeValidationError(value, 'Date');
|
||||
};
|
||||
|
||||
const serializeDateIso = (value) => {
|
||||
const serializeDateIso = value => {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
@@ -168,7 +167,7 @@ const serializeDateIso = (value) => {
|
||||
throw new TypeValidationError(value, 'Date');
|
||||
};
|
||||
|
||||
const parseDateIsoLiteral = (ast) => {
|
||||
const parseDateIsoLiteral = ast => {
|
||||
if (ast.kind === Kind.STRING) {
|
||||
return parseDateIsoValue(ast.value);
|
||||
}
|
||||
@@ -178,19 +177,14 @@ const parseDateIsoLiteral = (ast) => {
|
||||
|
||||
const DATE = new GraphQLScalarType({
|
||||
name: 'Date',
|
||||
description:
|
||||
'The Date scalar type is used in operations and types that involve dates.',
|
||||
description: 'The Date scalar type is used in operations and types that involve dates.',
|
||||
parseValue(value) {
|
||||
if (typeof value === 'string' || value instanceof Date) {
|
||||
return {
|
||||
__type: 'Date',
|
||||
iso: parseDateIsoValue(value),
|
||||
};
|
||||
} else if (
|
||||
typeof value === 'object' &&
|
||||
value.__type === 'Date' &&
|
||||
value.iso
|
||||
) {
|
||||
} else if (typeof value === 'object' && value.__type === 'Date' && value.iso) {
|
||||
return {
|
||||
__type: value.__type,
|
||||
iso: parseDateIsoValue(value.iso),
|
||||
@@ -202,11 +196,7 @@ const DATE = new GraphQLScalarType({
|
||||
serialize(value) {
|
||||
if (typeof value === 'string' || value instanceof Date) {
|
||||
return serializeDateIso(value);
|
||||
} else if (
|
||||
typeof value === 'object' &&
|
||||
value.__type === 'Date' &&
|
||||
value.iso
|
||||
) {
|
||||
} else if (typeof value === 'object' && value.__type === 'Date' && value.iso) {
|
||||
return serializeDateIso(value.iso);
|
||||
}
|
||||
|
||||
@@ -219,8 +209,8 @@ const DATE = new GraphQLScalarType({
|
||||
iso: parseDateIsoLiteral(ast),
|
||||
};
|
||||
} else if (ast.kind === Kind.OBJECT) {
|
||||
const __type = ast.fields.find((field) => field.name.value === '__type');
|
||||
const iso = ast.fields.find((field) => field.name.value === 'iso');
|
||||
const __type = ast.fields.find(field => field.name.value === '__type');
|
||||
const iso = ast.fields.find(field => field.name.value === 'iso');
|
||||
if (__type && __type.value && __type.value.value === 'Date' && iso) {
|
||||
return {
|
||||
__type: __type.value.value,
|
||||
@@ -273,8 +263,8 @@ const BYTES = new GraphQLScalarType({
|
||||
base64: ast.value,
|
||||
};
|
||||
} else if (ast.kind === Kind.OBJECT) {
|
||||
const __type = ast.fields.find((field) => field.name.value === '__type');
|
||||
const base64 = ast.fields.find((field) => field.name.value === 'base64');
|
||||
const __type = ast.fields.find(field => field.name.value === '__type');
|
||||
const base64 = ast.fields.find(field => field.name.value === 'base64');
|
||||
if (
|
||||
__type &&
|
||||
__type.value &&
|
||||
@@ -294,7 +284,7 @@ const BYTES = new GraphQLScalarType({
|
||||
},
|
||||
});
|
||||
|
||||
const parseFileValue = (value) => {
|
||||
const parseFileValue = value => {
|
||||
if (typeof value === 'string') {
|
||||
return {
|
||||
__type: 'File',
|
||||
@@ -314,10 +304,9 @@ const parseFileValue = (value) => {
|
||||
|
||||
const FILE = new GraphQLScalarType({
|
||||
name: 'File',
|
||||
description:
|
||||
'The File scalar type is used in operations and types that involve files.',
|
||||
description: 'The File scalar type is used in operations and types that involve files.',
|
||||
parseValue: parseFileValue,
|
||||
serialize: (value) => {
|
||||
serialize: value => {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
} else if (
|
||||
@@ -335,9 +324,9 @@ const FILE = new GraphQLScalarType({
|
||||
if (ast.kind === Kind.STRING) {
|
||||
return parseFileValue(ast.value);
|
||||
} else if (ast.kind === Kind.OBJECT) {
|
||||
const __type = ast.fields.find((field) => field.name.value === '__type');
|
||||
const name = ast.fields.find((field) => field.name.value === 'name');
|
||||
const url = ast.fields.find((field) => field.name.value === 'url');
|
||||
const __type = ast.fields.find(field => field.name.value === '__type');
|
||||
const name = ast.fields.find(field => field.name.value === 'name');
|
||||
const url = ast.fields.find(field => field.name.value === 'url');
|
||||
if (__type && __type.value && name && name.value) {
|
||||
return parseFileValue({
|
||||
__type: __type.value.value,
|
||||
@@ -353,8 +342,7 @@ const FILE = new GraphQLScalarType({
|
||||
|
||||
const FILE_INFO = new GraphQLObjectType({
|
||||
name: 'FileInfo',
|
||||
description:
|
||||
'The FileInfo object type is used to return the information about files.',
|
||||
description: 'The FileInfo object type is used to return the information about files.',
|
||||
fields: {
|
||||
name: {
|
||||
description: 'This is the file name.',
|
||||
@@ -407,8 +395,7 @@ const GEO_POINT_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const GEO_POINT = new GraphQLObjectType({
|
||||
name: 'GeoPoint',
|
||||
description:
|
||||
'The GeoPoint object type is used to return the information about geo point fields.',
|
||||
description: 'The GeoPoint object type is used to return the information about geo point fields.',
|
||||
fields: GEO_POINT_FIELDS,
|
||||
});
|
||||
|
||||
@@ -444,13 +431,11 @@ const ROLE_ACL_INPUT = new GraphQLInputObjectType({
|
||||
type: new GraphQLNonNull(GraphQLString),
|
||||
},
|
||||
read: {
|
||||
description:
|
||||
'Allow users who are members of the role to read the current object.',
|
||||
description: 'Allow users who are members of the role to read the current object.',
|
||||
type: new GraphQLNonNull(GraphQLBoolean),
|
||||
},
|
||||
write: {
|
||||
description:
|
||||
'Allow users who are members of the role to write on the current object.',
|
||||
description: 'Allow users who are members of the role to write on the current object.',
|
||||
type: new GraphQLNonNull(GraphQLBoolean),
|
||||
},
|
||||
},
|
||||
@@ -521,13 +506,11 @@ const ROLE_ACL = new GraphQLObjectType({
|
||||
type: new GraphQLNonNull(GraphQLID),
|
||||
},
|
||||
read: {
|
||||
description:
|
||||
'Allow users who are members of the role to read the current object.',
|
||||
description: 'Allow users who are members of the role to read the current object.',
|
||||
type: new GraphQLNonNull(GraphQLBoolean),
|
||||
},
|
||||
write: {
|
||||
description:
|
||||
'Allow users who are members of the role to write on the current object.',
|
||||
description: 'Allow users who are members of the role to write on the current object.',
|
||||
type: new GraphQLNonNull(GraphQLBoolean),
|
||||
},
|
||||
},
|
||||
@@ -557,7 +540,7 @@ const ACL = new GraphQLObjectType({
|
||||
type: new GraphQLList(new GraphQLNonNull(USER_ACL)),
|
||||
resolve(p) {
|
||||
const users = [];
|
||||
Object.keys(p).forEach((rule) => {
|
||||
Object.keys(p).forEach(rule => {
|
||||
if (rule !== '*' && rule.indexOf('role:') !== 0) {
|
||||
users.push({
|
||||
userId: toGlobalId('_User', rule),
|
||||
@@ -574,7 +557,7 @@ const ACL = new GraphQLObjectType({
|
||||
type: new GraphQLList(new GraphQLNonNull(ROLE_ACL)),
|
||||
resolve(p) {
|
||||
const roles = [];
|
||||
Object.keys(p).forEach((rule) => {
|
||||
Object.keys(p).forEach(rule => {
|
||||
if (rule.indexOf('role:') === 0) {
|
||||
roles.push({
|
||||
roleName: rule.replace('role:', ''),
|
||||
@@ -610,8 +593,7 @@ const CLASS_NAME_ATT = {
|
||||
};
|
||||
|
||||
const GLOBAL_OR_OBJECT_ID_ATT = {
|
||||
description:
|
||||
'This is the object id. You can use either the global or the object id.',
|
||||
description: 'This is the object id. You can use either the global or the object id.',
|
||||
type: OBJECT_ID,
|
||||
};
|
||||
|
||||
@@ -686,8 +668,7 @@ const READ_PREFERENCE_ATT = {
|
||||
};
|
||||
|
||||
const INCLUDE_READ_PREFERENCE_ATT = {
|
||||
description:
|
||||
'The read preference for the queries to be executed to include fields.',
|
||||
description: 'The read preference for the queries to be executed to include fields.',
|
||||
type: READ_PREFERENCE,
|
||||
};
|
||||
|
||||
@@ -713,8 +694,7 @@ const READ_OPTIONS_ATT = {
|
||||
};
|
||||
|
||||
const WHERE_ATT = {
|
||||
description:
|
||||
'These are the conditions that the objects need to match in order to be found',
|
||||
description: 'These are the conditions that the objects need to match in order to be found',
|
||||
type: OBJECT,
|
||||
};
|
||||
|
||||
@@ -736,8 +716,7 @@ const COUNT_ATT = {
|
||||
|
||||
const SEARCH_INPUT = new GraphQLInputObjectType({
|
||||
name: 'SearchInput',
|
||||
description:
|
||||
'The SearchInput type is used to specifiy a search operation on a full text search.',
|
||||
description: 'The SearchInput type is used to specifiy a search operation on a full text search.',
|
||||
fields: {
|
||||
term: {
|
||||
description: 'This is the term to be searched.',
|
||||
@@ -749,13 +728,11 @@ const SEARCH_INPUT = new GraphQLInputObjectType({
|
||||
type: GraphQLString,
|
||||
},
|
||||
caseSensitive: {
|
||||
description:
|
||||
'This is the flag to enable or disable case sensitive search.',
|
||||
description: 'This is the flag to enable or disable case sensitive search.',
|
||||
type: GraphQLBoolean,
|
||||
},
|
||||
diacriticSensitive: {
|
||||
description:
|
||||
'This is the flag to enable or disable diacritic sensitive search.',
|
||||
description: 'This is the flag to enable or disable diacritic sensitive search.',
|
||||
type: GraphQLBoolean,
|
||||
},
|
||||
},
|
||||
@@ -763,8 +740,7 @@ const SEARCH_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const TEXT_INPUT = new GraphQLInputObjectType({
|
||||
name: 'TextInput',
|
||||
description:
|
||||
'The TextInput type is used to specify a text operation on a constraint.',
|
||||
description: 'The TextInput type is used to specify a text operation on a constraint.',
|
||||
fields: {
|
||||
search: {
|
||||
description: 'This is the search to be executed.',
|
||||
@@ -775,8 +751,7 @@ const TEXT_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const BOX_INPUT = new GraphQLInputObjectType({
|
||||
name: 'BoxInput',
|
||||
description:
|
||||
'The BoxInput type is used to specifiy a box operation on a within geo query.',
|
||||
description: 'The BoxInput type is used to specifiy a box operation on a within geo query.',
|
||||
fields: {
|
||||
bottomLeft: {
|
||||
description: 'This is the bottom left coordinates of the box.',
|
||||
@@ -791,8 +766,7 @@ const BOX_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const WITHIN_INPUT = new GraphQLInputObjectType({
|
||||
name: 'WithinInput',
|
||||
description:
|
||||
'The WithinInput type is used to specify a within operation on a constraint.',
|
||||
description: 'The WithinInput type is used to specify a within operation on a constraint.',
|
||||
fields: {
|
||||
box: {
|
||||
description: 'This is the box to be specified.',
|
||||
@@ -819,8 +793,7 @@ const CENTER_SPHERE_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const GEO_WITHIN_INPUT = new GraphQLInputObjectType({
|
||||
name: 'GeoWithinInput',
|
||||
description:
|
||||
'The GeoWithinInput type is used to specify a geoWithin operation on a constraint.',
|
||||
description: 'The GeoWithinInput type is used to specify a geoWithin operation on a constraint.',
|
||||
fields: {
|
||||
polygon: {
|
||||
description: 'This is the polygon to be specified.',
|
||||
@@ -845,49 +818,49 @@ const GEO_INTERSECTS_INPUT = new GraphQLInputObjectType({
|
||||
},
|
||||
});
|
||||
|
||||
const equalTo = (type) => ({
|
||||
const equalTo = type => ({
|
||||
description:
|
||||
'This is the equalTo operator to specify a constraint to select the objects where the value of a field equals to a specified value.',
|
||||
type,
|
||||
});
|
||||
|
||||
const notEqualTo = (type) => ({
|
||||
const notEqualTo = type => ({
|
||||
description:
|
||||
'This is the notEqualTo operator to specify a constraint to select the objects where the value of a field do not equal to a specified value.',
|
||||
type,
|
||||
});
|
||||
|
||||
const lessThan = (type) => ({
|
||||
const lessThan = type => ({
|
||||
description:
|
||||
'This is the lessThan operator to specify a constraint to select the objects where the value of a field is less than a specified value.',
|
||||
type,
|
||||
});
|
||||
|
||||
const lessThanOrEqualTo = (type) => ({
|
||||
const lessThanOrEqualTo = type => ({
|
||||
description:
|
||||
'This is the lessThanOrEqualTo operator to specify a constraint to select the objects where the value of a field is less than or equal to a specified value.',
|
||||
type,
|
||||
});
|
||||
|
||||
const greaterThan = (type) => ({
|
||||
const greaterThan = type => ({
|
||||
description:
|
||||
'This is the greaterThan operator to specify a constraint to select the objects where the value of a field is greater than a specified value.',
|
||||
type,
|
||||
});
|
||||
|
||||
const greaterThanOrEqualTo = (type) => ({
|
||||
const greaterThanOrEqualTo = type => ({
|
||||
description:
|
||||
'This is the greaterThanOrEqualTo operator to specify a constraint to select the objects where the value of a field is greater than or equal to a specified value.',
|
||||
type,
|
||||
});
|
||||
|
||||
const inOp = (type) => ({
|
||||
const inOp = type => ({
|
||||
description:
|
||||
'This is the in operator to specify a constraint to select the objects where the value of a field equals any value in the specified array.',
|
||||
type: new GraphQLList(type),
|
||||
});
|
||||
|
||||
const notIn = (type) => ({
|
||||
const notIn = type => ({
|
||||
description:
|
||||
'This is the notIn operator to specify a constraint to select the objects where the value of a field do not equal any value in the specified array.',
|
||||
type: new GraphQLList(type),
|
||||
@@ -913,8 +886,7 @@ const options = {
|
||||
|
||||
const SUBQUERY_INPUT = new GraphQLInputObjectType({
|
||||
name: 'SubqueryInput',
|
||||
description:
|
||||
'The SubqueryInput type is used to specify a sub query to another class.',
|
||||
description: 'The SubqueryInput type is used to specify a sub query to another class.',
|
||||
fields: {
|
||||
className: CLASS_NAME_ATT,
|
||||
where: Object.assign({}, WHERE_ATT, {
|
||||
@@ -988,8 +960,7 @@ const STRING_WHERE_INPUT = new GraphQLInputObjectType({
|
||||
matchesRegex,
|
||||
options,
|
||||
text: {
|
||||
description:
|
||||
'This is the $text operator to specify a full text search constraint.',
|
||||
description: 'This is the $text operator to specify a full text search constraint.',
|
||||
type: TEXT_INPUT,
|
||||
},
|
||||
inQueryKey,
|
||||
@@ -1225,27 +1196,21 @@ let ARRAY_RESULT;
|
||||
|
||||
const loadArrayResult = (parseGraphQLSchema, parseClasses) => {
|
||||
const classTypes = parseClasses
|
||||
.filter((parseClass) =>
|
||||
parseGraphQLSchema.parseClassTypes[parseClass.className]
|
||||
.classGraphQLOutputType
|
||||
? true
|
||||
: false
|
||||
.filter(parseClass =>
|
||||
parseGraphQLSchema.parseClassTypes[parseClass.className].classGraphQLOutputType ? true : false
|
||||
)
|
||||
.map(
|
||||
(parseClass) =>
|
||||
parseGraphQLSchema.parseClassTypes[parseClass.className]
|
||||
.classGraphQLOutputType
|
||||
parseClass => parseGraphQLSchema.parseClassTypes[parseClass.className].classGraphQLOutputType
|
||||
);
|
||||
ARRAY_RESULT = new GraphQLUnionType({
|
||||
name: 'ArrayResult',
|
||||
description:
|
||||
'Use Inline Fragment on Array to get results: https://graphql.org/learn/queries/#inline-fragments',
|
||||
types: () => [ELEMENT, ...classTypes],
|
||||
resolveType: (value) => {
|
||||
resolveType: value => {
|
||||
if (value.__type === 'Object' && value.className && value.objectId) {
|
||||
if (parseGraphQLSchema.parseClassTypes[value.className]) {
|
||||
return parseGraphQLSchema.parseClassTypes[value.className]
|
||||
.classGraphQLOutputType;
|
||||
return parseGraphQLSchema.parseClassTypes[value.className].classGraphQLOutputType;
|
||||
} else {
|
||||
return ELEMENT;
|
||||
}
|
||||
@@ -1257,7 +1222,7 @@ const loadArrayResult = (parseGraphQLSchema, parseClasses) => {
|
||||
parseGraphQLSchema.graphQLTypes.push(ARRAY_RESULT);
|
||||
};
|
||||
|
||||
const load = (parseGraphQLSchema) => {
|
||||
const load = parseGraphQLSchema => {
|
||||
parseGraphQLSchema.addGraphQLType(GraphQLUpload, true);
|
||||
parseGraphQLSchema.addGraphQLType(ANY, true);
|
||||
parseGraphQLSchema.addGraphQLType(OBJECT, true);
|
||||
|
||||
@@ -39,8 +39,7 @@ const load = parseGraphQLSchema => {
|
||||
}
|
||||
},
|
||||
obj => {
|
||||
return parseGraphQLSchema.parseClassTypes[obj.className]
|
||||
.classGraphQLOutputType;
|
||||
return parseGraphQLSchema.parseClassTypes[obj.className].classGraphQLOutputType;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ const handleUpload = async (upload, config) => {
|
||||
const chunks = [];
|
||||
stream
|
||||
.on('error', reject)
|
||||
.on('data', (chunk) => chunks.push(chunk))
|
||||
.on('data', chunk => chunks.push(chunk))
|
||||
.on('end', () => resolve(Buffer.concat(chunks)));
|
||||
});
|
||||
}
|
||||
@@ -28,35 +28,23 @@ const handleUpload = async (upload, config) => {
|
||||
}
|
||||
|
||||
if (!filename.match(/^[_a-zA-Z0-9][a-zA-Z0-9@\.\ ~_-]*$/)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_FILE_NAME,
|
||||
'Filename contains invalid characters.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_FILE_NAME, 'Filename contains invalid characters.');
|
||||
}
|
||||
|
||||
try {
|
||||
return {
|
||||
fileInfo: await config.filesController.createFile(
|
||||
config,
|
||||
filename,
|
||||
data,
|
||||
mimetype
|
||||
),
|
||||
fileInfo: await config.filesController.createFile(config, filename, data, mimetype),
|
||||
};
|
||||
} catch (e) {
|
||||
logger.error('Error creating a file: ', e);
|
||||
throw new Parse.Error(
|
||||
Parse.Error.FILE_SAVE_ERROR,
|
||||
`Could not store file: ${filename}.`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.FILE_SAVE_ERROR, `Could not store file: ${filename}.`);
|
||||
}
|
||||
};
|
||||
|
||||
const load = (parseGraphQLSchema) => {
|
||||
const load = parseGraphQLSchema => {
|
||||
const createMutation = mutationWithClientMutationId({
|
||||
name: 'CreateFile',
|
||||
description:
|
||||
'The createFile mutation can be used to create and upload a new file.',
|
||||
description: 'The createFile mutation can be used to create and upload a new file.',
|
||||
inputFields: {
|
||||
upload: {
|
||||
description: 'This is the new file to be created and uploaded.',
|
||||
@@ -80,18 +68,9 @@ const load = (parseGraphQLSchema) => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
createMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(createMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(createMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
'createFile',
|
||||
createMutation,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation('createFile', createMutation, true, true);
|
||||
};
|
||||
|
||||
export { load, handleUpload };
|
||||
|
||||
@@ -24,8 +24,7 @@ const load = parseGraphQLSchema => {
|
||||
|
||||
const callCloudCodeMutation = mutationWithClientMutationId({
|
||||
name: 'CallCloudCode',
|
||||
description:
|
||||
'The callCloudCode mutation can be used to invoke a cloud code function.',
|
||||
description: 'The callCloudCode mutation can be used to invoke a cloud code function.',
|
||||
inputFields: {
|
||||
functionName: {
|
||||
description: 'This is the function to be called.',
|
||||
@@ -38,8 +37,7 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
outputFields: {
|
||||
result: {
|
||||
description:
|
||||
'This is the result value of the cloud code function execution.',
|
||||
description: 'This is the result value of the cloud code function execution.',
|
||||
type: defaultGraphQLTypes.ANY,
|
||||
},
|
||||
},
|
||||
@@ -49,15 +47,17 @@ const load = parseGraphQLSchema => {
|
||||
const { config, auth, info } = context;
|
||||
|
||||
return {
|
||||
result: (await FunctionsRouter.handleCloudFunction({
|
||||
params: {
|
||||
functionName,
|
||||
},
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
body: params,
|
||||
})).response.result,
|
||||
result: (
|
||||
await FunctionsRouter.handleCloudFunction({
|
||||
params: {
|
||||
functionName,
|
||||
},
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
body: params,
|
||||
})
|
||||
).response.result,
|
||||
};
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
@@ -65,18 +65,9 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
callCloudCodeMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(callCloudCodeMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(callCloudCodeMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
'callCloudCode',
|
||||
callCloudCodeMutation,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation('callCloudCode', callCloudCodeMutation, true, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@ import { GraphQLNonNull } from 'graphql';
|
||||
import { fromGlobalId, mutationWithClientMutationId } from 'graphql-relay';
|
||||
import getFieldNames from 'graphql-list-fields';
|
||||
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
|
||||
import {
|
||||
extractKeysAndInclude,
|
||||
getParseClassMutationConfig,
|
||||
} from '../parseGraphQLUtils';
|
||||
import { extractKeysAndInclude, getParseClassMutationConfig } from '../parseGraphQLUtils';
|
||||
import * as objectsMutations from '../helpers/objectsMutations';
|
||||
import * as objectsQueries from '../helpers/objectsQueries';
|
||||
import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLController';
|
||||
@@ -18,17 +15,10 @@ const getOnlyRequiredFields = (
|
||||
includedFieldsString,
|
||||
nativeObjectFields
|
||||
) => {
|
||||
const includedFields = includedFieldsString
|
||||
? includedFieldsString.split(',')
|
||||
: [];
|
||||
const selectedFields = selectedFieldsString
|
||||
? selectedFieldsString.split(',')
|
||||
: [];
|
||||
const includedFields = includedFieldsString ? includedFieldsString.split(',') : [];
|
||||
const selectedFields = selectedFieldsString ? selectedFieldsString.split(',') : [];
|
||||
const missingFields = selectedFields
|
||||
.filter(
|
||||
field =>
|
||||
!nativeObjectFields.includes(field) || includedFields.includes(field)
|
||||
)
|
||||
.filter(field => !nativeObjectFields.includes(field) || includedFields.includes(field))
|
||||
.join(',');
|
||||
if (!missingFields.length) {
|
||||
return { needGet: false, keys: '' };
|
||||
@@ -37,15 +27,10 @@ const getOnlyRequiredFields = (
|
||||
}
|
||||
};
|
||||
|
||||
const load = function(
|
||||
parseGraphQLSchema,
|
||||
parseClass,
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) {
|
||||
const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLClassConfig) {
|
||||
const className = parseClass.className;
|
||||
const graphQLClassName = transformClassNameToGraphQL(className);
|
||||
const getGraphQLQueryName =
|
||||
graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
|
||||
const getGraphQLQueryName = graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
|
||||
|
||||
const {
|
||||
create: isCreateEnabled = true,
|
||||
@@ -63,24 +48,20 @@ const load = function(
|
||||
} = parseGraphQLSchema.parseClassTypes[className];
|
||||
|
||||
if (isCreateEnabled) {
|
||||
const createGraphQLMutationName =
|
||||
createAlias || `create${graphQLClassName}`;
|
||||
const createGraphQLMutationName = createAlias || `create${graphQLClassName}`;
|
||||
const createGraphQLMutation = mutationWithClientMutationId({
|
||||
name: `Create${graphQLClassName}`,
|
||||
description: `The ${createGraphQLMutationName} mutation can be used to create a new object of the ${graphQLClassName} class.`,
|
||||
inputFields: {
|
||||
fields: {
|
||||
description:
|
||||
'These are the fields that will be used to create the new object.',
|
||||
description: 'These are the fields that will be used to create the new object.',
|
||||
type: classGraphQLCreateType || defaultGraphQLTypes.OBJECT,
|
||||
},
|
||||
},
|
||||
outputFields: {
|
||||
[getGraphQLQueryName]: {
|
||||
description: 'This is the created object.',
|
||||
type: new GraphQLNonNull(
|
||||
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
|
||||
),
|
||||
type: new GraphQLNonNull(classGraphQLOutputType || defaultGraphQLTypes.OBJECT),
|
||||
},
|
||||
},
|
||||
mutateAndGetPayload: async (args, context, mutationInfo) => {
|
||||
@@ -106,12 +87,12 @@ const load = function(
|
||||
.filter(field => field.startsWith(`${getGraphQLQueryName}.`))
|
||||
.map(field => field.replace(`${getGraphQLQueryName}.`, ''));
|
||||
const { keys, include } = extractKeysAndInclude(selectedFields);
|
||||
const { keys: requiredKeys, needGet } = getOnlyRequiredFields(
|
||||
fields,
|
||||
keys,
|
||||
include,
|
||||
['id', 'objectId', 'createdAt', 'updatedAt']
|
||||
);
|
||||
const { keys: requiredKeys, needGet } = getOnlyRequiredFields(fields, keys, include, [
|
||||
'id',
|
||||
'objectId',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
]);
|
||||
const needToGetAllKeys = objectsQueries.needToGetAllKeys(
|
||||
parseClass.fields,
|
||||
keys,
|
||||
@@ -160,38 +141,29 @@ const load = function(
|
||||
});
|
||||
|
||||
if (
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
createGraphQLMutation.args.input.type.ofType
|
||||
) &&
|
||||
parseGraphQLSchema.addGraphQLType(createGraphQLMutation.args.input.type.ofType) &&
|
||||
parseGraphQLSchema.addGraphQLType(createGraphQLMutation.type)
|
||||
) {
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
createGraphQLMutationName,
|
||||
createGraphQLMutation
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation(createGraphQLMutationName, createGraphQLMutation);
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpdateEnabled) {
|
||||
const updateGraphQLMutationName =
|
||||
updateAlias || `update${graphQLClassName}`;
|
||||
const updateGraphQLMutationName = updateAlias || `update${graphQLClassName}`;
|
||||
const updateGraphQLMutation = mutationWithClientMutationId({
|
||||
name: `Update${graphQLClassName}`,
|
||||
description: `The ${updateGraphQLMutationName} mutation can be used to update an object of the ${graphQLClassName} class.`,
|
||||
inputFields: {
|
||||
id: defaultGraphQLTypes.GLOBAL_OR_OBJECT_ID_ATT,
|
||||
fields: {
|
||||
description:
|
||||
'These are the fields that will be used to update the object.',
|
||||
description: 'These are the fields that will be used to update the object.',
|
||||
type: classGraphQLUpdateType || defaultGraphQLTypes.OBJECT,
|
||||
},
|
||||
},
|
||||
outputFields: {
|
||||
[getGraphQLQueryName]: {
|
||||
description: 'This is the updated object.',
|
||||
type: new GraphQLNonNull(
|
||||
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
|
||||
),
|
||||
type: new GraphQLNonNull(classGraphQLOutputType || defaultGraphQLTypes.OBJECT),
|
||||
},
|
||||
},
|
||||
mutateAndGetPayload: async (args, context, mutationInfo) => {
|
||||
@@ -225,12 +197,11 @@ const load = function(
|
||||
.filter(field => field.startsWith(`${getGraphQLQueryName}.`))
|
||||
.map(field => field.replace(`${getGraphQLQueryName}.`, ''));
|
||||
const { keys, include } = extractKeysAndInclude(selectedFields);
|
||||
const { keys: requiredKeys, needGet } = getOnlyRequiredFields(
|
||||
fields,
|
||||
keys,
|
||||
include,
|
||||
['id', 'objectId', 'updatedAt']
|
||||
);
|
||||
const { keys: requiredKeys, needGet } = getOnlyRequiredFields(fields, keys, include, [
|
||||
'id',
|
||||
'objectId',
|
||||
'updatedAt',
|
||||
]);
|
||||
const needToGetAllKeys = objectsQueries.needToGetAllKeys(
|
||||
parseClass.fields,
|
||||
keys,
|
||||
@@ -279,21 +250,15 @@ const load = function(
|
||||
});
|
||||
|
||||
if (
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
updateGraphQLMutation.args.input.type.ofType
|
||||
) &&
|
||||
parseGraphQLSchema.addGraphQLType(updateGraphQLMutation.args.input.type.ofType) &&
|
||||
parseGraphQLSchema.addGraphQLType(updateGraphQLMutation.type)
|
||||
) {
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
updateGraphQLMutationName,
|
||||
updateGraphQLMutation
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation(updateGraphQLMutationName, updateGraphQLMutation);
|
||||
}
|
||||
}
|
||||
|
||||
if (isDestroyEnabled) {
|
||||
const deleteGraphQLMutationName =
|
||||
destroyAlias || `delete${graphQLClassName}`;
|
||||
const deleteGraphQLMutationName = destroyAlias || `delete${graphQLClassName}`;
|
||||
const deleteGraphQLMutation = mutationWithClientMutationId({
|
||||
name: `Delete${graphQLClassName}`,
|
||||
description: `The ${deleteGraphQLMutationName} mutation can be used to delete an object of the ${graphQLClassName} class.`,
|
||||
@@ -303,9 +268,7 @@ const load = function(
|
||||
outputFields: {
|
||||
[getGraphQLQueryName]: {
|
||||
description: 'This is the deleted object.',
|
||||
type: new GraphQLNonNull(
|
||||
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
|
||||
),
|
||||
type: new GraphQLNonNull(classGraphQLOutputType || defaultGraphQLTypes.OBJECT),
|
||||
},
|
||||
},
|
||||
mutateAndGetPayload: async (args, context, mutationInfo) => {
|
||||
@@ -324,11 +287,7 @@ const load = function(
|
||||
.map(field => field.replace(`${getGraphQLQueryName}.`, ''));
|
||||
const { keys, include } = extractKeysAndInclude(selectedFields);
|
||||
let optimizedObject = {};
|
||||
if (
|
||||
keys &&
|
||||
keys.split(',').filter(key => !['id', 'objectId'].includes(key))
|
||||
.length > 0
|
||||
) {
|
||||
if (keys && keys.split(',').filter(key => !['id', 'objectId'].includes(key)).length > 0) {
|
||||
optimizedObject = await objectsQueries.getObject(
|
||||
className,
|
||||
id,
|
||||
@@ -342,13 +301,7 @@ const load = function(
|
||||
parseGraphQLSchema.parseClasses
|
||||
);
|
||||
}
|
||||
await objectsMutations.deleteObject(
|
||||
className,
|
||||
id,
|
||||
config,
|
||||
auth,
|
||||
info
|
||||
);
|
||||
await objectsMutations.deleteObject(className, id, config, auth, info);
|
||||
return {
|
||||
[getGraphQLQueryName]: {
|
||||
objectId: id,
|
||||
@@ -362,15 +315,10 @@ const load = function(
|
||||
});
|
||||
|
||||
if (
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
deleteGraphQLMutation.args.input.type.ofType
|
||||
) &&
|
||||
parseGraphQLSchema.addGraphQLType(deleteGraphQLMutation.args.input.type.ofType) &&
|
||||
parseGraphQLSchema.addGraphQLType(deleteGraphQLMutation.type)
|
||||
) {
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
deleteGraphQLMutationName,
|
||||
deleteGraphQLMutation
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation(deleteGraphQLMutationName, deleteGraphQLMutation);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,20 +8,11 @@ import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLControlle
|
||||
import { transformClassNameToGraphQL } from '../transformers/className';
|
||||
import { extractKeysAndInclude } from '../parseGraphQLUtils';
|
||||
|
||||
const getParseClassQueryConfig = function (
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) {
|
||||
const getParseClassQueryConfig = function (parseClassConfig: ?ParseGraphQLClassConfig) {
|
||||
return (parseClassConfig && parseClassConfig.query) || {};
|
||||
};
|
||||
|
||||
const getQuery = async (
|
||||
parseClass,
|
||||
_source,
|
||||
args,
|
||||
context,
|
||||
queryInfo,
|
||||
parseClasses
|
||||
) => {
|
||||
const getQuery = async (parseClass, _source, args, context, queryInfo, parseClasses) => {
|
||||
let { id } = args;
|
||||
const { options } = args;
|
||||
const { readPreference, includeReadPreference } = options || {};
|
||||
@@ -50,11 +41,7 @@ const getQuery = async (
|
||||
);
|
||||
};
|
||||
|
||||
const load = function (
|
||||
parseGraphQLSchema,
|
||||
parseClass,
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) {
|
||||
const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLClassConfig) {
|
||||
const className = parseClass.className;
|
||||
const graphQLClassName = transformClassNameToGraphQL(className);
|
||||
const {
|
||||
@@ -71,8 +58,7 @@ const load = function (
|
||||
} = parseGraphQLSchema.parseClassTypes[className];
|
||||
|
||||
if (isGetEnabled) {
|
||||
const lowerCaseClassName =
|
||||
graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
|
||||
const lowerCaseClassName = graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
|
||||
|
||||
const getGraphQLQueryName = getAlias || lowerCaseClassName;
|
||||
|
||||
@@ -82,9 +68,7 @@ const load = function (
|
||||
id: defaultGraphQLTypes.GLOBAL_OR_OBJECT_ID_ATT,
|
||||
options: defaultGraphQLTypes.READ_OPTIONS_ATT,
|
||||
},
|
||||
type: new GraphQLNonNull(
|
||||
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
|
||||
),
|
||||
type: new GraphQLNonNull(classGraphQLOutputType || defaultGraphQLTypes.OBJECT),
|
||||
async resolve(_source, args, context, queryInfo) {
|
||||
try {
|
||||
return await getQuery(
|
||||
@@ -103,41 +87,25 @@ const load = function (
|
||||
}
|
||||
|
||||
if (isFindEnabled) {
|
||||
const lowerCaseClassName =
|
||||
graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
|
||||
const lowerCaseClassName = graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
|
||||
|
||||
const findGraphQLQueryName = findAlias || pluralize(lowerCaseClassName);
|
||||
|
||||
parseGraphQLSchema.addGraphQLQuery(findGraphQLQueryName, {
|
||||
description: `The ${findGraphQLQueryName} query can be used to find objects of the ${graphQLClassName} class.`,
|
||||
args: classGraphQLFindArgs,
|
||||
type: new GraphQLNonNull(
|
||||
classGraphQLFindResultType || defaultGraphQLTypes.OBJECT
|
||||
),
|
||||
type: new GraphQLNonNull(classGraphQLFindResultType || defaultGraphQLTypes.OBJECT),
|
||||
async resolve(_source, args, context, queryInfo) {
|
||||
try {
|
||||
const {
|
||||
where,
|
||||
order,
|
||||
skip,
|
||||
first,
|
||||
after,
|
||||
last,
|
||||
before,
|
||||
options,
|
||||
} = args;
|
||||
const {
|
||||
readPreference,
|
||||
includeReadPreference,
|
||||
subqueryReadPreference,
|
||||
} = options || {};
|
||||
const { where, order, skip, first, after, last, before, options } = args;
|
||||
const { readPreference, includeReadPreference, subqueryReadPreference } = options || {};
|
||||
const { config, auth, info } = context;
|
||||
const selectedFields = getFieldNames(queryInfo);
|
||||
|
||||
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(',');
|
||||
|
||||
|
||||
@@ -8,11 +8,7 @@ import {
|
||||
GraphQLBoolean,
|
||||
GraphQLEnumType,
|
||||
} from 'graphql';
|
||||
import {
|
||||
globalIdField,
|
||||
connectionArgs,
|
||||
connectionDefinitions,
|
||||
} from 'graphql-relay';
|
||||
import { globalIdField, connectionArgs, connectionDefinitions } from 'graphql-relay';
|
||||
import getFieldNames from 'graphql-list-fields';
|
||||
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
|
||||
import * as objectsQueries from '../helpers/objectsQueries';
|
||||
@@ -21,14 +17,9 @@ import { transformClassNameToGraphQL } from '../transformers/className';
|
||||
import { transformInputTypeToGraphQL } from '../transformers/inputType';
|
||||
import { transformOutputTypeToGraphQL } from '../transformers/outputType';
|
||||
import { transformConstraintTypeToGraphQL } from '../transformers/constraintType';
|
||||
import {
|
||||
extractKeysAndInclude,
|
||||
getParseClassMutationConfig,
|
||||
} from '../parseGraphQLUtils';
|
||||
import { extractKeysAndInclude, getParseClassMutationConfig } from '../parseGraphQLUtils';
|
||||
|
||||
const getParseClassTypeConfig = function (
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) {
|
||||
const getParseClassTypeConfig = function (parseClassConfig: ?ParseGraphQLClassConfig) {
|
||||
return (parseClassConfig && parseClassConfig.type) || {};
|
||||
};
|
||||
|
||||
@@ -51,22 +42,19 @@ const getInputFieldsAndConstraints = function (
|
||||
let classSortFields;
|
||||
|
||||
// All allowed customs fields
|
||||
const classCustomFields = classFields.filter((field) => {
|
||||
return (
|
||||
!Object.keys(defaultGraphQLTypes.PARSE_OBJECT_FIELDS).includes(field) &&
|
||||
field !== 'id'
|
||||
);
|
||||
const classCustomFields = classFields.filter(field => {
|
||||
return !Object.keys(defaultGraphQLTypes.PARSE_OBJECT_FIELDS).includes(field) && field !== 'id';
|
||||
});
|
||||
|
||||
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 +62,7 @@ const getInputFieldsAndConstraints = function (
|
||||
}
|
||||
|
||||
if (allowedOutputFields) {
|
||||
classOutputFields = classCustomFields.filter((field) => {
|
||||
classOutputFields = classCustomFields.filter(field => {
|
||||
return allowedOutputFields.includes(field);
|
||||
});
|
||||
} else {
|
||||
@@ -82,13 +70,11 @@ const getInputFieldsAndConstraints = function (
|
||||
}
|
||||
// Filters the "password" field from class _User
|
||||
if (parseClass.className === '_User') {
|
||||
classOutputFields = classOutputFields.filter(
|
||||
(outputField) => outputField !== 'password'
|
||||
);
|
||||
classOutputFields = classOutputFields.filter(outputField => outputField !== 'password');
|
||||
}
|
||||
|
||||
if (allowedConstraintFields) {
|
||||
classConstraintFields = classCustomFields.filter((field) => {
|
||||
classConstraintFields = classCustomFields.filter(field => {
|
||||
return allowedConstraintFields.includes(field);
|
||||
});
|
||||
} else {
|
||||
@@ -107,7 +93,7 @@ const getInputFieldsAndConstraints = function (
|
||||
});
|
||||
}
|
||||
} else {
|
||||
classSortFields = classFields.map((field) => {
|
||||
classSortFields = classFields.map(field => {
|
||||
return { field, asc: true, desc: true };
|
||||
});
|
||||
}
|
||||
@@ -121,11 +107,7 @@ const getInputFieldsAndConstraints = function (
|
||||
};
|
||||
};
|
||||
|
||||
const load = (
|
||||
parseGraphQLSchema,
|
||||
parseClass,
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) => {
|
||||
const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLClassConfig) => {
|
||||
const className = parseClass.className;
|
||||
const graphQLClassName = transformClassNameToGraphQL(className);
|
||||
const {
|
||||
@@ -159,8 +141,7 @@ const load = (
|
||||
[field]: {
|
||||
description: `This is the object ${field}.`,
|
||||
type:
|
||||
(className === '_User' &&
|
||||
(field === 'username' || field === 'password')) ||
|
||||
(className === '_User' && (field === 'username' || field === 'password')) ||
|
||||
parseClass.fields[field].required
|
||||
? new GraphQLNonNull(type)
|
||||
: type,
|
||||
@@ -175,9 +156,7 @@ const load = (
|
||||
}
|
||||
),
|
||||
});
|
||||
classGraphQLCreateType = parseGraphQLSchema.addGraphQLType(
|
||||
classGraphQLCreateType
|
||||
);
|
||||
classGraphQLCreateType = parseGraphQLSchema.addGraphQLType(classGraphQLCreateType);
|
||||
|
||||
const classGraphQLUpdateTypeName = `Update${graphQLClassName}FieldsInput`;
|
||||
let classGraphQLUpdateType = new GraphQLInputObjectType({
|
||||
@@ -208,9 +187,7 @@ const load = (
|
||||
}
|
||||
),
|
||||
});
|
||||
classGraphQLUpdateType = parseGraphQLSchema.addGraphQLType(
|
||||
classGraphQLUpdateType
|
||||
);
|
||||
classGraphQLUpdateType = parseGraphQLSchema.addGraphQLType(classGraphQLUpdateType);
|
||||
|
||||
const classGraphQLPointerTypeName = `${graphQLClassName}PointerInput`;
|
||||
let classGraphQLPointerType = new GraphQLInputObjectType({
|
||||
@@ -233,8 +210,7 @@ const load = (
|
||||
},
|
||||
});
|
||||
classGraphQLPointerType =
|
||||
parseGraphQLSchema.addGraphQLType(classGraphQLPointerType) ||
|
||||
defaultGraphQLTypes.OBJECT;
|
||||
parseGraphQLSchema.addGraphQLType(classGraphQLPointerType) || defaultGraphQLTypes.OBJECT;
|
||||
|
||||
const classGraphQLRelationTypeName = `${graphQLClassName}RelationInput`;
|
||||
let classGraphQLRelationType = new GraphQLInputObjectType({
|
||||
@@ -261,8 +237,7 @@ const load = (
|
||||
},
|
||||
});
|
||||
classGraphQLRelationType =
|
||||
parseGraphQLSchema.addGraphQLType(classGraphQLRelationType) ||
|
||||
defaultGraphQLTypes.OBJECT;
|
||||
parseGraphQLSchema.addGraphQLType(classGraphQLRelationType) || defaultGraphQLTypes.OBJECT;
|
||||
|
||||
const classGraphQLConstraintsTypeName = `${graphQLClassName}WhereInput`;
|
||||
let classGraphQLConstraintsType = new GraphQLInputObjectType({
|
||||
@@ -310,8 +285,7 @@ const load = (
|
||||
}),
|
||||
});
|
||||
classGraphQLConstraintsType =
|
||||
parseGraphQLSchema.addGraphQLType(classGraphQLConstraintsType) ||
|
||||
defaultGraphQLTypes.OBJECT;
|
||||
parseGraphQLSchema.addGraphQLType(classGraphQLConstraintsType) || defaultGraphQLTypes.OBJECT;
|
||||
|
||||
const classGraphQLRelationConstraintsTypeName = `${graphQLClassName}RelationWhereInput`;
|
||||
let classGraphQLRelationConstraintsType = new GraphQLInputObjectType({
|
||||
@@ -319,8 +293,7 @@ const load = (
|
||||
description: `The ${classGraphQLRelationConstraintsTypeName} input type is used in operations that involve filtering objects of ${graphQLClassName} class.`,
|
||||
fields: () => ({
|
||||
have: {
|
||||
description:
|
||||
'Run a relational/pointer query where at least one child object can match.',
|
||||
description: 'Run a relational/pointer query where at least one child object can match.',
|
||||
type: classGraphQLConstraintsType,
|
||||
},
|
||||
haveNot: {
|
||||
@@ -357,14 +330,11 @@ const load = (
|
||||
return updatedSortFields;
|
||||
}, {}),
|
||||
});
|
||||
classGraphQLOrderType = parseGraphQLSchema.addGraphQLType(
|
||||
classGraphQLOrderType
|
||||
);
|
||||
classGraphQLOrderType = parseGraphQLSchema.addGraphQLType(classGraphQLOrderType);
|
||||
|
||||
const classGraphQLFindArgs = {
|
||||
where: {
|
||||
description:
|
||||
'These are the conditions that the objects need to match in order to be found.',
|
||||
description: 'These are the conditions that the objects need to match in order to be found.',
|
||||
type: classGraphQLConstraintsType,
|
||||
},
|
||||
order: {
|
||||
@@ -378,12 +348,9 @@ const load = (
|
||||
options: defaultGraphQLTypes.READ_OPTIONS_ATT,
|
||||
};
|
||||
const classGraphQLOutputTypeName = `${graphQLClassName}`;
|
||||
const interfaces = [
|
||||
defaultGraphQLTypes.PARSE_OBJECT,
|
||||
parseGraphQLSchema.relayNodeInterface,
|
||||
];
|
||||
const interfaces = [defaultGraphQLTypes.PARSE_OBJECT, parseGraphQLSchema.relayNodeInterface];
|
||||
const parseObjectFields = {
|
||||
id: globalIdField(className, (obj) => obj.objectId),
|
||||
id: globalIdField(className, obj => obj.objectId),
|
||||
...defaultGraphQLTypes.PARSE_OBJECT_FIELDS,
|
||||
};
|
||||
const outputFields = () => {
|
||||
@@ -395,44 +362,26 @@ const load = (
|
||||
);
|
||||
if (parseClass.fields[field].type === 'Relation') {
|
||||
const targetParseClassTypes =
|
||||
parseGraphQLSchema.parseClassTypes[
|
||||
parseClass.fields[field].targetClass
|
||||
];
|
||||
const args = targetParseClassTypes
|
||||
? targetParseClassTypes.classGraphQLFindArgs
|
||||
: undefined;
|
||||
parseGraphQLSchema.parseClassTypes[parseClass.fields[field].targetClass];
|
||||
const args = targetParseClassTypes ? targetParseClassTypes.classGraphQLFindArgs : undefined;
|
||||
return {
|
||||
...fields,
|
||||
[field]: {
|
||||
description: `This is the object ${field}.`,
|
||||
args,
|
||||
type: parseClass.fields[field].required
|
||||
? new GraphQLNonNull(type)
|
||||
: type,
|
||||
type: parseClass.fields[field].required ? new GraphQLNonNull(type) : type,
|
||||
async resolve(source, args, context, queryInfo) {
|
||||
try {
|
||||
const {
|
||||
where,
|
||||
order,
|
||||
skip,
|
||||
first,
|
||||
after,
|
||||
last,
|
||||
before,
|
||||
options,
|
||||
} = args;
|
||||
const {
|
||||
readPreference,
|
||||
includeReadPreference,
|
||||
subqueryReadPreference,
|
||||
} = options || {};
|
||||
const { where, order, skip, first, after, last, before, options } = args;
|
||||
const { readPreference, includeReadPreference, subqueryReadPreference } =
|
||||
options || {};
|
||||
const { config, auth, info } = context;
|
||||
const selectedFields = getFieldNames(queryInfo);
|
||||
|
||||
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(',');
|
||||
|
||||
@@ -478,12 +427,10 @@ const load = (
|
||||
...fields,
|
||||
[field]: {
|
||||
description: `This is the object ${field}.`,
|
||||
type: parseClass.fields[field].required
|
||||
? new GraphQLNonNull(type)
|
||||
: type,
|
||||
type: parseClass.fields[field].required ? new GraphQLNonNull(type) : 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],
|
||||
}));
|
||||
@@ -498,17 +445,11 @@ const load = (
|
||||
...fields,
|
||||
[field]: {
|
||||
description: `Use Inline Fragment on Array to get results: https://graphql.org/learn/queries/#inline-fragments`,
|
||||
type: parseClass.fields[field].required
|
||||
? new GraphQLNonNull(type)
|
||||
: type,
|
||||
type: parseClass.fields[field].required ? new GraphQLNonNull(type) : type,
|
||||
async resolve(source) {
|
||||
if (!source[field]) return null;
|
||||
return source[field].map(async (elem) => {
|
||||
if (
|
||||
elem.className &&
|
||||
elem.objectId &&
|
||||
elem.__type === 'Object'
|
||||
) {
|
||||
return source[field].map(async elem => {
|
||||
if (elem.className && elem.objectId && elem.__type === 'Object') {
|
||||
return elem;
|
||||
} else {
|
||||
return { value: elem };
|
||||
@@ -522,9 +463,7 @@ const load = (
|
||||
...fields,
|
||||
[field]: {
|
||||
description: `This is the object ${field}.`,
|
||||
type: parseClass.fields[field].required
|
||||
? new GraphQLNonNull(type)
|
||||
: type,
|
||||
type: parseClass.fields[field].required ? new GraphQLNonNull(type) : type,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
@@ -538,9 +477,7 @@ const load = (
|
||||
interfaces,
|
||||
fields: outputFields,
|
||||
});
|
||||
classGraphQLOutputType = parseGraphQLSchema.addGraphQLType(
|
||||
classGraphQLOutputType
|
||||
);
|
||||
classGraphQLOutputType = parseGraphQLSchema.addGraphQLType(classGraphQLOutputType);
|
||||
|
||||
const { connectionType, edgeType } = connectionDefinitions({
|
||||
name: graphQLClassName,
|
||||
|
||||
@@ -21,15 +21,17 @@ const load = parseGraphQLSchema => {
|
||||
functionName = this.args.to;
|
||||
}
|
||||
|
||||
return (await FunctionsRouter.handleCloudFunction({
|
||||
params: {
|
||||
functionName,
|
||||
},
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
body: args,
|
||||
})).response.result;
|
||||
return (
|
||||
await FunctionsRouter.handleCloudFunction({
|
||||
params: {
|
||||
functionName,
|
||||
},
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
body: args,
|
||||
})
|
||||
).response.result;
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@ import Parse from 'parse/node';
|
||||
import { GraphQLNonNull } from 'graphql';
|
||||
import { mutationWithClientMutationId } from 'graphql-relay';
|
||||
import * as schemaTypes from './schemaTypes';
|
||||
import {
|
||||
transformToParse,
|
||||
transformToGraphQL,
|
||||
} from '../transformers/schemaFields';
|
||||
import { transformToParse, transformToGraphQL } from '../transformers/schemaFields';
|
||||
import { enforceMasterKeyAccess } from '../parseGraphQLUtils';
|
||||
import { getClass } from './schemaQueries';
|
||||
|
||||
@@ -42,10 +39,7 @@ const load = parseGraphQLSchema => {
|
||||
}
|
||||
|
||||
const schema = await config.database.loadSchema({ clearCache: true });
|
||||
const parseClass = await schema.addClassIfNotExists(
|
||||
name,
|
||||
transformToParse(schemaFields)
|
||||
);
|
||||
const parseClass = await schema.addClassIfNotExists(name, transformToParse(schemaFields));
|
||||
return {
|
||||
class: {
|
||||
name: parseClass.className,
|
||||
@@ -58,18 +52,9 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
createClassMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(createClassMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(createClassMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
'createClass',
|
||||
createClassMutation,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation('createClass', createClassMutation, true, true);
|
||||
|
||||
const updateClassMutation = mutationWithClientMutationId({
|
||||
name: 'UpdateClass',
|
||||
@@ -123,23 +108,13 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
updateClassMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(updateClassMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(updateClassMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
'updateClass',
|
||||
updateClassMutation,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation('updateClass', updateClassMutation, true, true);
|
||||
|
||||
const deleteClassMutation = mutationWithClientMutationId({
|
||||
name: 'DeleteClass',
|
||||
description:
|
||||
'The deleteClass mutation can be used to delete an existing object class.',
|
||||
description: 'The deleteClass mutation can be used to delete an existing object class.',
|
||||
inputFields: {
|
||||
name: schemaTypes.CLASS_NAME_ATT,
|
||||
},
|
||||
@@ -178,18 +153,9 @@ const load = parseGraphQLSchema => {
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.addGraphQLType(
|
||||
deleteClassMutation.args.input.type.ofType,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLType(deleteClassMutation.args.input.type.ofType, true, true);
|
||||
parseGraphQLSchema.addGraphQLType(deleteClassMutation.type, true, true);
|
||||
parseGraphQLSchema.addGraphQLMutation(
|
||||
'deleteClass',
|
||||
deleteClassMutation,
|
||||
true,
|
||||
true
|
||||
);
|
||||
parseGraphQLSchema.addGraphQLMutation('deleteClass', deleteClassMutation, true, true);
|
||||
};
|
||||
|
||||
export { load };
|
||||
|
||||
@@ -9,15 +9,9 @@ const getClass = async (name, schema) => {
|
||||
return await schema.getOneSchema(name, true);
|
||||
} catch (e) {
|
||||
if (e === undefined) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_CLASS_NAME,
|
||||
`Class ${name} does not exist.`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${name} does not exist.`);
|
||||
} else {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INTERNAL_SERVER_ERROR,
|
||||
'Database adapter error.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Database adapter error.');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -26,8 +20,7 @@ const load = parseGraphQLSchema => {
|
||||
parseGraphQLSchema.addGraphQLQuery(
|
||||
'class',
|
||||
{
|
||||
description:
|
||||
'The class query can be used to retrieve an existing object class.',
|
||||
description: 'The class query can be used to retrieve an existing object class.',
|
||||
args: {
|
||||
name: schemaTypes.CLASS_NAME_ATT,
|
||||
},
|
||||
@@ -57,11 +50,8 @@ const load = parseGraphQLSchema => {
|
||||
parseGraphQLSchema.addGraphQLQuery(
|
||||
'classes',
|
||||
{
|
||||
description:
|
||||
'The classes query can be used to retrieve the existing object classes.',
|
||||
type: new GraphQLNonNull(
|
||||
new GraphQLList(new GraphQLNonNull(schemaTypes.CLASS))
|
||||
),
|
||||
description: 'The classes query can be used to retrieve the existing object classes.',
|
||||
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(schemaTypes.CLASS))),
|
||||
resolve: async (_source, _args, context) => {
|
||||
try {
|
||||
const { config, auth } = context;
|
||||
|
||||
@@ -14,8 +14,7 @@ const SCHEMA_FIELD_NAME_ATT = {
|
||||
|
||||
const SCHEMA_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
name: 'SchemaFieldInput',
|
||||
description:
|
||||
'The SchemaFieldInput is used to specify a field of an object class schema.',
|
||||
description: 'The SchemaFieldInput is used to specify a field of an object class schema.',
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
},
|
||||
@@ -57,8 +56,7 @@ const SCHEMA_STRING_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_STRING_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaStringField',
|
||||
description:
|
||||
'The SchemaStringField is used to return information of a String field.',
|
||||
description: 'The SchemaStringField is used to return information of a String field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -76,8 +74,7 @@ const SCHEMA_NUMBER_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_NUMBER_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaNumberField',
|
||||
description:
|
||||
'The SchemaNumberField is used to return information of a Number field.',
|
||||
description: 'The SchemaNumberField is used to return information of a Number field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -95,8 +92,7 @@ const SCHEMA_BOOLEAN_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_BOOLEAN_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaBooleanField',
|
||||
description:
|
||||
'The SchemaBooleanField is used to return information of a Boolean field.',
|
||||
description: 'The SchemaBooleanField is used to return information of a Boolean field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -114,8 +110,7 @@ const SCHEMA_ARRAY_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_ARRAY_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaArrayField',
|
||||
description:
|
||||
'The SchemaArrayField is used to return information of an Array field.',
|
||||
description: 'The SchemaArrayField is used to return information of an Array field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -133,8 +128,7 @@ const SCHEMA_OBJECT_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_OBJECT_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaObjectField',
|
||||
description:
|
||||
'The SchemaObjectField is used to return information of an Object field.',
|
||||
description: 'The SchemaObjectField is used to return information of an Object field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -152,8 +146,7 @@ const SCHEMA_DATE_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_DATE_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaDateField',
|
||||
description:
|
||||
'The SchemaDateField is used to return information of a Date field.',
|
||||
description: 'The SchemaDateField is used to return information of a Date field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -171,8 +164,7 @@ const SCHEMA_FILE_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_FILE_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaFileField',
|
||||
description:
|
||||
'The SchemaFileField is used to return information of a File field.',
|
||||
description: 'The SchemaFileField is used to return information of a File field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -190,8 +182,7 @@ const SCHEMA_GEO_POINT_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_GEO_POINT_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaGeoPointField',
|
||||
description:
|
||||
'The SchemaGeoPointField is used to return information of a Geo Point field.',
|
||||
description: 'The SchemaGeoPointField is used to return information of a Geo Point field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -209,8 +200,7 @@ const SCHEMA_POLYGON_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_POLYGON_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaPolygonField',
|
||||
description:
|
||||
'The SchemaPolygonField is used to return information of a Polygon field.',
|
||||
description: 'The SchemaPolygonField is used to return information of a Polygon field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -228,8 +218,7 @@ const SCHEMA_BYTES_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_BYTES_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaBytesField',
|
||||
description:
|
||||
'The SchemaBytesField is used to return information of a Bytes field.',
|
||||
description: 'The SchemaBytesField is used to return information of a Bytes field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -253,8 +242,7 @@ const SCHEMA_POINTER_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_POINTER_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaPointerField',
|
||||
description:
|
||||
'The SchemaPointerField is used to return information of a Pointer field.',
|
||||
description: 'The SchemaPointerField is used to return information of a Pointer field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -274,8 +262,7 @@ const SCHEMA_RELATION_FIELD_INPUT = new GraphQLInputObjectType({
|
||||
|
||||
const SCHEMA_RELATION_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaRelationField',
|
||||
description:
|
||||
'The SchemaRelationField is used to return information of a Relation field.',
|
||||
description: 'The SchemaRelationField is used to return information of a Relation field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -285,8 +272,7 @@ const SCHEMA_RELATION_FIELD = new GraphQLObjectType({
|
||||
|
||||
const SCHEMA_ACL_FIELD = new GraphQLObjectType({
|
||||
name: 'SchemaACLField',
|
||||
description:
|
||||
'The SchemaACLField is used to return information of an ACL field.',
|
||||
description: 'The SchemaACLField is used to return information of an ACL field.',
|
||||
interfaces: [SCHEMA_FIELD],
|
||||
fields: {
|
||||
name: SCHEMA_FIELD_NAME_ATT,
|
||||
@@ -298,28 +284,23 @@ const SCHEMA_FIELDS_INPUT = new GraphQLInputObjectType({
|
||||
description: `The CreateClassSchemaInput type is used to specify the schema for a new object class to be created.`,
|
||||
fields: {
|
||||
addStrings: {
|
||||
description:
|
||||
'These are the String fields to be added to the class schema.',
|
||||
description: 'These are the String fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_STRING_FIELD_INPUT)),
|
||||
},
|
||||
addNumbers: {
|
||||
description:
|
||||
'These are the Number fields to be added to the class schema.',
|
||||
description: 'These are the Number fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_NUMBER_FIELD_INPUT)),
|
||||
},
|
||||
addBooleans: {
|
||||
description:
|
||||
'These are the Boolean fields to be added to the class schema.',
|
||||
description: 'These are the Boolean fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_BOOLEAN_FIELD_INPUT)),
|
||||
},
|
||||
addArrays: {
|
||||
description:
|
||||
'These are the Array fields to be added to the class schema.',
|
||||
description: 'These are the Array fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_ARRAY_FIELD_INPUT)),
|
||||
},
|
||||
addObjects: {
|
||||
description:
|
||||
'These are the Object fields to be added to the class schema.',
|
||||
description: 'These are the Object fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_OBJECT_FIELD_INPUT)),
|
||||
},
|
||||
addDates: {
|
||||
@@ -336,23 +317,19 @@ const SCHEMA_FIELDS_INPUT = new GraphQLInputObjectType({
|
||||
type: SCHEMA_GEO_POINT_FIELD_INPUT,
|
||||
},
|
||||
addPolygons: {
|
||||
description:
|
||||
'These are the Polygon fields to be added to the class schema.',
|
||||
description: 'These are the Polygon fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_POLYGON_FIELD_INPUT)),
|
||||
},
|
||||
addBytes: {
|
||||
description:
|
||||
'These are the Bytes fields to be added to the class schema.',
|
||||
description: 'These are the Bytes fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_BYTES_FIELD_INPUT)),
|
||||
},
|
||||
addPointers: {
|
||||
description:
|
||||
'These are the Pointer fields to be added to the class schema.',
|
||||
description: 'These are the Pointer fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_POINTER_FIELD_INPUT)),
|
||||
},
|
||||
addRelations: {
|
||||
description:
|
||||
'These are the Relation fields to be added to the class schema.',
|
||||
description: 'These are the Relation fields to be added to the class schema.',
|
||||
type: new GraphQLList(new GraphQLNonNull(SCHEMA_RELATION_FIELD_INPUT)),
|
||||
},
|
||||
remove: {
|
||||
@@ -374,9 +351,7 @@ const CLASS = new GraphQLObjectType({
|
||||
name: CLASS_NAME_ATT,
|
||||
schemaFields: {
|
||||
description: "These are the schema's fields of the object class.",
|
||||
type: new GraphQLNonNull(
|
||||
new GraphQLList(new GraphQLNonNull(SCHEMA_FIELD))
|
||||
),
|
||||
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(SCHEMA_FIELD))),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -5,18 +5,10 @@ import rest from '../../rest';
|
||||
import { extractKeysAndInclude } from './parseClassTypes';
|
||||
import { Auth } from '../../Auth';
|
||||
|
||||
const getUserFromSessionToken = async (
|
||||
context,
|
||||
queryInfo,
|
||||
keysPrefix,
|
||||
userId
|
||||
) => {
|
||||
const getUserFromSessionToken = async (context, queryInfo, keysPrefix, userId) => {
|
||||
const { info, config } = context;
|
||||
if (!info || !info.sessionToken) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'Invalid session token'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Invalid session token');
|
||||
}
|
||||
const sessionToken = info.sessionToken;
|
||||
const selectedFields = getFieldNames(queryInfo)
|
||||
@@ -70,10 +62,7 @@ const getUserFromSessionToken = async (
|
||||
info.context
|
||||
);
|
||||
if (!response.results || response.results.length == 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'Invalid session token'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Invalid session token');
|
||||
} else {
|
||||
const user = response.results[0];
|
||||
return {
|
||||
@@ -91,17 +80,11 @@ const load = parseGraphQLSchema => {
|
||||
parseGraphQLSchema.addGraphQLQuery(
|
||||
'viewer',
|
||||
{
|
||||
description:
|
||||
'The viewer query can be used to return the current user data.',
|
||||
description: 'The viewer query can be used to return the current user data.',
|
||||
type: new GraphQLNonNull(parseGraphQLSchema.viewerType),
|
||||
async resolve(_source, _args, context, queryInfo) {
|
||||
try {
|
||||
return await getUserFromSessionToken(
|
||||
context,
|
||||
queryInfo,
|
||||
'user.',
|
||||
false
|
||||
);
|
||||
return await getUserFromSessionToken(context, queryInfo, 'user.', false);
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import * as defaultGraphQLTypes from '../loaders/defaultGraphQLTypes';
|
||||
|
||||
const transformConstraintTypeToGraphQL = (
|
||||
parseType,
|
||||
targetClass,
|
||||
parseClassTypes,
|
||||
fieldName
|
||||
) => {
|
||||
const transformConstraintTypeToGraphQL = (parseType, targetClass, parseClassTypes, fieldName) => {
|
||||
if (fieldName === 'id' || fieldName === 'objectId') {
|
||||
return defaultGraphQLTypes.ID_WHERE_INPUT;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import {
|
||||
GraphQLString,
|
||||
GraphQLFloat,
|
||||
GraphQLBoolean,
|
||||
GraphQLList,
|
||||
} from 'graphql';
|
||||
import { GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLList } from 'graphql';
|
||||
import * as defaultGraphQLTypes from '../loaders/defaultGraphQLTypes';
|
||||
|
||||
const transformInputTypeToGraphQL = (
|
||||
parseType,
|
||||
targetClass,
|
||||
parseClassTypes
|
||||
) => {
|
||||
const transformInputTypeToGraphQL = (parseType, targetClass, parseClassTypes) => {
|
||||
switch (parseType) {
|
||||
case 'String':
|
||||
return GraphQLString;
|
||||
|
||||
@@ -14,19 +14,13 @@ const transformTypes = async (
|
||||
classGraphQLUpdateType,
|
||||
config: { isCreateEnabled, isUpdateEnabled },
|
||||
} = parseGraphQLSchema.parseClassTypes[className];
|
||||
const parseClass = parseGraphQLSchema.parseClasses.find(
|
||||
(clazz) => clazz.className === className
|
||||
);
|
||||
const parseClass = parseGraphQLSchema.parseClasses.find(clazz => clazz.className === className);
|
||||
if (fields) {
|
||||
const classGraphQLCreateTypeFields =
|
||||
isCreateEnabled && classGraphQLCreateType
|
||||
? classGraphQLCreateType.getFields()
|
||||
: null;
|
||||
isCreateEnabled && classGraphQLCreateType ? classGraphQLCreateType.getFields() : null;
|
||||
const classGraphQLUpdateTypeFields =
|
||||
isUpdateEnabled && classGraphQLUpdateType
|
||||
? classGraphQLUpdateType.getFields()
|
||||
: null;
|
||||
const promises = Object.keys(fields).map(async (field) => {
|
||||
isUpdateEnabled && classGraphQLUpdateType ? classGraphQLUpdateType.getFields() : null;
|
||||
const promises = Object.keys(fields).map(async field => {
|
||||
let inputTypeField;
|
||||
if (inputType === 'create' && classGraphQLCreateTypeFields) {
|
||||
inputTypeField = classGraphQLCreateTypeFields[field];
|
||||
@@ -84,18 +78,15 @@ const transformers = {
|
||||
}
|
||||
throw new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'Invalid file upload.');
|
||||
},
|
||||
polygon: (value) => ({
|
||||
polygon: value => ({
|
||||
__type: 'Polygon',
|
||||
coordinates: value.map((geoPoint) => [
|
||||
geoPoint.latitude,
|
||||
geoPoint.longitude,
|
||||
]),
|
||||
coordinates: value.map(geoPoint => [geoPoint.latitude, geoPoint.longitude]),
|
||||
}),
|
||||
geoPoint: (value) => ({
|
||||
geoPoint: value => ({
|
||||
...value,
|
||||
__type: 'GeoPoint',
|
||||
}),
|
||||
ACL: (value) => {
|
||||
ACL: value => {
|
||||
const parseACL = {};
|
||||
if (value.public) {
|
||||
parseACL['*'] = {
|
||||
@@ -104,7 +95,7 @@ const transformers = {
|
||||
};
|
||||
}
|
||||
if (value.users) {
|
||||
value.users.forEach((rule) => {
|
||||
value.users.forEach(rule => {
|
||||
const globalIdObject = fromGlobalId(rule.userId);
|
||||
if (globalIdObject.type === '_User') {
|
||||
rule.userId = globalIdObject.id;
|
||||
@@ -116,7 +107,7 @@ const transformers = {
|
||||
});
|
||||
}
|
||||
if (value.roles) {
|
||||
value.roles.forEach((rule) => {
|
||||
value.roles.forEach(rule => {
|
||||
parseACL[`role:${rule.roleName}`] = {
|
||||
read: rule.read,
|
||||
write: rule.write,
|
||||
@@ -125,13 +116,7 @@ const transformers = {
|
||||
}
|
||||
return parseACL;
|
||||
},
|
||||
relation: async (
|
||||
targetClass,
|
||||
field,
|
||||
value,
|
||||
parseGraphQLSchema,
|
||||
{ config, auth, info }
|
||||
) => {
|
||||
relation: async (targetClass, field, value, parseGraphQLSchema, { config, auth, info }) => {
|
||||
if (Object.keys(value).length === 0)
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_POINTER,
|
||||
@@ -147,22 +132,16 @@ const transformers = {
|
||||
if (value.createAndAdd) {
|
||||
nestedObjectsToAdd = (
|
||||
await Promise.all(
|
||||
value.createAndAdd.map(async (input) => {
|
||||
value.createAndAdd.map(async input => {
|
||||
const parseFields = await transformTypes('create', input, {
|
||||
className: targetClass,
|
||||
parseGraphQLSchema,
|
||||
req: { config, auth, info },
|
||||
});
|
||||
return objectsMutations.createObject(
|
||||
targetClass,
|
||||
parseFields,
|
||||
config,
|
||||
auth,
|
||||
info
|
||||
);
|
||||
return objectsMutations.createObject(targetClass, parseFields, config, auth, info);
|
||||
})
|
||||
)
|
||||
).map((object) => ({
|
||||
).map(object => ({
|
||||
__type: 'Pointer',
|
||||
className: targetClass,
|
||||
objectId: object.objectId,
|
||||
@@ -171,7 +150,7 @@ const transformers = {
|
||||
|
||||
if (value.add || nestedObjectsToAdd.length > 0) {
|
||||
if (!value.add) value.add = [];
|
||||
value.add = value.add.map((input) => {
|
||||
value.add = value.add.map(input => {
|
||||
const globalIdObject = fromGlobalId(input);
|
||||
if (globalIdObject.type === targetClass) {
|
||||
input = globalIdObject.id;
|
||||
@@ -191,7 +170,7 @@ const transformers = {
|
||||
if (value.remove) {
|
||||
op.ops.push({
|
||||
__op: 'RemoveRelation',
|
||||
objects: value.remove.map((input) => {
|
||||
objects: value.remove.map(input => {
|
||||
const globalIdObject = fromGlobalId(input);
|
||||
if (globalIdObject.type === targetClass) {
|
||||
input = globalIdObject.id;
|
||||
@@ -206,13 +185,7 @@ const transformers = {
|
||||
}
|
||||
return op;
|
||||
},
|
||||
pointer: async (
|
||||
targetClass,
|
||||
field,
|
||||
value,
|
||||
parseGraphQLSchema,
|
||||
{ config, auth, info }
|
||||
) => {
|
||||
pointer: async (targetClass, field, value, parseGraphQLSchema, { config, auth, info }) => {
|
||||
if (Object.keys(value).length > 1 || Object.keys(value).length === 0)
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_POINTER,
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
import * as defaultGraphQLTypes from '../loaders/defaultGraphQLTypes';
|
||||
import {
|
||||
GraphQLString,
|
||||
GraphQLFloat,
|
||||
GraphQLBoolean,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
} from 'graphql';
|
||||
import { GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLList, GraphQLNonNull } from 'graphql';
|
||||
|
||||
const transformOutputTypeToGraphQL = (
|
||||
parseType,
|
||||
targetClass,
|
||||
parseClassTypes
|
||||
) => {
|
||||
const transformOutputTypeToGraphQL = (parseType, targetClass, parseClassTypes) => {
|
||||
switch (parseType) {
|
||||
case 'String':
|
||||
return GraphQLString;
|
||||
@@ -41,9 +31,7 @@ const transformOutputTypeToGraphQL = (
|
||||
parseClassTypes[targetClass] &&
|
||||
parseClassTypes[targetClass].classGraphQLFindResultType
|
||||
) {
|
||||
return new GraphQLNonNull(
|
||||
parseClassTypes[targetClass].classGraphQLFindResultType
|
||||
);
|
||||
return new GraphQLNonNull(parseClassTypes[targetClass].classGraphQLFindResultType);
|
||||
} else {
|
||||
return new GraphQLNonNull(defaultGraphQLTypes.OBJECT);
|
||||
}
|
||||
|
||||
@@ -51,9 +51,7 @@ const transformQueryConstraintInputToParse = (
|
||||
parentConstraints,
|
||||
parseClasses
|
||||
) => {
|
||||
const fields = parseClasses.find(
|
||||
parseClass => parseClass.className === className
|
||||
).fields;
|
||||
const fields = parseClasses.find(parseClass => parseClass.className === className).fields;
|
||||
if (parentFieldName === 'id' && className) {
|
||||
Object.keys(constraints).forEach(constraintName => {
|
||||
const constraintValue = constraints[constraintName];
|
||||
@@ -110,12 +108,7 @@ const transformQueryConstraintInputToParse = (
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
if (
|
||||
fieldValue.key &&
|
||||
fieldValue.value &&
|
||||
parentConstraints &&
|
||||
parentFieldName
|
||||
) {
|
||||
if (fieldValue.key && fieldValue.value && parentConstraints && parentFieldName) {
|
||||
delete parentConstraints[parentFieldName];
|
||||
parentConstraints[`${parentFieldName}.${fieldValue.key}`] = {
|
||||
...parentConstraints[`${parentFieldName}.${fieldValue.key}`],
|
||||
@@ -123,8 +116,7 @@ const transformQueryConstraintInputToParse = (
|
||||
};
|
||||
} else if (
|
||||
fields[parentFieldName] &&
|
||||
(fields[parentFieldName].type === 'Pointer' ||
|
||||
fields[parentFieldName].type === 'Relation')
|
||||
(fields[parentFieldName].type === 'Pointer' || fields[parentFieldName].type === 'Relation')
|
||||
) {
|
||||
const { targetClass } = fields[parentFieldName];
|
||||
if (fieldName === 'exists') {
|
||||
@@ -193,11 +185,7 @@ const transformQueryConstraintInputToParse = (
|
||||
}
|
||||
break;
|
||||
case 'box':
|
||||
if (
|
||||
typeof fieldValue === 'object' &&
|
||||
fieldValue.bottomLeft &&
|
||||
fieldValue.upperRight
|
||||
) {
|
||||
if (typeof fieldValue === 'object' && fieldValue.bottomLeft && fieldValue.upperRight) {
|
||||
fieldValue = [
|
||||
{
|
||||
__type: 'GeoPoint',
|
||||
@@ -221,11 +209,7 @@ const transformQueryConstraintInputToParse = (
|
||||
}
|
||||
break;
|
||||
case 'centerSphere':
|
||||
if (
|
||||
typeof fieldValue === 'object' &&
|
||||
fieldValue.center &&
|
||||
fieldValue.distance
|
||||
) {
|
||||
if (typeof fieldValue === 'object' && fieldValue.center && fieldValue.distance) {
|
||||
fieldValue = [
|
||||
{
|
||||
__type: 'GeoPoint',
|
||||
|
||||
@@ -22,20 +22,12 @@ const transformToParse = (graphQLSchemaFields, existingFields) => {
|
||||
}
|
||||
if (
|
||||
graphQLSchemaFields.remove &&
|
||||
graphQLSchemaFields.remove.find(
|
||||
removeField => removeField.name === field.name
|
||||
)
|
||||
graphQLSchemaFields.remove.find(removeField => removeField.name === field.name)
|
||||
) {
|
||||
return parseSchemaFields;
|
||||
}
|
||||
if (
|
||||
parseSchemaFields[field.name] ||
|
||||
(existingFields && existingFields[field.name])
|
||||
) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_KEY_NAME,
|
||||
`Duplicated field name: ${field.name}`
|
||||
);
|
||||
if (parseSchemaFields[field.name] || (existingFields && existingFields[field.name])) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Duplicated field name: ${field.name}`);
|
||||
}
|
||||
if (type === 'Relation' || type === 'Pointer') {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user