From ffde0a3920e71b8c9da7503ff477457ffacc9ccd Mon Sep 17 00:00:00 2001 From: ManifoldFR <wilson.jallet@gmail.com> Date: Wed, 28 Feb 2018 01:48:38 +0100 Subject: [PATCH] =?UTF-8?q?Impl=C3=A9mentation=20GraphQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avec iGraphQL pour interagir avec le schéma GraphQL --- .gitlab-ci.yml | 5 ++--- src/index.js | 3 --- src/server.js | 31 +++++++++++++++++++++++++++++++ src/views/home.pug | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7c04492..71a6cec 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,7 +49,7 @@ test:lint: test:async: stage: test script: - - npm start + - npm start & - sleep 5 - curl http://localhost:3000 - pkill node @@ -60,8 +60,7 @@ test:async: deploy_staging: stage: deploy script: - - npm start & - - sleep 30 + - npm start & sleep 5 - exit 0 environment: name: staging diff --git a/src/index.js b/src/index.js index f9c12e2..bcb0a10 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,6 @@ import server from './server'; import router from './admin_view/admin_view'; import colors from 'colors'; -import { graphqlExpress, graphiqlExpress } from 'graphql-server-express'; -import makeExecutableSchema from 'graphql-tools'; -import knex from '../db/knex_router'; import path from 'path'; /** diff --git a/src/server.js b/src/server.js index b24da82..f48b6c4 100644 --- a/src/server.js +++ b/src/server.js @@ -2,8 +2,11 @@ import express from 'express'; import bodyParser from 'body-parser'; import favicon from 'serve-favicon'; import morgan from 'morgan'; +import knex from '../db/knex_router'; import path from 'path'; import ldap_auth from './ldap_auth/ldap_auth'; +import { graphqlExpress, graphiqlExpress } from 'graphql-server-express'; +import { makeExecutableSchema } from 'graphql-tools'; /** * @file server.js @@ -34,4 +37,32 @@ server.use(morgan('dev')); // setting up ldap authentication ldap_auth(server); +const typeDefs = ` + type Query { + groups: [Group] + } + + type Group { + name: String + id: Int + school: String + } +`; + +const resolvers = { + Query: { + groups: () => knex.select().from('groups') + } +}; + +const schema = makeExecutableSchema({ + typeDefs, + resolvers +}); + +server.use('/graphql', bodyParser.json(), graphqlExpress({schema})); + +server.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql'})); + + export default server; diff --git a/src/views/home.pug b/src/views/home.pug index 7835d6b..20f88d1 100644 --- a/src/views/home.pug +++ b/src/views/home.pug @@ -12,4 +12,4 @@ block content input.form-control(type="search", name="columns") button.form-control(type="submit") Search | - a(href="/graphql") Check GraphQL \ No newline at end of file + a(href="/graphiql") Check GraphQL \ No newline at end of file -- GitLab