From 2d94e9d9468ae8fd354471bcc1721539b0ae4b9e Mon Sep 17 00:00:00 2001
From: ManifoldFR <wilson.jallet@gmail.com>
Date: Fri, 2 Mar 2018 10:11:25 +0100
Subject: [PATCH] Modularising the schema: part one

---
 src/graphql/schema.js         | 26 +++-----------------------
 src/graphql/user_and_group.js | 27 +++++++++++++++++++++++++++
 src/server.js                 |  4 ++++
 3 files changed, 34 insertions(+), 23 deletions(-)
 create mode 100644 src/graphql/user_and_group.js

diff --git a/src/graphql/schema.js b/src/graphql/schema.js
index 47f67ea..215452e 100644
--- a/src/graphql/schema.js
+++ b/src/graphql/schema.js
@@ -8,6 +8,8 @@ import { makeExecutableSchema } from 'graphql-tools';
 import { request } from 'https';
 import { assertBinaryExpression } from 'babel-types';
 
+import { Group, User } from './user_and_group';
+
 const typeDefs = `
     type Query {
         allGroups: [Group]
@@ -15,28 +17,6 @@ const typeDefs = `
         user(uid: ID) : [User]
     }
 
-    type Group {
-        uid: ID
-        name: String
-        website: String
-        createdAt: String
-        updatedAt: String
-        description: String
-        school: String
-        parentuid: String
-    }
-
-    type User {
-        givenName: String!
-        lastName: String!
-        uid: ID!
-        birthdate: String!
-        mail: String
-        phone: String
-        groups: [String]
-        address: String
-    }
-
     type Mutation {
         asAdmin(groupid: String): AdminMutation
         asMember(groupid: String): MemberMutation
@@ -233,7 +213,7 @@ const resolvers = {
 };
 
 const schema = makeExecutableSchema({
-    typeDefs,
+    typeDefs: [typeDefs, Group, User],
     resolvers
 });
 
diff --git a/src/graphql/user_and_group.js b/src/graphql/user_and_group.js
new file mode 100644
index 0000000..be03a20
--- /dev/null
+++ b/src/graphql/user_and_group.js
@@ -0,0 +1,27 @@
+const User = `
+    type User {
+        givenName: String!
+        lastName: String!
+        uid: ID!
+        birthdate: String!
+        mail: String
+        phone: String
+        groups: [Group]
+        address: String
+    }
+`;
+
+const Group = `
+    type Group {
+        uid: ID
+        name: String
+        website: String
+        createdAt: String
+        updatedAt: String
+        description: String
+        school: String
+        parentuid: String
+    }
+`;
+
+export { Group, User };
\ No newline at end of file
diff --git a/src/server.js b/src/server.js
index f98d163..39e8192 100644
--- a/src/server.js
+++ b/src/server.js
@@ -9,6 +9,7 @@ import path from 'path';
 import cors from 'cors';
 import schema from './graphql/schema';
 import setupLdapAuth from './ldap/ldap_auth';
+import { express as graphqlVoyager } from 'graphql-voyager/middleware';
 import { graphqlExpress, graphiqlExpress } from 'graphql-server-express';
 import flash from 'connect-flash';
 
@@ -65,6 +66,9 @@ server.use('/graphql', bodyParser.json(), cors(),
 // GraphiQL est une console interactive pour faire des requêtes au schéma GraphQL
 server.use('/graphiql', graphiqlExpress({endpointURL: '/graphql'}));
 
+// GraphQL voyager
+server.use('/voyager', graphqlVoyager({ endpointUrl: '/graphql' }));
+
 // connect-flash is middleware for flashing messages
 server.use(flash());
 
-- 
GitLab