diff --git a/src/graphql/schema.js b/src/graphql/schema.js index e844d0c575f82f2be4a987c9e7fd124f48bfed5a..c1209010e603e1207bab5e0796236f53137c09b6 100644 --- a/src/graphql/schema.js +++ b/src/graphql/schema.js @@ -4,14 +4,14 @@ */ import knex from '../../db/knex_router'; -import { listGroups, listMembers} from '../ldap/ldap_data'; +// 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! + allGroups: [Group] + group(id: ID) : [Group] } type Group { @@ -25,12 +25,13 @@ const typeDefs = ` `; const getAllVisibleGroups = (user) => { - let group_ids = listGroups(user.id); - return knex.select().from('groups').whereIn('id', group_ids); + // let group_ids = listGroups(user.id); + return knex.select().from('groups')/*.whereIn('id', group_ids)*/; }; const getGroupIfVisible = (user, id) => { - return this.getAllVisibleGroups(user).where('id', id); + return getAllVisibleGroups(user)/*.where('id', id).then(function(table) { + console.log(JSON.stringify(table,null,2))*/; }; const resolvers = { @@ -39,6 +40,7 @@ const resolvers = { return getAllVisibleGroups(context.user); }, group: (obj, args, context) => { + console.log(args.id); return getGroupIfVisible(context.user, args.id); } } diff --git a/src/ldap/ldap_data.js b/src/ldap/ldap_data.js index 5e8e5e88a44e7d7f52e5903341cce89ad3411f97..f1fb8a5e068a009991f31f76e4fb09a5c3eb2f32 100644 --- a/src/ldap/ldap_data.js +++ b/src/ldap/ldap_data.js @@ -116,7 +116,6 @@ function TOL(c0="", c1="", c2="", c3="", c4="", c5="", c6="", c7="", c8="", c9=" // Synthaxe d'utilisation //listGroups("quentin.louis").then((meList) => { console.log(meList); }); -TOL("","","","","","","faerix","","","","","","").then((meList) => { console.log(meList); }); /* Partage pour le reste du monde ; même remarque synthaxe export { listGroups, listMembers, TOL }; */ diff --git a/src/server.js b/src/server.js index 00500627da7046efd2d40dfdd9d86c2b61123d00..a40a9c57dcb4903ef9a11707f386f2ca50bdc5e4 100644 --- a/src/server.js +++ b/src/server.js @@ -32,11 +32,19 @@ server.use(favicon(path.resolve('./','assets','favicon.ico'))); server.use(morgan('dev')); // Charge le middleware express pour GraphQL -server.use('/graphql', bodyParser.json(), +server.use('/graphql', bodyParser.json(), cors(), graphqlExpress(req => { + let uid; + + try { + uid = req.session.id; + } catch (err) { + uid = "1"; + } + return { schema : schema, - context : {user : {id : req.session.id}} + context : {user : {id : uid}} }; }));