Skip to content

Commit 757118f

Browse files
committed
Refactor config to separate objectql.config.ts file
Moved datasource and objects directory configuration from index.ts to a new objectql.config.ts file for better separation of concerns and maintainability. Updated index.ts to import and use the new config.
1 parent 00862f7 commit 757118f

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

examples/basic-usage/src/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
import { ObjectQL, ObjectConfig, UnifiedQuery } from '@objectql/core';
2-
import { MongoDriver } from '@objectql/driver-mongo';
32
import { createObjectQLRouter } from '@objectql/express';
43
import express from 'express';
54
import cors from 'cors';
65
import * as path from 'path';
6+
import config from './objectql.config';
77

88
const app = new ObjectQL({
9-
datasources: {
10-
default: new MongoDriver({
11-
url: process.env.MONGO_URL || 'mongodb://127.0.0.1:27017/objectql_example',
12-
dbName: 'objectql_example'
13-
})
14-
}
9+
datasources: config.datasources
1510
});
1611

1712
// Load objects from directory (includes .object.yml and .hook.js)
18-
const objectsDir = path.join(__dirname, 'objects');
19-
console.log(`Loading objects from ${objectsDir}...`);
20-
app.loadFromDirectory(objectsDir);
13+
console.log(`Loading objects from ${config.objectsDir}...`);
14+
app.loadFromDirectory(config.objectsDir);
2115

2216
const projectObj = app.getObject('projects');
2317
if (!projectObj) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MongoDriver } from '@objectql/driver-mongo';
2+
import path from 'path';
3+
4+
export default {
5+
datasources: {
6+
default: new MongoDriver({
7+
url: process.env.MONGO_URL || 'mongodb://127.0.0.1:27017/objectql_example',
8+
dbName: 'objectql_example'
9+
})
10+
},
11+
objectsDir: path.join(__dirname, 'objects')
12+
};

0 commit comments

Comments
 (0)