1
1
const graphql = require ( 'graphql' ) ;
2
2
const arangojs = require ( "arangojs" ) ;
3
3
const aql = arangojs . aql ;
4
+ const { makeExecutableSchema } = require ( 'graphql-tools' ) ;
4
5
const { ApolloError } = require ( 'apollo-server' ) ;
5
6
const waitOn = require ( 'wait-on' ) ;
6
7
7
8
let db ;
8
9
let disableEdgeValidation ;
9
- let diasableDiractivesChecking
10
+ let disableDirectivesChecking ;
10
11
11
12
module . exports = {
12
- init : async function ( schema ) {
13
- let db_name = process . env . db ? process . env . db : 'dev-db' ;
14
- let url = process . env . URL ? process . env . URL : 'http://localhost:8529' ;
15
- let drop = process . env . DROP === 'true' ;
16
- diasableDiractivesChecking = process . env . DISABLE_DIRECTIVES_CHECKING === 'true' ;
17
- disableEdgeValidation = process . env . DISABLE_EDGE_VALIDATION === 'true' ;
13
+ init : async function ( args ) {
14
+ let typeDefs = args . typeDefs ;
15
+ let db_name = args . db_name || 'dev-db' ;
16
+ let url = args . url || 'http://localhost:8529' ;
17
+ let drop = args . drop || false ;
18
+ disableDirectivesChecking = args . disableDirectivesChecking || false ;
19
+ disableEdgeValidation = args . disableEdgeValidation || false ;
18
20
db = new arangojs . Database ( { url : url } ) ;
19
21
20
22
// wait for ArangoDB
@@ -35,6 +37,11 @@ module.exports = {
35
37
( ) => console . log ( )
36
38
) ;
37
39
}
40
+ const schema = makeExecutableSchema ( {
41
+ 'typeDefs' : typeDefs ,
42
+ 'resolvers' : { }
43
+ } ) ;
44
+
38
45
await createAndUseDatabase ( db , db_name ) ;
39
46
await createTypeCollections ( db , schema ) ;
40
47
await createEdgeCollections ( db , schema ) ;
@@ -75,14 +82,9 @@ module.exports = {
75
82
} ,
76
83
getEdgeCollectionName : function ( type , field ) {
77
84
return getEdgeCollectionName ( type , field ) ;
78
- } ,
79
- hello : ( ) => hello ( ) // TODO: Remove after testing
85
+ }
80
86
} ;
81
87
82
- async function hello ( ) {
83
- return "This is the arangodb.tools saying hello!"
84
- }
85
-
86
88
async function createAndUseDatabase ( db , db_name ) {
87
89
await db . createDatabase ( db_name ) . then (
88
90
( ) => { console . info ( `Database '${ db_name } ' created` ) ; } ,
@@ -101,7 +103,7 @@ async function createTypeCollections(db, schema) {
101
103
await collection . create ( ) . then (
102
104
( ) => { console . info ( `Collection '${ collection_name } ' created` ) } ,
103
105
err => {
104
- // console.warn(`Collection '${collection_name}' not created:` , err.response.body.errorMessage);
106
+ console . warn ( `Collection '${ collection_name } ' not created:` , err . response . body . errorMessage ) ;
105
107
}
106
108
) ;
107
109
}
@@ -384,7 +386,7 @@ async function create(isRoot, ctxt, data, returnType, info){
384
386
}
385
387
386
388
// directives handling
387
- addfinalDirectiveChecksForType ( ctxt , returnType , aql `${ asAQLVar ( resVar ) } ._id` , info . schema ) ;
389
+ addFinalDirectiveChecksForType ( ctxt , returnType , aql `${ asAQLVar ( resVar ) } ._id` , info . schema ) ;
388
390
389
391
// overwrite the current action
390
392
if ( isRoot ) {
@@ -434,7 +436,7 @@ async function createEdge(isRoot, ctxt, source, sourceType, sourceField, target,
434
436
ctxt . trans . params [ docVar ] = doc ;
435
437
ctxt . trans . code . push ( `let ${ resVar } = db._query(aql\`INSERT ${ aqlDocVar } IN ${ collection } RETURN NEW\`).next();` ) ;
436
438
437
- addfinalDirectiveChecksForType ( ctxt , sourceType , source , info . schema ) ;
439
+ addFinalDirectiveChecksForType ( ctxt , sourceType , source , info . schema ) ;
438
440
439
441
// overwrite the current action
440
442
if ( isRoot ) {
@@ -673,7 +675,7 @@ async function update(isRoot, ctxt, id, data, returnType, info){
673
675
}
674
676
675
677
// directives handling
676
- addfinalDirectiveChecksForType ( ctxt , returnType , aql `${ asAQLVar ( resVar ) } ._id` , info . schema ) ;
678
+ addFinalDirectiveChecksForType ( ctxt , returnType , aql `${ asAQLVar ( resVar ) } ._id` , info . schema ) ;
677
679
678
680
// overwrite the current action
679
681
if ( isRoot ) {
@@ -1159,8 +1161,8 @@ function addPossibleEdgeTypes(query, schema, type_name, field_name, use_aql = tr
1159
1161
* @param resVar
1160
1162
* @param schema
1161
1163
*/
1162
- function addfinalDirectiveChecksForType ( ctxt , type , id , schema ) {
1163
- if ( ! diasableDiractivesChecking ) {
1164
+ function addFinalDirectiveChecksForType ( ctxt , type , id , schema ) {
1165
+ if ( ! disableDirectivesChecking ) {
1164
1166
for ( let f in type . getFields ( ) ) {
1165
1167
let field = type . getFields ( ) [ f ] ;
1166
1168
for ( dir of field . astNode . directives ) {
0 commit comments