Skip to content

Commit cbd3351

Browse files
committed
pass driver as part of the options to custom functions by default, include new helper function
1 parent b62c9e2 commit cbd3351

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

graphql-server/drivers/arangodb/driver.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ module.exports = {
6666
isEndOfList: async function (parent, args, info) {
6767
return await isEndOfList(parent, args, info);
6868
},
69+
addPossibleEdgeTypes: function(query, schema, type_name, field_name){
70+
return addPossibleEdgeTypes(query, schema, type_name, field_name);
71+
},
6972
getEdgeCollectionName: function(type, field){
7073
return getEdgeCollectionName(type, field);
7174
},
@@ -1095,3 +1098,24 @@ function conditionalThrow(msg){
10951098
throw msg;
10961099
}
10971100
}
1101+
1102+
/**
1103+
* Add all possible edge-collections for the given type and field to query
1104+
* @param query, schema, type_name, field_name, directionString (Optional)
1105+
*/
1106+
function addPossibleEdgeTypes(query, schema, type_name, field_name, directionString = ""){
1107+
let type = schema._typeMap[type_name];
1108+
if(graphql.isInterfaceType(type)){
1109+
let possible_types = schema.getPossibleTypes(type);
1110+
for (let i in possible_types) {
1111+
if (i != 0) {
1112+
query.push(aql`,`);
1113+
}
1114+
let collection = db.collection(getEdgeCollectionName(possible_types[i].name, field_name));
1115+
query.push(aql`${collection}`);
1116+
}
1117+
} else {
1118+
let collection = db.collection(getEdgeCollectionName(type.name, field_name));
1119+
query.push(aql`${collection}`);
1120+
}
1121+
}

graphql-server/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const typeDefs = gql`${text + textExtend}`;
1111
async function run(){
1212
// setup resolvers
1313
const resolvers = await graphqlResolvers.get({ driver: driver });
14-
const customResolvers = await graphqlCustomResolvers.get({});
14+
const customResolvers = await graphqlCustomResolvers.get({ driver: driver });
1515
resolvers.Query = {...resolvers.Query, ...customResolvers.Query};
1616

1717
const server = new ApolloServer({typeDefs, resolvers: resolvers});

0 commit comments

Comments
 (0)