Skip to content

Commit d3810c2

Browse files
omairvaiyanidavimacedo
authored andcommitted
GraphQL Configuration Options (#5782)
* add parse-graph-ql configuration for class schema customisation Not yet tested - essentially an RFC * refactor and add graphql router, controller and config cache * fix(GraphQLController): add missing check isEnabled * chore(GraphQLController): remove awaits from cache put * chore(GraphQLController): remove check for if its enabled * refactor(GraphQLController): only use cache if mounted * chore(GraphQLController): group all validation errors and throw at once * chore(GraphQLSchema): move transformations into controller validation * refactor(GraphQL): improve ctrl validation and fix schema usage of config * refactor(GraphQLSchema): remove code related to additional schema This code has been moved into a separate feature branch. * fix(GraphQLSchema): fix incorrect default return type for class configs * refactor(GraphQLSchema): update staleness check code to account for config * fix(GraphQLServer): fix regressed tests due to internal schema changes This will be followed up with a backwards compatability fix for the `ClassFields` issue to avoid breakages for our users * refactor: rename to ParseGraphQLController for consistency * fix(ParseGraphQLCtrl): numerous fixes for validity checking Also includes some minor code refactoring * chore(GraphQL): minor syntax cleanup * fix(SchemaController): add _GraphQLConfig to volatile classes * refactor(ParseGraphQLServer): return update config value in setGraphQLConfig * testing(ParseGraphQL): add test cases for new graphQLConfig * fix(GraphQLController): fix issue where config with multiple items was not being mapped to the db * fix(postgres): add _GraphQLConfig default schema on load fixes failing postgres tests * GraphQL @mock directive (#5836) * Add mock directive * Include tests for @mock directive * Fix existing tests due to the change from ClassFields to ClassCreateFields * fix(parseClassMutations): safer type transformation based on input type * fix(parseClassMutations): only define necessary input fields * fix(GraphQL): fix incorrect import paths
1 parent bbcc20f commit d3810c2

18 files changed

+2956
-290
lines changed

Diff for: spec/ParseGraphQLController.spec.js

+973
Large diffs are not rendered by default.

Diff for: spec/ParseGraphQLSchema.spec.js

+80-24
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,118 @@ const { ParseGraphQLSchema } = require('../lib/GraphQL/ParseGraphQLSchema');
44
describe('ParseGraphQLSchema', () => {
55
let parseServer;
66
let databaseController;
7+
let parseGraphQLController;
78
let parseGraphQLSchema;
89

910
beforeAll(async () => {
1011
parseServer = await global.reconfigureServer({
1112
schemaCacheTTL: 100,
1213
});
1314
databaseController = parseServer.config.databaseController;
14-
parseGraphQLSchema = new ParseGraphQLSchema(
15+
parseGraphQLController = parseServer.config.parseGraphQLController;
16+
parseGraphQLSchema = new ParseGraphQLSchema({
1517
databaseController,
16-
defaultLogger
17-
);
18+
parseGraphQLController,
19+
log: defaultLogger,
20+
});
1821
});
1922

2023
describe('constructor', () => {
21-
it('should require a databaseController and a log instance', () => {
24+
it('should require a parseGraphQLController, databaseController and a log instance', () => {
2225
expect(() => new ParseGraphQLSchema()).toThrow(
23-
'You must provide a databaseController instance!'
24-
);
25-
expect(() => new ParseGraphQLSchema({})).toThrow(
26-
'You must provide a log instance!'
26+
'You must provide a parseGraphQLController instance!'
2727
);
28-
expect(() => new ParseGraphQLSchema({}, {})).not.toThrow();
28+
expect(
29+
() => new ParseGraphQLSchema({ parseGraphQLController: {} })
30+
).toThrow('You must provide a databaseController instance!');
31+
expect(
32+
() =>
33+
new ParseGraphQLSchema({
34+
parseGraphQLController: {},
35+
databaseController: {},
36+
})
37+
).toThrow('You must provide a log instance!');
2938
});
3039
});
3140

3241
describe('load', () => {
3342
it('should cache schema', async () => {
3443
const graphQLSchema = await parseGraphQLSchema.load();
35-
expect(graphQLSchema).toBe(await parseGraphQLSchema.load());
44+
const updatedGraphQLSchema = await parseGraphQLSchema.load();
45+
expect(graphQLSchema).toBe(updatedGraphQLSchema);
3646
await new Promise(resolve => setTimeout(resolve, 200));
3747
expect(graphQLSchema).toBe(await parseGraphQLSchema.load());
3848
});
3949

4050
it('should load a brand new GraphQL Schema if Parse Schema changes', async () => {
4151
await parseGraphQLSchema.load();
4252
const parseClasses = parseGraphQLSchema.parseClasses;
43-
const parseClassesString = parseGraphQLSchema.parseClasses;
44-
const parseClassTypes = parseGraphQLSchema.parseClasses;
45-
const graphQLSchema = parseGraphQLSchema.parseClasses;
46-
const graphQLTypes = parseGraphQLSchema.parseClasses;
47-
const graphQLQueries = parseGraphQLSchema.parseClasses;
48-
const graphQLMutations = parseGraphQLSchema.parseClasses;
49-
const graphQLSubscriptions = parseGraphQLSchema.parseClasses;
53+
const parseClassesString = parseGraphQLSchema.parseClassesString;
54+
const parseClassTypes = parseGraphQLSchema.parseClassTypes;
55+
const graphQLSchema = parseGraphQLSchema.graphQLSchema;
56+
const graphQLTypes = parseGraphQLSchema.graphQLTypes;
57+
const graphQLQueries = parseGraphQLSchema.graphQLQueries;
58+
const graphQLMutations = parseGraphQLSchema.graphQLMutations;
59+
const graphQLSubscriptions = parseGraphQLSchema.graphQLSubscriptions;
5060
const newClassObject = new Parse.Object('NewClass');
5161
await newClassObject.save();
5262
await databaseController.schemaCache.clear();
5363
await new Promise(resolve => setTimeout(resolve, 200));
5464
await parseGraphQLSchema.load();
5565
expect(parseClasses).not.toBe(parseGraphQLSchema.parseClasses);
56-
expect(parseClassesString).not.toBe(parseGraphQLSchema.parseClasses);
57-
expect(parseClassTypes).not.toBe(parseGraphQLSchema.parseClasses);
58-
expect(graphQLSchema).not.toBe(parseGraphQLSchema.parseClasses);
59-
expect(graphQLTypes).not.toBe(parseGraphQLSchema.parseClasses);
60-
expect(graphQLQueries).not.toBe(parseGraphQLSchema.parseClasses);
61-
expect(graphQLMutations).not.toBe(parseGraphQLSchema.parseClasses);
62-
expect(graphQLSubscriptions).not.toBe(parseGraphQLSchema.parseClasses);
66+
expect(parseClassesString).not.toBe(
67+
parseGraphQLSchema.parseClassesString
68+
);
69+
expect(parseClassTypes).not.toBe(parseGraphQLSchema.parseClassTypes);
70+
expect(graphQLSchema).not.toBe(parseGraphQLSchema.graphQLSchema);
71+
expect(graphQLTypes).not.toBe(parseGraphQLSchema.graphQLTypes);
72+
expect(graphQLQueries).not.toBe(parseGraphQLSchema.graphQLQueries);
73+
expect(graphQLMutations).not.toBe(parseGraphQLSchema.graphQLMutations);
74+
expect(graphQLSubscriptions).not.toBe(
75+
parseGraphQLSchema.graphQLSubscriptions
76+
);
77+
});
78+
79+
it('should load a brand new GraphQL Schema if graphQLConfig changes', async () => {
80+
const parseGraphQLController = {
81+
graphQLConfig: { enabledForClasses: [] },
82+
getGraphQLConfig() {
83+
return this.graphQLConfig;
84+
},
85+
};
86+
const parseGraphQLSchema = new ParseGraphQLSchema({
87+
databaseController,
88+
parseGraphQLController,
89+
log: defaultLogger,
90+
});
91+
await parseGraphQLSchema.load();
92+
const parseClasses = parseGraphQLSchema.parseClasses;
93+
const parseClassesString = parseGraphQLSchema.parseClassesString;
94+
const parseClassTypes = parseGraphQLSchema.parseClassTypes;
95+
const graphQLSchema = parseGraphQLSchema.graphQLSchema;
96+
const graphQLTypes = parseGraphQLSchema.graphQLTypes;
97+
const graphQLQueries = parseGraphQLSchema.graphQLQueries;
98+
const graphQLMutations = parseGraphQLSchema.graphQLMutations;
99+
const graphQLSubscriptions = parseGraphQLSchema.graphQLSubscriptions;
100+
101+
parseGraphQLController.graphQLConfig = {
102+
enabledForClasses: ['_User'],
103+
};
104+
105+
await new Promise(resolve => setTimeout(resolve, 200));
106+
await parseGraphQLSchema.load();
107+
expect(parseClasses).not.toBe(parseGraphQLSchema.parseClasses);
108+
expect(parseClassesString).not.toBe(
109+
parseGraphQLSchema.parseClassesString
110+
);
111+
expect(parseClassTypes).not.toBe(parseGraphQLSchema.parseClassTypes);
112+
expect(graphQLSchema).not.toBe(parseGraphQLSchema.graphQLSchema);
113+
expect(graphQLTypes).not.toBe(parseGraphQLSchema.graphQLTypes);
114+
expect(graphQLQueries).not.toBe(parseGraphQLSchema.graphQLQueries);
115+
expect(graphQLMutations).not.toBe(parseGraphQLSchema.graphQLMutations);
116+
expect(graphQLSubscriptions).not.toBe(
117+
parseGraphQLSchema.graphQLSubscriptions
118+
);
63119
});
64120
});
65121
});

0 commit comments

Comments
 (0)