GraphQL: Allow true GraphQL Schema Customization (#6360)
* Allow real GraphQL Schema via ParseServer.start * wip * working * tests ok * add tests about enum/input use case * Add async function based merge * Better naming * remove useless condition
This commit is contained in:
@@ -197,19 +197,60 @@ class ParseGraphQLSchema {
|
||||
if (this.graphQLCustomTypeDefs) {
|
||||
schemaDirectives.load(this);
|
||||
|
||||
this.graphQLSchema = mergeSchemas({
|
||||
schemas: [
|
||||
this.graphQLSchemaDirectivesDefinitions,
|
||||
this.graphQLAutoSchema,
|
||||
this.graphQLCustomTypeDefs,
|
||||
],
|
||||
mergeDirectives: true,
|
||||
});
|
||||
if (typeof this.graphQLCustomTypeDefs.getTypeMap === 'function') {
|
||||
const customGraphQLSchemaTypeMap = this.graphQLCustomTypeDefs.getTypeMap();
|
||||
Object.values(customGraphQLSchemaTypeMap).forEach(
|
||||
customGraphQLSchemaType => {
|
||||
if (
|
||||
!customGraphQLSchemaType ||
|
||||
!customGraphQLSchemaType.name ||
|
||||
customGraphQLSchemaType.name.startsWith('__')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const autoGraphQLSchemaType = this.graphQLAutoSchema.getType(
|
||||
customGraphQLSchemaType.name
|
||||
);
|
||||
if (autoGraphQLSchemaType) {
|
||||
autoGraphQLSchemaType._fields = {
|
||||
...autoGraphQLSchemaType._fields,
|
||||
...customGraphQLSchemaType._fields,
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
this.graphQLSchema = mergeSchemas({
|
||||
schemas: [
|
||||
this.graphQLSchemaDirectivesDefinitions,
|
||||
this.graphQLCustomTypeDefs,
|
||||
this.graphQLAutoSchema,
|
||||
],
|
||||
mergeDirectives: true,
|
||||
});
|
||||
} else if (typeof this.graphQLCustomTypeDefs === 'function') {
|
||||
this.graphQLSchema = await this.graphQLCustomTypeDefs({
|
||||
directivesDefinitionsSchema: this.graphQLSchemaDirectivesDefinitions,
|
||||
autoSchema: this.graphQLAutoSchema,
|
||||
mergeSchemas,
|
||||
});
|
||||
} else {
|
||||
this.graphQLSchema = mergeSchemas({
|
||||
schemas: [
|
||||
this.graphQLSchemaDirectivesDefinitions,
|
||||
this.graphQLAutoSchema,
|
||||
this.graphQLCustomTypeDefs,
|
||||
],
|
||||
mergeDirectives: true,
|
||||
});
|
||||
}
|
||||
|
||||
const graphQLSchemaTypeMap = this.graphQLSchema.getTypeMap();
|
||||
Object.keys(graphQLSchemaTypeMap).forEach(graphQLSchemaTypeName => {
|
||||
const graphQLSchemaType = graphQLSchemaTypeMap[graphQLSchemaTypeName];
|
||||
if (typeof graphQLSchemaType.getFields === 'function') {
|
||||
if (
|
||||
typeof graphQLSchemaType.getFields === 'function' &&
|
||||
this.graphQLCustomTypeDefs.definitions
|
||||
) {
|
||||
const graphQLCustomTypeDef = this.graphQLCustomTypeDefs.definitions.find(
|
||||
definition => definition.name.value === graphQLSchemaTypeName
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user