diff --git a/package-lock.json b/package-lock.json index 878e1770bbc9c4b23987eac5c42a1f2119adb385..5a7f9c667688d83d032a72a74ae63eafeb40061c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -384,14 +384,6 @@ "normalize-path": "^2.1.1" } }, - "apollo-cache-control": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/apollo-cache-control/-/apollo-cache-control-0.1.1.tgz", - "integrity": "sha512-XJQs167e9u+e5ybSi51nGYr70NPBbswdvTEHtbtXbwkZ+n9t0SLPvUcoqceayOSwjK1XYOdU/EKPawNdb3rLQA==", - "requires": { - "graphql-extensions": "^0.0.x" - } - }, "apollo-link": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/apollo-link/-/apollo-link-1.2.2.tgz", @@ -402,38 +394,6 @@ "zen-observable-ts": "^0.8.9" } }, - "apollo-server-core": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-1.3.6.tgz", - "integrity": "sha1-CGNiQ8LeVvqMJn1o3WAssfvTI+M=", - "requires": { - "apollo-cache-control": "^0.1.0", - "apollo-tracing": "^0.1.0", - "graphql-extensions": "^0.0.x" - } - }, - "apollo-server-express": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-1.3.6.tgz", - "integrity": "sha1-ISCwUCGofe9E+v2EbooOKjKFLbc=", - "requires": { - "apollo-server-core": "^1.3.6", - "apollo-server-module-graphiql": "^1.3.4" - } - }, - "apollo-server-module-graphiql": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/apollo-server-module-graphiql/-/apollo-server-module-graphiql-1.3.4.tgz", - "integrity": "sha1-UDmbfFG3Jn0MhBUp9Rc+X8cwTeQ=" - }, - "apollo-tracing": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.1.4.tgz", - "integrity": "sha512-Uv+1nh5AsNmC3m130i2u3IqbS+nrxyVV3KYimH5QKsdPjxxIQB3JAT+jJmpeDxBel8gDVstNmCh82QSLxLSIdQ==", - "requires": { - "graphql-extensions": "~0.0.9" - } - }, "apollo-utilities": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/apollo-utilities/-/apollo-utilities-1.0.11.tgz", @@ -1761,11 +1721,6 @@ "isarray": "^1.0.0" } }, - "buffer-from": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.0.0.tgz", - "integrity": "sha512-83apNb8KK0Se60UE1+4Ukbe3HbfELJ6UlI4ldtOGs7So4KD26orJM8hIY9lxdzP+UpItH1Yh/Y8GUvNFWFFRxA==" - }, "buffer-writer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz", @@ -3225,7 +3180,7 @@ }, "event-stream": { "version": "3.3.4", - "resolved": "http://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", + "resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", "integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=", "dev": true, "requires": { @@ -3442,6 +3397,17 @@ } } }, + "express-graphql": { + "version": "0.6.12", + "resolved": "https://registry.npmjs.org/express-graphql/-/express-graphql-0.6.12.tgz", + "integrity": "sha512-ouLWV0hRw4hnaLtXzzwhdC79ewxKbY2PRvm05mPc/zOH5W5WVCHDQ1SmNxEPBQdUeeSNh29aIqW9zEQkA3kMuA==", + "requires": { + "accepts": "^1.3.0", + "content-type": "^1.0.4", + "http-errors": "^1.3.0", + "raw-body": "^2.3.2" + } + }, "express-session": { "version": "1.15.6", "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.15.6.tgz", @@ -4675,15 +4641,6 @@ "iterall": "^1.2.1" } }, - "graphql-extensions": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/graphql-extensions/-/graphql-extensions-0.0.10.tgz", - "integrity": "sha512-TnQueqUDCYzOSrpQb3q1ngDSP2otJSF+9yNLrQGPzkMsvnQ+v6e2d5tl+B35D4y+XpmvVnAn4T3ZK28mkILveA==", - "requires": { - "core-js": "^2.5.3", - "source-map-support": "^0.5.1" - } - }, "graphql-request": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-1.5.1.tgz", @@ -4692,14 +4649,6 @@ "cross-fetch": "2.0.0" } }, - "graphql-server-express": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/graphql-server-express/-/graphql-server-express-1.3.6.tgz", - "integrity": "sha1-Y0aVTE3qBnAi3ZMtgUVygDpA1Fs=", - "requires": { - "apollo-server-express": "^1.3.6" - } - }, "graphql-tools": { "version": "2.24.0", "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-2.24.0.tgz", @@ -8889,22 +8838,6 @@ "urix": "^0.1.0" } }, - "source-map-support": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.5.tgz", - "integrity": "sha512-mR7/Nd5l1z6g99010shcXJiNEaf3fEtmLhRB/sBcQVJGodcHCULPp2y4Sfa43Kv2zq7T+Izmfp/WHCR6dYkQCA==", - "requires": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" - } - } - }, "source-map-url": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz", diff --git a/package.json b/package.json index 3737a46b0e489e0fe3766962ae0aff0a34269d82..e66886440735a2b63d893250d64ed0966bd8794c 100644 --- a/package.json +++ b/package.json @@ -12,12 +12,12 @@ "copy-webpack-plugin": "^4.5.0", "cors": "^2.8.4", "express": "^4.16.2", + "express-graphql": "^0.6.12", "express-session": "^1.15.6", "file-loader": "^1.1.11", "fs": "0.0.1-security", "fuse.js": "^3.2.0", "graphql": "^0.13.2", - "graphql-server-express": "^1.3.6", "graphql-tools": "^2.24.0", "graphql-voyager": "^1.0.0-rc.15", "knex": "^0.14.6", diff --git a/src/graphql/resolvers.js b/src/graphql/resolvers.js index 4bce359e531861467591f3c80dd4785a06ba1aa4..fa09f4c69c369a60c1fa8dd928b2f13dc06f126e 100644 --- a/src/graphql/resolvers.js +++ b/src/graphql/resolvers.js @@ -73,7 +73,6 @@ export const resolvers = { }, searchTOL: (obj, args, context) => { - console.log("Searching TOL for",args); const result = connectors.utilisateur.repliquerTOLdesIds({ givenName: args.givenName, lastName: args.lastName, diff --git a/src/server.js b/src/server.js index 9f4338399c9906694e73d683a3cd8fda1d27c1fc..34842ed9e7cf316629e011f62bbcbe56a608841e 100644 --- a/src/server.js +++ b/src/server.js @@ -8,7 +8,7 @@ import express from 'express'; import schema from './graphql/schema'; import { express as graphqlVoyager } from 'graphql-voyager/middleware'; -import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'; // new name of 'graphql-server-express'. cf npmjs.com +import graphqlHTTP from 'express-graphql'; // new name of 'graphql-server-express'. cf npmjs.com import flash from 'connect-flash'; import { ensureLoggedIn } from 'connect-ensure-login'; import passport from 'passport'; @@ -121,36 +121,16 @@ const corsOptions = { }; server.use(cors(corsOptions)); -// Charge le middleware express pour GraphQL -server.use('/graphql', bodyParser.json(), - graphqlExpress(req => { - // vary the options *on a per-request basis* - // (options are passed by using req object as argument) - let uid; - let password; - - try { - uid = req.user.uid; - password = "mythe"; - } catch (err) { - uid = defaultUser.dn.split("=")[1].split(",")[0]; - password = defaultUser.passwd; - } - - // console.log("Accessing GraphQL as: ",uid); - - return { - schema : schema, - context: { user: { uid: uid, password: password } } // accessible in every single resolver as the third argument - }; - }) -); - -// GraphiQL est une console interactive pour faire des requêtes GraphQL à la BDD -server.use('/graphiql', - /*ensureLoggedIn('/login'),*/ - graphiqlExpress({endpointURL: '/graphql'}) -); +server.use('/graphql', bodyParser.json(), graphqlHTTP(async (req, res, params) => ({ + schema: schema, + graphiql: true, + context: { + user: { + uid: req.user ? req.user.uid : defaultUser.dn.split("=")[1].split(",")[0], + password: "mythe" + } + } +}))); // GraphQL voyager affiche une représentation sous forme de graphe du schema GraphQL server.use('/voyager', diff --git a/src/views/home.pug b/src/views/home.pug index 6a21179d2c8d7bfe22018627b6e52c5e7f5aeca6..e0ab000f7844672cdf5c09297db356e13c37c574 100644 --- a/src/views/home.pug +++ b/src/views/home.pug @@ -17,7 +17,7 @@ block content h2 GraphiQL and Voyager p GraphiQL is an interactive environment to make GraphQL requests to the database. p GraphQL Voyager is an application that displays the GraphQL schema as an actual graph. - a(class="button button-small",href="/graphiql") GraphiQL + a(class="button button-small",href="/graphql") GraphiQL a(class="button button-small",href="/voyager") Voyager | p Currently logged in as: #{userName}.