Skip to content

GraphQL: Renaming Types/Inputs #5883

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

Merged
merged 16 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
576 changes: 271 additions & 305 deletions spec/ParseGraphQLServer.spec.js

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions src/GraphQL/loaders/defaultGraphQLTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,10 @@ const _options = {
type: GraphQLString,
};

const STRING_CONSTRAINT = new GraphQLInputObjectType({
name: 'StringConstraint',
const STRING_WHERE_INPUT = new GraphQLInputObjectType({
name: 'StringWhereInput',
description:
'The StringConstraint input type is used in operations that involve filtering objects by a field of type String.',
'The StringWhereInput input type is used in operations that involve filtering objects by a field of type String.',
fields: {
_eq: _eq(GraphQLString),
_ne: _ne(GraphQLString),
Expand All @@ -785,10 +785,10 @@ const STRING_CONSTRAINT = new GraphQLInputObjectType({
},
});

const NUMBER_CONSTRAINT = new GraphQLInputObjectType({
name: 'NumberConstraint',
const NUMBER_WHERE_INPUT = new GraphQLInputObjectType({
name: 'NumberWhereInput',
description:
'The NumberConstraint input type is used in operations that involve filtering objects by a field of type Number.',
'The NumberWhereInput input type is used in operations that involve filtering objects by a field of type Number.',
fields: {
_eq: _eq(GraphQLFloat),
_ne: _ne(GraphQLFloat),
Expand All @@ -804,10 +804,10 @@ const NUMBER_CONSTRAINT = new GraphQLInputObjectType({
},
});

const BOOLEAN_CONSTRAINT = new GraphQLInputObjectType({
name: 'BooleanConstraint',
const BOOLEAN_WHERE_INPUT = new GraphQLInputObjectType({
name: 'BooleanWhereInput',
description:
'The BooleanConstraint input type is used in operations that involve filtering objects by a field of type Boolean.',
'The BooleanWhereInput input type is used in operations that involve filtering objects by a field of type Boolean.',
fields: {
_eq: _eq(GraphQLBoolean),
_ne: _ne(GraphQLBoolean),
Expand All @@ -817,10 +817,10 @@ const BOOLEAN_CONSTRAINT = new GraphQLInputObjectType({
},
});

const ARRAY_CONSTRAINT = new GraphQLInputObjectType({
name: 'ArrayConstraint',
const ARRAY_WHERE_INPUT = new GraphQLInputObjectType({
name: 'ArrayWhereInput',
description:
'The ArrayConstraint input type is used in operations that involve filtering objects by a field of type Array.',
'The ArrayWhereInput input type is used in operations that involve filtering objects by a field of type Array.',
fields: {
_eq: _eq(ANY),
_ne: _ne(ANY),
Expand Down Expand Up @@ -861,10 +861,10 @@ const KEY_VALUE = new GraphQLInputObjectType({
},
});

const OBJECT_CONSTRAINT = new GraphQLInputObjectType({
name: 'ObjectConstraint',
const OBJECT_WHERE_INPUT = new GraphQLInputObjectType({
name: 'ObjectWhereInput',
description:
'The ObjectConstraint input type is used in operations that involve filtering result by a field of type Object.',
'The ObjectWhereInput input type is used in operations that involve filtering result by a field of type Object.',
fields: {
_eq: _eq(KEY_VALUE),
_ne: _ne(KEY_VALUE),
Expand All @@ -880,10 +880,10 @@ const OBJECT_CONSTRAINT = new GraphQLInputObjectType({
},
});

const DATE_CONSTRAINT = new GraphQLInputObjectType({
name: 'DateConstraint',
const DATE_WHERE_INPUT = new GraphQLInputObjectType({
name: 'DateWhereInput',
description:
'The DateConstraint input type is used in operations that involve filtering objects by a field of type Date.',
'The DateWhereInput input type is used in operations that involve filtering objects by a field of type Date.',
fields: {
_eq: _eq(DATE),
_ne: _ne(DATE),
Expand All @@ -899,10 +899,10 @@ const DATE_CONSTRAINT = new GraphQLInputObjectType({
},
});

const BYTES_CONSTRAINT = new GraphQLInputObjectType({
name: 'BytesConstraint',
const BYTES_WHERE_INPUT = new GraphQLInputObjectType({
name: 'BytesWhereInput',
description:
'The BytesConstraint input type is used in operations that involve filtering objects by a field of type Bytes.',
'The BytesWhereInput input type is used in operations that involve filtering objects by a field of type Bytes.',
fields: {
_eq: _eq(BYTES),
_ne: _ne(BYTES),
Expand All @@ -918,10 +918,10 @@ const BYTES_CONSTRAINT = new GraphQLInputObjectType({
},
});

const FILE_CONSTRAINT = new GraphQLInputObjectType({
name: 'FileConstraint',
const FILE_WHERE_INPUT = new GraphQLInputObjectType({
name: 'FileWhereInput',
description:
'The FILE_CONSTRAINT input type is used in operations that involve filtering objects by a field of type File.',
'The FileWhereInput input type is used in operations that involve filtering objects by a field of type File.',
fields: {
_eq: _eq(FILE),
_ne: _ne(FILE),
Expand All @@ -939,10 +939,10 @@ const FILE_CONSTRAINT = new GraphQLInputObjectType({
},
});

const GEO_POINT_CONSTRAINT = new GraphQLInputObjectType({
name: 'GeoPointConstraint',
const GEO_POINT_WHERE_INPUT = new GraphQLInputObjectType({
name: 'GeoPointWhereInput',
description:
'The GeoPointConstraint input type is used in operations that involve filtering objects by a field of type GeoPoint.',
'The GeoPointWhereInput input type is used in operations that involve filtering objects by a field of type GeoPoint.',
fields: {
_exists,
_nearSphere: {
Expand Down Expand Up @@ -983,10 +983,10 @@ const GEO_POINT_CONSTRAINT = new GraphQLInputObjectType({
},
});

const POLYGON_CONSTRAINT = new GraphQLInputObjectType({
name: 'PolygonConstraint',
const POLYGON_WHERE_INPUT = new GraphQLInputObjectType({
name: 'PolygonWhereInput',
description:
'The PolygonConstraint input type is used in operations that involve filtering objects by a field of type Polygon.',
'The PolygonWhereInput input type is used in operations that involve filtering objects by a field of type Polygon.',
fields: {
_exists,
_geoIntersects: {
Expand Down Expand Up @@ -1044,16 +1044,16 @@ const load = parseGraphQLSchema => {
parseGraphQLSchema.graphQLTypes.push(CENTER_SPHERE_OPERATOR);
parseGraphQLSchema.graphQLTypes.push(GEO_WITHIN_OPERATOR);
parseGraphQLSchema.graphQLTypes.push(GEO_INTERSECTS);
parseGraphQLSchema.graphQLTypes.push(STRING_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(NUMBER_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(BOOLEAN_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(ARRAY_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(OBJECT_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(DATE_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(BYTES_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(FILE_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(GEO_POINT_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(POLYGON_CONSTRAINT);
parseGraphQLSchema.graphQLTypes.push(STRING_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(NUMBER_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(BOOLEAN_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(ARRAY_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(OBJECT_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(DATE_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(BYTES_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(FILE_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(GEO_POINT_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(POLYGON_WHERE_INPUT);
parseGraphQLSchema.graphQLTypes.push(FIND_RESULT);
parseGraphQLSchema.graphQLTypes.push(SIGN_UP_RESULT);
};
Expand Down Expand Up @@ -1128,16 +1128,16 @@ export {
_dontSelect,
_regex,
_options,
STRING_CONSTRAINT,
NUMBER_CONSTRAINT,
BOOLEAN_CONSTRAINT,
ARRAY_CONSTRAINT,
OBJECT_CONSTRAINT,
DATE_CONSTRAINT,
BYTES_CONSTRAINT,
FILE_CONSTRAINT,
GEO_POINT_CONSTRAINT,
POLYGON_CONSTRAINT,
STRING_WHERE_INPUT,
NUMBER_WHERE_INPUT,
BOOLEAN_WHERE_INPUT,
ARRAY_WHERE_INPUT,
OBJECT_WHERE_INPUT,
DATE_WHERE_INPUT,
BYTES_WHERE_INPUT,
FILE_WHERE_INPUT,
GEO_POINT_WHERE_INPUT,
POLYGON_WHERE_INPUT,
FIND_RESULT,
SIGN_UP_RESULT,
load,
Expand Down
39 changes: 12 additions & 27 deletions src/GraphQL/loaders/objectsMutations.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
import { GraphQLNonNull, GraphQLBoolean, GraphQLObjectType } from 'graphql';
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
import rest from '../../rest';

const parseMap = {
_op: '__op',
};

const transformToParse = fields => {
if (!fields || typeof fields !== 'object') {
return;
}
Object.keys(fields).forEach(fieldName => {
const fieldValue = fields[fieldName];
if (parseMap[fieldName]) {
delete fields[fieldName];
fields[parseMap[fieldName]] = fieldValue;
}
if (typeof fieldValue === 'object') {
transformToParse(fieldValue);
}
});
};
import { transformMutationInputToParse } from '../transformers/mutation';
import { transformClassNameToParse } from '../transformers/className';

const createObject = async (className, fields, config, auth, info) => {
if (!fields) {
fields = {};
}

transformToParse(fields);
transformMutationInputToParse(fields);

return (await rest.create(config, auth, className, fields, info.clientSDK))
.response;
Expand All @@ -45,7 +27,7 @@ const updateObject = async (
fields = {};
}

transformToParse(fields);
transformMutationInputToParse(fields);

return (await rest.update(
config,
Expand All @@ -68,13 +50,14 @@ const load = parseGraphQLSchema => {
'The create mutation can be used to create a new object of a certain class.',
args: {
className: defaultGraphQLTypes.CLASS_NAME_ATT,
fields: defaultGraphQLTypes.FIELDS_ATT,
input: defaultGraphQLTypes.FIELDS_ATT,
},
type: new GraphQLNonNull(defaultGraphQLTypes.CREATE_RESULT),
async resolve(_source, args, context) {
try {
const { className, fields } = args;
const { className: graphQLClassName, input: fields } = args;
const { config, auth, info } = context;
const className = transformClassNameToParse(graphQLClassName);

return await createObject(className, fields, config, auth, info);
} catch (e) {
Expand All @@ -89,13 +72,14 @@ const load = parseGraphQLSchema => {
args: {
className: defaultGraphQLTypes.CLASS_NAME_ATT,
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
fields: defaultGraphQLTypes.FIELDS_ATT,
input: defaultGraphQLTypes.FIELDS_ATT,
},
type: new GraphQLNonNull(defaultGraphQLTypes.UPDATE_RESULT),
async resolve(_source, args, context) {
try {
const { className, objectId, fields } = args;
const { className: graphQLClassName, objectId, input: fields } = args;
const { config, auth, info } = context;
const className = transformClassNameToParse(graphQLClassName);

return await updateObject(
className,
Expand All @@ -121,8 +105,9 @@ const load = parseGraphQLSchema => {
type: new GraphQLNonNull(GraphQLBoolean),
async resolve(_source, args, context) {
try {
const { className, objectId } = args;
const { className: graphQLClassName, objectId } = args;
const { config, auth, info } = context;
const className = transformClassNameToParse(graphQLClassName);

return await deleteObject(className, objectId, config, auth, info);
} catch (e) {
Expand Down
Loading