Last active
April 7, 2020 14:27
-
-
Save craicoverflow/c8cdeb013b1e8d5fda1a416170be7a75 to your computer and use it in GitHub Desktop.
Hybvrid runtime services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function createModels(modelsDir: string, schema: GraphQLSchema, defaultDataProvider: GraphbackDataProvider, dbProviderOverrides: { [modelName: string]: GraphbackDataProvider } = {}, pubSub: PubSub): Promise<{ [serviceName: string]: CRUDService }> { | |
const models = require(modelsDir); | |
delete models.modelConfigs; | |
const services = {}; | |
for (const modelName of Object.keys(models)) { | |
const modelType = schema.getType(modelName) as GraphQLObjectType | |
const dbProvider = dbProviderOverrides[modelName] || defaultDataProvider | |
const modelService: GraphbackCRUDService = new models[modelName](modelType, dbProvider, { | |
pubSub, | |
...{ | |
name: [modelName], | |
pubSub: { | |
publishCreate: false, | |
publishUpdate: false, | |
publishDelete: false, | |
}, | |
} | |
}); | |
services[modelName] = modelService; | |
} | |
return services; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment