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

Improve callCloudCode mutation to receive a CloudCodeFunction enum instead of a String #6029

Merged
merged 6 commits into from
Sep 9, 2019
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
29 changes: 28 additions & 1 deletion spec/ParseGraphQLSchema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('ParseGraphQLSchema', () => {
let databaseController;
let parseGraphQLController;
let parseGraphQLSchema;
const appId = 'test';

beforeAll(async () => {
parseServer = await global.reconfigureServer({
Expand All @@ -18,11 +19,12 @@ describe('ParseGraphQLSchema', () => {
databaseController,
parseGraphQLController,
log: defaultLogger,
appId,
});
});

describe('constructor', () => {
it('should require a parseGraphQLController, databaseController and a log instance', () => {
it('should require a parseGraphQLController, databaseController, a log instance, and the appId', () => {
expect(() => new ParseGraphQLSchema()).toThrow(
'You must provide a parseGraphQLController instance!'
);
Expand All @@ -36,6 +38,14 @@ describe('ParseGraphQLSchema', () => {
databaseController: {},
})
).toThrow('You must provide a log instance!');
expect(
() =>
new ParseGraphQLSchema({
parseGraphQLController: {},
databaseController: {},
log: {},
})
).toThrow('You must provide the appId!');
});
});

Expand Down Expand Up @@ -88,6 +98,7 @@ describe('ParseGraphQLSchema', () => {
databaseController,
parseGraphQLController,
log: defaultLogger,
appId,
});
await parseGraphQLSchema.load();
const parseClasses = parseGraphQLSchema.parseClasses;
Expand Down Expand Up @@ -134,6 +145,7 @@ describe('ParseGraphQLSchema', () => {
);
},
},
appId,
});
await parseGraphQLSchema.load();
const type = new GraphQLObjectType({ name: 'SomeClass' });
Expand All @@ -156,6 +168,7 @@ describe('ParseGraphQLSchema', () => {
fail('Should not warn');
},
},
appId,
});
await parseGraphQLSchema.load();
const type = new GraphQLObjectType({ name: 'SomeClass' });
Expand Down Expand Up @@ -184,6 +197,7 @@ describe('ParseGraphQLSchema', () => {
);
},
},
appId,
});
await parseGraphQLSchema.load();
expect(
Expand All @@ -203,6 +217,7 @@ describe('ParseGraphQLSchema', () => {
fail('Should not warn');
},
},
appId,
});
await parseGraphQLSchema.load();
const type = new GraphQLObjectType({ name: 'String' });
Expand All @@ -225,6 +240,7 @@ describe('ParseGraphQLSchema', () => {
);
},
},
appId,
});
await parseGraphQLSchema.load();
const field = {};
Expand All @@ -247,6 +263,7 @@ describe('ParseGraphQLSchema', () => {
fail('Should not warn');
},
},
appId,
});
await parseGraphQLSchema.load();
const field = {};
Expand Down Expand Up @@ -274,6 +291,7 @@ describe('ParseGraphQLSchema', () => {
);
},
},
appId,
});
await parseGraphQLSchema.load();
expect(parseGraphQLSchema.addGraphQLQuery('viewer', {})).toBeUndefined();
Expand All @@ -289,6 +307,7 @@ describe('ParseGraphQLSchema', () => {
fail('Should not warn');
},
},
appId,
});
await parseGraphQLSchema.load();
delete parseGraphQLSchema.graphQLQueries.viewer;
Expand All @@ -314,6 +333,7 @@ describe('ParseGraphQLSchema', () => {
);
},
},
appId,
});
await parseGraphQLSchema.load();
const field = {};
Expand All @@ -338,6 +358,7 @@ describe('ParseGraphQLSchema', () => {
fail('Should not warn');
},
},
appId,
});
await parseGraphQLSchema.load();
const field = {};
Expand Down Expand Up @@ -367,6 +388,7 @@ describe('ParseGraphQLSchema', () => {
);
},
},
appId,
});
await parseGraphQLSchema.load();
expect(
Expand All @@ -384,6 +406,7 @@ describe('ParseGraphQLSchema', () => {
fail('Should not warn');
},
},
appId,
});
await parseGraphQLSchema.load();
delete parseGraphQLSchema.graphQLMutations.signUp;
Expand All @@ -405,6 +428,7 @@ describe('ParseGraphQLSchema', () => {
fail('Should not warn');
},
},
appId,
});
expect(
parseGraphQLSchema
Expand Down Expand Up @@ -443,6 +467,7 @@ describe('ParseGraphQLSchema', () => {
databaseController,
parseGraphQLController,
log: defaultLogger,
appId,
});
await parseGraphQLSchema.databaseController.schemaCache.clear();
const schema1 = await parseGraphQLSchema.load();
Expand Down Expand Up @@ -476,6 +501,7 @@ describe('ParseGraphQLSchema', () => {
databaseController,
parseGraphQLController,
log: defaultLogger,
appId,
});
const car1 = new Parse.Object('Car');
await car1.save();
Expand Down Expand Up @@ -511,6 +537,7 @@ describe('ParseGraphQLSchema', () => {
databaseController,
parseGraphQLController,
log: defaultLogger,
appId,
});
const car = new Parse.Object('Car');
await car.save();
Expand Down
118 changes: 105 additions & 13 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5177,19 +5177,23 @@ describe('ParseGraphQLServer', () => {

describe('Functions Mutations', () => {
it('can be called', async () => {
Parse.Cloud.define('hello', async () => {
return 'Hello world!';
});
try {
Parse.Cloud.define('hello', async () => {
return 'Hello world!';
});

const result = await apolloClient.mutate({
mutation: gql`
mutation CallFunction {
callCloudCode(functionName: "hello")
}
`,
});
const result = await apolloClient.mutate({
mutation: gql`
mutation CallFunction {
callCloudCode(functionName: hello)
}
`,
});

expect(result.data.callCloudCode).toEqual('Hello world!');
expect(result.data.callCloudCode).toEqual('Hello world!');
} catch (e) {
handleError(e);
}
});

it('can throw errors', async () => {
Expand All @@ -5201,7 +5205,7 @@ describe('ParseGraphQLServer', () => {
await apolloClient.mutate({
mutation: gql`
mutation CallFunction {
callCloudCode(functionName: "hello")
callCloudCode(functionName: hello)
}
`,
});
Expand Down Expand Up @@ -5302,14 +5306,102 @@ describe('ParseGraphQLServer', () => {
apolloClient.mutate({
mutation: gql`
mutation CallFunction($params: Object) {
callCloudCode(functionName: "hello", params: $params)
callCloudCode(functionName: hello, params: $params)
}
`,
variables: {
params,
},
});
});

it('should list all functions in the enum type', async () => {
try {
Parse.Cloud.define('a', async () => {
return 'hello a';
});

Parse.Cloud.define('b', async () => {
return 'hello b';
});

Parse.Cloud.define('_underscored', async () => {
return 'hello _underscored';
});

Parse.Cloud.define('contains1Number', async () => {
return 'hello contains1Number';
});

const functionEnum = (await apolloClient.query({
query: gql`
query ObjectType {
__type(name: "CloudCodeFunction") {
kind
enumValues {
name
}
}
}
`,
})).data['__type'];
expect(functionEnum.kind).toEqual('ENUM');
expect(
functionEnum.enumValues.map(value => value.name).sort()
).toEqual(['_underscored', 'a', 'b', 'contains1Number']);
} catch (e) {
handleError(e);
}
});

it('should warn functions not matching GraphQL allowed names', async () => {
try {
spyOn(
parseGraphQLServer.parseGraphQLSchema.log,
'warn'
).and.callThrough();

Parse.Cloud.define('a', async () => {
return 'hello a';
});

Parse.Cloud.define('double-barrelled', async () => {
return 'hello b';
});

Parse.Cloud.define('1NumberInTheBeggning', async () => {
return 'hello contains1Number';
});

const functionEnum = (await apolloClient.query({
query: gql`
query ObjectType {
__type(name: "CloudCodeFunction") {
kind
enumValues {
name
}
}
}
`,
})).data['__type'];
expect(functionEnum.kind).toEqual('ENUM');
expect(
functionEnum.enumValues.map(value => value.name).sort()
).toEqual(['a']);
expect(
parseGraphQLServer.parseGraphQLSchema.log.warn.calls
.all()
.map(call => call.args[0])
.sort()
).toEqual([
'Function 1NumberInTheBeggning could not be added to the auto schema because GraphQL names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/.',
'Function double-barrelled could not be added to the auto schema because GraphQL names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/.',
]);
} catch (e) {
handleError(e);
}
});
});

describe('Data Types', () => {
Expand Down
Loading