Skip to content

Commit 0cdaab0

Browse files
committed
fix: call SchemaController.getAllClasses with wrong type parameter
1 parent 35ac4c3 commit 0cdaab0

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

spec/schemas.spec.js

+82
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,51 @@ describe('schemas', () => {
239239
});
240240
});
241241

242+
it('ensure refresh cache after creating a class', async done => {
243+
await request({
244+
url: 'http://localhost:8378/1/schemas',
245+
method: 'POST',
246+
headers: masterKeyHeaders,
247+
json: true,
248+
body: {
249+
className: 'A',
250+
},
251+
});
252+
const response = await request({
253+
url: 'http://localhost:8378/1/schemas',
254+
method: 'GET',
255+
headers: masterKeyHeaders,
256+
json: true,
257+
});
258+
const expected = {
259+
results: [
260+
userSchema,
261+
roleSchema,
262+
{
263+
className: 'A',
264+
fields: {
265+
//Default fields
266+
ACL: { type: 'ACL' },
267+
createdAt: { type: 'Date' },
268+
updatedAt: { type: 'Date' },
269+
objectId: { type: 'String' },
270+
},
271+
classLevelPermissions: defaultClassLevelPermissions,
272+
},
273+
],
274+
};
275+
expect(
276+
response.data.results
277+
.sort((s1, s2) => s1.className.localeCompare(s2.className))
278+
.map(s => {
279+
const withoutIndexes = Object.assign({}, s);
280+
delete withoutIndexes.indexes;
281+
return withoutIndexes;
282+
})
283+
).toEqual(expected.results.sort((s1, s2) => s1.className.localeCompare(s2.className)));
284+
done();
285+
});
286+
242287
it('responds with a single schema', done => {
243288
const obj = hasAllPODobject();
244289
obj.save().then(() => {
@@ -1507,6 +1552,43 @@ describe('schemas', () => {
15071552
});
15081553
});
15091554

1555+
it('ensure refresh cache after deleting a class', async done => {
1556+
await request({
1557+
url: 'http://localhost:8378/1/schemas',
1558+
method: 'POST',
1559+
headers: masterKeyHeaders,
1560+
json: true,
1561+
body: {
1562+
className: 'A',
1563+
},
1564+
});
1565+
await request({
1566+
method: 'DELETE',
1567+
url: 'http://localhost:8378/1/schemas/A',
1568+
headers: masterKeyHeaders,
1569+
json: true,
1570+
});
1571+
const response = await request({
1572+
url: 'http://localhost:8378/1/schemas',
1573+
method: 'GET',
1574+
headers: masterKeyHeaders,
1575+
json: true,
1576+
});
1577+
const expected = {
1578+
results: [userSchema, roleSchema],
1579+
};
1580+
expect(
1581+
response.data.results
1582+
.sort((s1, s2) => s1.className.localeCompare(s2.className))
1583+
.map(s => {
1584+
const withoutIndexes = Object.assign({}, s);
1585+
delete withoutIndexes.indexes;
1586+
return withoutIndexes;
1587+
})
1588+
).toEqual(expected.results.sort((s1, s2) => s1.className.localeCompare(s2.className)));
1589+
done();
1590+
});
1591+
15101592
it('deletes collections including join tables', done => {
15111593
const obj = new Parse.Object('MyClass');
15121594
obj.set('data', 'data');

src/GraphQL/loaders/schemaQueries.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const load = parseGraphQLSchema => {
6060
enforceMasterKeyAccess(auth);
6161

6262
const schema = await config.database.loadSchema({ clearCache: true });
63-
return (await schema.getAllClasses(true)).map(parseClass => ({
63+
return (await schema.getAllClasses({ clearCache: true })).map(parseClass => ({
6464
name: parseClass.className,
6565
schemaFields: transformToGraphQL(parseClass.fields),
6666
}));

src/Routers/SchemasRouter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function classNameMismatchResponse(bodyClass, pathClass) {
1616
function getAllSchemas(req) {
1717
return req.config.database
1818
.loadSchema({ clearCache: true })
19-
.then(schemaController => schemaController.getAllClasses(true))
19+
.then(schemaController => schemaController.getAllClasses({ clearCache: true }))
2020
.then(schemas => ({ response: { results: schemas } }));
2121
}
2222

0 commit comments

Comments
 (0)