Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(GraphQL): Rename objectId to id #5985

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
881 changes: 417 additions & 464 deletions spec/ParseGraphQLServer.spec.js

Large diffs are not rendered by default.

33 changes: 6 additions & 27 deletions src/GraphQL/loaders/defaultGraphQLTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,7 @@ const POLYGON_INPUT = new GraphQLList(new GraphQLNonNull(GEO_POINT_INPUT));

const POLYGON = new GraphQLList(new GraphQLNonNull(GEO_POINT));

const RELATION_INPUT = new GraphQLInputObjectType({
name: 'RelationInput',
description: 'Object involved into a relation',
fields: {
objectId: {
description: 'Id of the object involved.',
type: new GraphQLNonNull(GraphQLID),
},
},
});
const OBJECT_ID = new GraphQLNonNull(GraphQLID);

const CLASS_NAME_ATT = {
description: 'This is the class name of the object.',
Expand All @@ -418,7 +409,8 @@ const FIELDS_ATT = {

const OBJECT_ID_ATT = {
description: 'This is the object id.',
type: new GraphQLNonNull(GraphQLID),
type: OBJECT_ID,
resolve: ({ objectId }) => objectId,
};

const CREATED_AT_ATT = {
Expand All @@ -441,7 +433,7 @@ const INPUT_FIELDS = {
};

const CREATE_RESULT_FIELDS = {
objectId: OBJECT_ID_ATT,
id: OBJECT_ID_ATT,
createdAt: CREATED_AT_ATT,
};

Expand Down Expand Up @@ -491,17 +483,6 @@ const INCLUDE_ATT = {
type: GraphQLString,
};

const POINTER_INPUT = new GraphQLInputObjectType({
name: 'PointerInput',
description: 'Allow to link an object to another object',
fields: {
objectId: {
description: 'Id of the object involved.',
type: new GraphQLNonNull(GraphQLID),
},
},
});

const READ_PREFERENCE = new GraphQLEnumType({
name: 'ReadPreference',
description:
Expand Down Expand Up @@ -1118,8 +1099,7 @@ const load = parseGraphQLSchema => {
parseGraphQLSchema.addGraphQLType(FIND_RESULT, true);
parseGraphQLSchema.addGraphQLType(SIGN_UP_RESULT, true);
parseGraphQLSchema.addGraphQLType(ELEMENT, true);
parseGraphQLSchema.addGraphQLType(RELATION_INPUT, true);
parseGraphQLSchema.addGraphQLType(POINTER_INPUT, true);
parseGraphQLSchema.addGraphQLType(OBJECT_ID, true);
};

export {
Expand All @@ -1145,6 +1125,7 @@ export {
GEO_POINT,
POLYGON_INPUT,
POLYGON,
OBJECT_ID,
CLASS_NAME_ATT,
FIELDS_ATT,
OBJECT_ID_ATT,
Expand Down Expand Up @@ -1206,8 +1187,6 @@ export {
SIGN_UP_RESULT,
ARRAY_RESULT,
ELEMENT,
POINTER_INPUT,
RELATION_INPUT,
load,
loadArrayResult,
};
29 changes: 15 additions & 14 deletions src/GraphQL/loaders/objectsMutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ const load = parseGraphQLSchema => {
const { className, fields } = args;
const { config, auth, info } = context;

return await createObject(className, fields, config, auth, info);
const object = await createObject(
className,
fields,
config,
auth,
info
);

return object;
} catch (e) {
parseGraphQLSchema.handleError(e);
}
Expand All @@ -71,23 +79,16 @@ const load = parseGraphQLSchema => {
'The update mutation can be used to update an object of a certain class.',
args: {
className: defaultGraphQLTypes.CLASS_NAME_ATT,
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
id: defaultGraphQLTypes.OBJECT_ID_ATT,
fields: defaultGraphQLTypes.FIELDS_ATT,
},
type: new GraphQLNonNull(defaultGraphQLTypes.UPDATE_RESULT),
async resolve(_source, args, context) {
try {
const { className, objectId, fields } = args;
const { className, id, fields } = args;
const { config, auth, info } = context;

return await updateObject(
className,
objectId,
fields,
config,
auth,
info
);
return await updateObject(className, id, fields, config, auth, info);
} catch (e) {
parseGraphQLSchema.handleError(e);
}
Expand All @@ -104,15 +105,15 @@ const load = parseGraphQLSchema => {
'The delete mutation can be used to delete an object of a certain class.',
args: {
className: defaultGraphQLTypes.CLASS_NAME_ATT,
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
id: defaultGraphQLTypes.OBJECT_ID_ATT,
},
type: new GraphQLNonNull(GraphQLBoolean),
async resolve(_source, args, context) {
try {
const { className, objectId } = args;
const { className, id } = args;
const { config, auth, info } = context;

return await deleteObject(className, objectId, config, auth, info);
return await deleteObject(className, id, config, auth, info);
} catch (e) {
parseGraphQLSchema.handleError(e);
}
Expand Down
26 changes: 17 additions & 9 deletions src/GraphQL/loaders/objectsQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const getObject = async (
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
}

const object = response.results[0];
if (className === '_User') {
delete response.results[0].sessionToken;
delete object.sessionToken;
}

return response.results[0];
return object;
};

const findObjects = async (
Expand All @@ -70,7 +70,6 @@ const findObjects = async (
if (!where) {
where = {};
}

transformQueryInputToParse(where);

const options = {};
Expand Down Expand Up @@ -136,7 +135,7 @@ const load = parseGraphQLSchema => {
'The get query can be used to get an object of a certain class by its objectId.',
args: {
className: defaultGraphQLTypes.CLASS_NAME_ATT,
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
id: defaultGraphQLTypes.OBJECT_ID_ATT,
keys: defaultGraphQLTypes.KEYS_ATT,
include: defaultGraphQLTypes.INCLUDE_ATT,
readPreference: defaultGraphQLTypes.READ_PREFERENCE_ATT,
Expand All @@ -147,7 +146,7 @@ const load = parseGraphQLSchema => {
try {
const {
className,
objectId,
id,
keys,
include,
readPreference,
Expand All @@ -156,9 +155,9 @@ const load = parseGraphQLSchema => {

const { config, auth, info } = context;

return await getObject(
const object = await getObject(
className,
objectId,
id,
keys,
include,
readPreference,
Expand All @@ -167,6 +166,10 @@ const load = parseGraphQLSchema => {
auth,
info
);
object.id = object.objectId;
delete object.objectId;

return object;
} catch (e) {
parseGraphQLSchema.handleError(e);
}
Expand Down Expand Up @@ -222,7 +225,7 @@ const load = parseGraphQLSchema => {
const { config, auth, info } = context;
const selectedFields = getFieldNames(queryInfo);

return await findObjects(
const objects = await findObjects(
className,
where,
order,
Expand All @@ -239,6 +242,11 @@ const load = parseGraphQLSchema => {
info,
selectedFields
);
objects.results.forEach(obj => {
obj.id = obj.objectId;
delete obj.objectId;
});
return objects;
} catch (e) {
parseGraphQLSchema.handleError(e);
}
Expand Down
26 changes: 13 additions & 13 deletions src/GraphQL/loaders/parseClassMutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const load = function(
fields,
keys,
include,
['objectId', 'createdAt', 'updatedAt']
['id', 'createdAt', 'updatedAt']
);
let optimizedObject = {};
if (needGet) {
Expand Down Expand Up @@ -125,7 +125,7 @@ const load = function(
parseGraphQLSchema.addGraphQLMutation(updateGraphQLMutationName, {
description: `The ${updateGraphQLMutationName} mutation can be used to update an object of the ${graphQLClassName} class.`,
args: {
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
id: defaultGraphQLTypes.OBJECT_ID_ATT,
fields: {
description: 'These are the fields used to update the object.',
type: classGraphQLUpdateType || defaultGraphQLTypes.OBJECT,
Expand All @@ -136,7 +136,7 @@ const load = function(
),
async resolve(_source, args, context, mutationInfo) {
try {
const { objectId, fields } = args;
const { id, fields } = args;
const { config, auth, info } = context;

const parseFields = await transformTypes('update', fields, {
Expand All @@ -147,7 +147,7 @@ const load = function(

const updatedObject = await objectsMutations.updateObject(
className,
objectId,
id,
parseFields,
config,
auth,
Expand All @@ -160,13 +160,13 @@ const load = function(
fields,
keys,
include,
['objectId', 'updatedAt']
['id', 'updatedAt']
);
let optimizedObject = {};
if (needGet) {
optimizedObject = await objectsQueries.getObject(
className,
objectId,
id,
requiredKeys,
include,
undefined,
Expand All @@ -177,7 +177,7 @@ const load = function(
);
}
return {
objectId: objectId,
id,
...updatedObject,
...fields,
...optimizedObject,
Expand All @@ -194,24 +194,24 @@ const load = function(
parseGraphQLSchema.addGraphQLMutation(deleteGraphQLMutationName, {
description: `The ${deleteGraphQLMutationName} mutation can be used to delete an object of the ${graphQLClassName} class.`,
args: {
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
id: defaultGraphQLTypes.OBJECT_ID_ATT,
},
type: new GraphQLNonNull(
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
),
async resolve(_source, args, context, mutationInfo) {
try {
const { objectId } = args;
const { id } = args;
const { config, auth, info } = context;
const selectedFields = getFieldNames(mutationInfo);
const { keys, include } = extractKeysAndInclude(selectedFields);

let optimizedObject = {};
const splitedKeys = keys.split(',');
if (splitedKeys.length > 1 || splitedKeys[0] !== 'objectId') {
if (splitedKeys.length > 1 || splitedKeys[0] !== 'id') {
optimizedObject = await objectsQueries.getObject(
className,
objectId,
id,
keys,
include,
undefined,
Expand All @@ -223,12 +223,12 @@ const load = function(
}
await objectsMutations.deleteObject(
className,
objectId,
id,
config,
auth,
info
);
return { objectId: objectId, ...optimizedObject };
return { id, ...optimizedObject };
} catch (e) {
parseGraphQLSchema.handleError(e);
}
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQL/loaders/parseClassQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const getParseClassQueryConfig = function(
};

const getQuery = async (className, _source, args, context, queryInfo) => {
const { objectId, readPreference, includeReadPreference } = args;
const { id, readPreference, includeReadPreference } = args;
const { config, auth, info } = context;
const selectedFields = getFieldNames(queryInfo);

const { keys, include } = extractKeysAndInclude(selectedFields);

return await objectsQueries.getObject(
className,
objectId,
id,
keys,
include,
readPreference,
Expand Down Expand Up @@ -57,7 +57,7 @@ const load = function(
parseGraphQLSchema.addGraphQLQuery(getGraphQLQueryName, {
description: `The ${getGraphQLQueryName} query can be used to get an object of the ${graphQLClassName} class by its id.`,
args: {
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
id: defaultGraphQLTypes.OBJECT_ID_ATT,
readPreference: defaultGraphQLTypes.READ_PREFERENCE_ATT,
includeReadPreference: defaultGraphQLTypes.INCLUDE_READ_PREFERENCE_ATT,
},
Expand Down
Loading