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
@@ -7,6 +7,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
let databaseController;
|
||||
let parseGraphQLController;
|
||||
let parseGraphQLSchema;
|
||||
const appId = 'test';
|
||||
|
||||
beforeAll(async () => {
|
||||
parseServer = await global.reconfigureServer({
|
||||
@@ -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!'
|
||||
);
|
||||
@@ -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!');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -88,6 +98,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
databaseController,
|
||||
parseGraphQLController,
|
||||
log: defaultLogger,
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const parseClasses = parseGraphQLSchema.parseClasses;
|
||||
@@ -134,6 +145,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const type = new GraphQLObjectType({ name: 'SomeClass' });
|
||||
@@ -156,6 +168,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
fail('Should not warn');
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const type = new GraphQLObjectType({ name: 'SomeClass' });
|
||||
@@ -184,6 +197,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
expect(
|
||||
@@ -203,6 +217,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
fail('Should not warn');
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const type = new GraphQLObjectType({ name: 'String' });
|
||||
@@ -225,6 +240,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const field = {};
|
||||
@@ -247,6 +263,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
fail('Should not warn');
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const field = {};
|
||||
@@ -274,6 +291,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
expect(parseGraphQLSchema.addGraphQLQuery('viewer', {})).toBeUndefined();
|
||||
@@ -289,6 +307,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
fail('Should not warn');
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
delete parseGraphQLSchema.graphQLQueries.viewer;
|
||||
@@ -314,6 +333,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const field = {};
|
||||
@@ -338,6 +358,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
fail('Should not warn');
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const field = {};
|
||||
@@ -367,6 +388,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
expect(
|
||||
@@ -384,6 +406,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
fail('Should not warn');
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
delete parseGraphQLSchema.graphQLMutations.signUp;
|
||||
@@ -405,6 +428,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
fail('Should not warn');
|
||||
},
|
||||
},
|
||||
appId,
|
||||
});
|
||||
expect(
|
||||
parseGraphQLSchema
|
||||
@@ -443,6 +467,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
databaseController,
|
||||
parseGraphQLController,
|
||||
log: defaultLogger,
|
||||
appId,
|
||||
});
|
||||
await parseGraphQLSchema.databaseController.schemaCache.clear();
|
||||
const schema1 = await parseGraphQLSchema.load();
|
||||
@@ -476,6 +501,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
databaseController,
|
||||
parseGraphQLController,
|
||||
log: defaultLogger,
|
||||
appId,
|
||||
});
|
||||
const car1 = new Parse.Object('Car');
|
||||
await car1.save();
|
||||
@@ -511,6 +537,7 @@ describe('ParseGraphQLSchema', () => {
|
||||
databaseController,
|
||||
parseGraphQLController,
|
||||
log: defaultLogger,
|
||||
appId,
|
||||
});
|
||||
const car = new Parse.Object('Car');
|
||||
await car.save();
|
||||
|
||||
@@ -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