File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " i-graphql" ,
3- "version" : " 0.2.1 " ,
3+ "version" : " 0.2.2 " ,
44 "private" : false ,
55 "license" : " MIT" ,
66 "description" : " GraphQL Friendly ORM for MongoDB" ,
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export const mc = async (props: {
1010 if ( mongoConnection ) {
1111 return Promise . resolve ( mongoConnection ) ;
1212 }
13- const resolvedMongoUrl = mongoUrl || process . env . MONGO_URL ;
13+ const resolvedMongoUrl = mongoUrl || tryToCreateMongoUrl ( ) ;
1414 let client : MongoClient | undefined = mongoClient ;
1515 if ( resolvedMongoUrl && ! client ) {
1616 client = new MongoClient ( resolvedMongoUrl , {
@@ -33,3 +33,15 @@ export const mc = async (props: {
3333 await afterConnection ?.( db ) ;
3434 return mongoConnection ;
3535} ;
36+
37+ export const tryToCreateMongoUrl = ( ) => {
38+ if ( process . env . MONGO_URL ) return process . env . MONGO_URL ;
39+ if (
40+ ! process . env . MONGO_PASSWORD ||
41+ ! process . env . MONGO_USERNAME ||
42+ ! process . env . MONGO_DATABASE ||
43+ ! process . env . MONGO_HOSTNAME
44+ )
45+ return '' ;
46+ return `mongodb+srv://${ process . env . MONGO_USERNAME } :${ process . env . MONGO_PASSWORD } @${ process . env . MONGO_HOSTNAME } /${ process . env . MONGO_DATABASE } ?retryWrites=true&w=majority` ;
47+ } ;
You can’t perform that action at this time.
0 commit comments