Skip to content

Instantly share code, notes, and snippets.

@craicoverflow
Last active April 7, 2020 14:27
Show Gist options
  • Save craicoverflow/c8cdeb013b1e8d5fda1a416170be7a75 to your computer and use it in GitHub Desktop.
Save craicoverflow/c8cdeb013b1e8d5fda1a416170be7a75 to your computer and use it in GitHub Desktop.
Hybvrid runtime services
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