Skip to content

Commit d784a52

Browse files
committed
fix: call SchemaController.getAllClasses with wrong type parameter
1 parent 31960b5 commit d784a52

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

spec/schemas.spec.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,53 @@ describe('schemas', () => {
239239
});
240240
});
241241

242+
it('ensure refresh cache after creating a class', done => {
243+
request({
244+
url: 'http://localhost:8378/1/schemas',
245+
method: 'POST',
246+
headers: masterKeyHeaders,
247+
json: true,
248+
body: {
249+
className: 'A',
250+
},
251+
}).then(() => {
252+
request({
253+
url: 'http://localhost:8378/1/schemas',
254+
method: 'GET',
255+
headers: masterKeyHeaders,
256+
json: true,
257+
}).then(response => {
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+
});
287+
});
288+
242289
it('responds with a single schema', done => {
243290
const obj = hasAllPODobject();
244291
obj.save().then(() => {
@@ -1507,6 +1554,46 @@ describe('schemas', () => {
15071554
});
15081555
});
15091556

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

src/GraphQL/loaders/schemaQueries.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)