/**
* @file Ce fichier genere le shema utilise par Apollo. C'est ici que les requetes GraphQl sont résolues.
* @author akka vodol
*/
import knex from '../../db/knex_router';
import { listGroups, listMembers } from '../ldap/ldap_data';
import { makeExecutableSchema } from 'graphql-tools';
import { request } from 'https';
const typeDefs = `
type Query {
allGroups: [Group]
group(id: ID) : [Group]
}
type Group {
name: String!
id: ID!
website: String
updatedAt: String!
description: String
school: String!
}
`;
const getAllVisibleGroups = (user) => {
console.log("getAllVisibleGroups gets called");
// let group_ids = listGroups(user.id);
return knex.select().from('groups')/*.whereIn('id', group_ids)*/;
};
const getGroupIfVisible = (user, id) => {
console.log("getGroupIfVisible gets called");
return getAllVisibleGroups(user).where('id', id)/*.then(function(table) {
console.log(JSON.stringify(table,null,2))*/;
};
const resolvers = {
Query: {
allGroups: (obj, args, context) => {
return getAllVisibleGroups(context.user);
},
group: (obj, args, context) => {
return getGroupIfVisible(context.user, args.id);
}
}
};
const schema = makeExecutableSchema({
typeDefs,
resolvers
});
export default schema;