Improve callCloudCode mutation to receive a CloudCodeFunction enum instead of a String (#6029)
* Add listing test * Improvements * Fixinf package.json * Fix package.json * Fix tests
This commit is contained in:
committed by
GitHub
parent
33d2b16476
commit
a754b883b2
@@ -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 () => {
|
||||
@@ -5201,7 +5205,7 @@ describe('ParseGraphQLServer', () => {
|
||||
await apolloClient.mutate({
|
||||
mutation: gql`
|
||||
mutation CallFunction {
|
||||
callCloudCode(functionName: "hello")
|
||||
callCloudCode(functionName: hello)
|
||||
}
|
||||
`,
|
||||
});
|
||||
@@ -5302,7 +5306,7 @@ describe('ParseGraphQLServer', () => {
|
||||
apolloClient.mutate({
|
||||
mutation: gql`
|
||||
mutation CallFunction($params: Object) {
|
||||
callCloudCode(functionName: "hello", params: $params)
|
||||
callCloudCode(functionName: hello, params: $params)
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
@@ -5310,6 +5314,94 @@ describe('ParseGraphQLServer', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
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', () => {
|
||||
|
||||
Reference in New Issue
Block a user