Skip to content
Snippets Groups Projects
Commit 6beabd02 authored by Wilson JALLET's avatar Wilson JALLET :money_with_wings:
Browse files

Merge into branch master

parents c0ade457 8909c92e
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ import { request } from 'https';
const typeDefs = `
type Query {
groups: [Group]!
allGroups: [Group]!
group(id : ID) : Group!
}
......@@ -24,25 +24,22 @@ const typeDefs = `
}
`;
const knex_req = {
getAllVisibleGroups : (user) => {
let group_ids = listGroups(user.id);
return knex.select().from('groups').whereIn('id', group_ids);
},
const getAllVisibleGroups = (user) => {
let group_ids = listGroups(user.id);
return knex.select().from('groups').whereIn('id', group_ids);
};
getGroupIfVisible : (user, id) => {
return getAllVisibleGroups(user).where('id', args.id);
}
const getGroupIfVisible = (user, id) => {
return this.getAllVisibleGroups(user).where('id', id);
};
const resolvers = {
Query: {
groups: (obj, args, context) => {
return knex_req.getAllVisibleGroups(context.user);
allGroups: (obj, args, context) => {
return getAllVisibleGroups(context.user);
},
group: (obj, args, context) => {
return knex_req.getGroupIfVisible(context.user, args.id);
return getGroupIfVisible(context.user, args.id);
}
}
};
......
......@@ -16,7 +16,7 @@ const server = express();
// on sait pas a quoi ca sert mais il parait que c'est utile
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({
extended: false
extended: true
}));
// setting up view engine for pug
......@@ -32,10 +32,16 @@ server.use(favicon(path.resolve('./','assets','favicon.ico')));
server.use(morgan('dev'));
// Charge le middleware express pour GraphQL
server.use('/graphql', cors(), bodyParser.json(), graphqlExpress({schema}));
server.use('/graphql', bodyParser.json(),
graphqlExpress(req => {
return {
schema : schema,
context : {user : {id : req.session.id}}
};
}));
// GraphiQL est une console interactive pour faire des requêtes au schéma GraphQL
server.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql'}));
server.use('/graphiql', graphiqlExpress({endpointURL: '/graphql'}));
// connect-flash is middleware for flashing messages
server.use(flash());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment