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
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
bbcc20fd60
commit
d3810c2eba
@@ -4,6 +4,7 @@ const { ParseGraphQLSchema } = require('../lib/GraphQL/ParseGraphQLSchema');
|
||||
describe('ParseGraphQLSchema', () => {
|
||||
let parseServer;
|
||||
let databaseController;
|
||||
let parseGraphQLController;
|
||||
let parseGraphQLSchema;
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -11,28 +12,37 @@ describe('ParseGraphQLSchema', () => {
|
||||
schemaCacheTTL: 100,
|
||||
});
|
||||
databaseController = parseServer.config.databaseController;
|
||||
parseGraphQLSchema = new ParseGraphQLSchema(
|
||||
parseGraphQLController = parseServer.config.parseGraphQLController;
|
||||
parseGraphQLSchema = new ParseGraphQLSchema({
|
||||
databaseController,
|
||||
defaultLogger
|
||||
);
|
||||
parseGraphQLController,
|
||||
log: defaultLogger,
|
||||
});
|
||||
});
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should require a databaseController and a log instance', () => {
|
||||
it('should require a parseGraphQLController, databaseController and a log instance', () => {
|
||||
expect(() => new ParseGraphQLSchema()).toThrow(
|
||||
'You must provide a databaseController instance!'
|
||||
'You must provide a parseGraphQLController instance!'
|
||||
);
|
||||
expect(() => new ParseGraphQLSchema({})).toThrow(
|
||||
'You must provide a log instance!'
|
||||
);
|
||||
expect(() => new ParseGraphQLSchema({}, {})).not.toThrow();
|
||||
expect(
|
||||
() => new ParseGraphQLSchema({ parseGraphQLController: {} })
|
||||
).toThrow('You must provide a databaseController instance!');
|
||||
expect(
|
||||
() =>
|
||||
new ParseGraphQLSchema({
|
||||
parseGraphQLController: {},
|
||||
databaseController: {},
|
||||
})
|
||||
).toThrow('You must provide a log instance!');
|
||||
});
|
||||
});
|
||||
|
||||
describe('load', () => {
|
||||
it('should cache schema', async () => {
|
||||
const graphQLSchema = await parseGraphQLSchema.load();
|
||||
expect(graphQLSchema).toBe(await parseGraphQLSchema.load());
|
||||
const updatedGraphQLSchema = await parseGraphQLSchema.load();
|
||||
expect(graphQLSchema).toBe(updatedGraphQLSchema);
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
expect(graphQLSchema).toBe(await parseGraphQLSchema.load());
|
||||
});
|
||||
@@ -40,26 +50,72 @@ describe('ParseGraphQLSchema', () => {
|
||||
it('should load a brand new GraphQL Schema if Parse Schema changes', async () => {
|
||||
await parseGraphQLSchema.load();
|
||||
const parseClasses = parseGraphQLSchema.parseClasses;
|
||||
const parseClassesString = parseGraphQLSchema.parseClasses;
|
||||
const parseClassTypes = parseGraphQLSchema.parseClasses;
|
||||
const graphQLSchema = parseGraphQLSchema.parseClasses;
|
||||
const graphQLTypes = parseGraphQLSchema.parseClasses;
|
||||
const graphQLQueries = parseGraphQLSchema.parseClasses;
|
||||
const graphQLMutations = parseGraphQLSchema.parseClasses;
|
||||
const graphQLSubscriptions = parseGraphQLSchema.parseClasses;
|
||||
const parseClassesString = parseGraphQLSchema.parseClassesString;
|
||||
const parseClassTypes = parseGraphQLSchema.parseClassTypes;
|
||||
const graphQLSchema = parseGraphQLSchema.graphQLSchema;
|
||||
const graphQLTypes = parseGraphQLSchema.graphQLTypes;
|
||||
const graphQLQueries = parseGraphQLSchema.graphQLQueries;
|
||||
const graphQLMutations = parseGraphQLSchema.graphQLMutations;
|
||||
const graphQLSubscriptions = parseGraphQLSchema.graphQLSubscriptions;
|
||||
const newClassObject = new Parse.Object('NewClass');
|
||||
await newClassObject.save();
|
||||
await databaseController.schemaCache.clear();
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
await parseGraphQLSchema.load();
|
||||
expect(parseClasses).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(parseClassesString).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(parseClassTypes).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(graphQLSchema).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(graphQLTypes).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(graphQLQueries).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(graphQLMutations).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(graphQLSubscriptions).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(parseClassesString).not.toBe(
|
||||
parseGraphQLSchema.parseClassesString
|
||||
);
|
||||
expect(parseClassTypes).not.toBe(parseGraphQLSchema.parseClassTypes);
|
||||
expect(graphQLSchema).not.toBe(parseGraphQLSchema.graphQLSchema);
|
||||
expect(graphQLTypes).not.toBe(parseGraphQLSchema.graphQLTypes);
|
||||
expect(graphQLQueries).not.toBe(parseGraphQLSchema.graphQLQueries);
|
||||
expect(graphQLMutations).not.toBe(parseGraphQLSchema.graphQLMutations);
|
||||
expect(graphQLSubscriptions).not.toBe(
|
||||
parseGraphQLSchema.graphQLSubscriptions
|
||||
);
|
||||
});
|
||||
|
||||
it('should load a brand new GraphQL Schema if graphQLConfig changes', async () => {
|
||||
const parseGraphQLController = {
|
||||
graphQLConfig: { enabledForClasses: [] },
|
||||
getGraphQLConfig() {
|
||||
return this.graphQLConfig;
|
||||
},
|
||||
};
|
||||
const parseGraphQLSchema = new ParseGraphQLSchema({
|
||||
databaseController,
|
||||
parseGraphQLController,
|
||||
log: defaultLogger,
|
||||
});
|
||||
await parseGraphQLSchema.load();
|
||||
const parseClasses = parseGraphQLSchema.parseClasses;
|
||||
const parseClassesString = parseGraphQLSchema.parseClassesString;
|
||||
const parseClassTypes = parseGraphQLSchema.parseClassTypes;
|
||||
const graphQLSchema = parseGraphQLSchema.graphQLSchema;
|
||||
const graphQLTypes = parseGraphQLSchema.graphQLTypes;
|
||||
const graphQLQueries = parseGraphQLSchema.graphQLQueries;
|
||||
const graphQLMutations = parseGraphQLSchema.graphQLMutations;
|
||||
const graphQLSubscriptions = parseGraphQLSchema.graphQLSubscriptions;
|
||||
|
||||
parseGraphQLController.graphQLConfig = {
|
||||
enabledForClasses: ['_User'],
|
||||
};
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
await parseGraphQLSchema.load();
|
||||
expect(parseClasses).not.toBe(parseGraphQLSchema.parseClasses);
|
||||
expect(parseClassesString).not.toBe(
|
||||
parseGraphQLSchema.parseClassesString
|
||||
);
|
||||
expect(parseClassTypes).not.toBe(parseGraphQLSchema.parseClassTypes);
|
||||
expect(graphQLSchema).not.toBe(parseGraphQLSchema.graphQLSchema);
|
||||
expect(graphQLTypes).not.toBe(parseGraphQLSchema.graphQLTypes);
|
||||
expect(graphQLQueries).not.toBe(parseGraphQLSchema.graphQLQueries);
|
||||
expect(graphQLMutations).not.toBe(parseGraphQLSchema.graphQLMutations);
|
||||
expect(graphQLSubscriptions).not.toBe(
|
||||
parseGraphQLSchema.graphQLSubscriptions
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user