Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL Configuration Options #5782

Merged
merged 32 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a22dfe6
add parse-graph-ql configuration for class schema customisation
omairvaiyani Jul 8, 2019
5121073
refactor and add graphql router, controller and config cache
omairvaiyani Jul 11, 2019
51b74a4
Merge pull request #1 from omairvaiyani/graphql-config-modularisation
omairvaiyani Jul 11, 2019
1714528
fix(GraphQLController): add missing check isEnabled
omairvaiyani Jul 12, 2019
078e4ad
chore(GraphQLController): remove awaits from cache put
omairvaiyani Jul 12, 2019
8dba72e
chore(GraphQLController): remove check for if its enabled
omairvaiyani Jul 12, 2019
03400f7
refactor(GraphQLController): only use cache if mounted
omairvaiyani Jul 12, 2019
7334bd7
chore(GraphQLController): group all validation errors and throw at once
omairvaiyani Jul 12, 2019
b10d09b
chore(GraphQLSchema): move transformations into controller validation
omairvaiyani Jul 12, 2019
eef0b2b
refactor(GraphQL): improve ctrl validation and fix schema usage of co…
omairvaiyani Jul 12, 2019
206f8bc
refactor(GraphQLSchema): remove code related to additional schema
omairvaiyani Jul 12, 2019
a2fb12e
fix(GraphQLSchema): fix incorrect default return type for class configs
omairvaiyani Jul 12, 2019
5a7004d
refactor(GraphQLSchema): update staleness check code to account for c…
omairvaiyani Jul 12, 2019
eb7356c
fix(GraphQLServer): fix regressed tests due to internal schema changes
omairvaiyani Jul 13, 2019
c986320
Merge branch 'master' into graphql-config
omairvaiyani Jul 13, 2019
df8aa90
refactor: rename to ParseGraphQLController for consistency
omairvaiyani Jul 14, 2019
8f87292
fix(ParseGraphQLCtrl): numerous fixes for validity checking
omairvaiyani Jul 16, 2019
5ef997c
chore(GraphQL): minor syntax cleanup
omairvaiyani Jul 16, 2019
1f9a7a6
fix(SchemaController): add _GraphQLConfig to volatile classes
omairvaiyani Jul 16, 2019
543b319
refactor(ParseGraphQLServer): return update config value in setGraphQ…
omairvaiyani Jul 16, 2019
091e92f
testing(ParseGraphQL): add test cases for new graphQLConfig
omairvaiyani Jul 16, 2019
704e2fb
Merge branch 'graphql-config' of https://github.com/omairvaiyani/pars…
omairvaiyani Jul 16, 2019
a77d2c2
fix(GraphQLController): fix issue where config with multiple items wa…
omairvaiyani Jul 16, 2019
4a139ad
fix(postgres): add _GraphQLConfig default schema on load
omairvaiyani Jul 22, 2019
687c9d6
Merge branch 'master' into graphql-config-merge-master
omairvaiyani Jul 22, 2019
848ea77
Merge pull request #2 from omairvaiyani/graphql-config-merge-master
omairvaiyani Jul 22, 2019
2e0940c
GraphQL @mock directive (#5836)
davimacedo Jul 22, 2019
e60e798
Merge branch 'graphql-config' of github.com:omairvaiyani/parse-server…
davimacedo Jul 22, 2019
c9595ec
Fix existing tests due to the change from ClassFields to ClassCreateF…
davimacedo Jul 22, 2019
aedd4bc
fix(parseClassMutations): safer type transformation based on input type
omairvaiyani Jul 25, 2019
17e4a5a
fix(parseClassMutations): only define necessary input fields
omairvaiyani Jul 25, 2019
441dead
fix(GraphQL): fix incorrect import paths
omairvaiyani Jul 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
973 changes: 973 additions & 0 deletions spec/ParseGraphQLController.spec.js

Large diffs are not rendered by default.

104 changes: 80 additions & 24 deletions spec/ParseGraphQLSchema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,118 @@ const { ParseGraphQLSchema } = require('../lib/GraphQL/ParseGraphQLSchema');
describe('ParseGraphQLSchema', () => {
let parseServer;
let databaseController;
let parseGraphQLController;
let parseGraphQLSchema;

beforeAll(async () => {
parseServer = await global.reconfigureServer({
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!'
);
expect(() => new ParseGraphQLSchema({})).toThrow(
'You must provide a log instance!'
'You must provide a parseGraphQLController 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());
});

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
);
});
});
});
Loading