Created
April 7, 2020 14:11
-
-
Save craicoverflow/ed4b805e3d44b0504c631afd7dfdcc9a to your computer and use it in GitHub Desktop.
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); | |
const modelsConfig = { ...models.modelConfigs }; | |
delete models.modelConfigs; | |
const noteConfig = { | |
name: "Note", | |
pubSub: { | |
publishCreate: false, | |
publishUpdate: false, | |
publishDelete: false, | |
}, | |
} | |
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, | |
...noteConfig.pubSub | |
}); | |
services[modelName] = modelService; | |
} | |
return services; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment