Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #70 from multinet-app/graphiql
Browse files Browse the repository at this point in the history
Add GraphiQL support
  • Loading branch information
waxlamp committed Jun 28, 2019
2 parents 91c8f93 + b2b536e commit 5263fd1
Show file tree
Hide file tree
Showing 9 changed files with 5,599 additions and 6 deletions.
26 changes: 26 additions & 0 deletions docs/graphiql.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=================
multinet-graphiql
=================

A `GraphiQL <https://github.com/graphql/graphiql>`_ client for testing and
playing around with Multinet's GraphQL API.

.. highlight: sh
Installation
============

1. Build and run the Multinet server (:ref:`multinet-girder`).

2. Install the dependencies: ::

$ yarn install

3. Run the dev server: ::

% yarn serve

This server will also recompile the application on the fly whenever the
source code changes.

4. Open your browser to point at the address displayed by the command in step 3.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Welcome to Multinet
:maxdepth: 2

installation
graphiql

Indices and tables
==================
Expand Down
7 changes: 5 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.. _multinet-girder:

===============
multinet-girder
=================
===============
A Girder plugin proof-of-concept for a MultiNet API / web application

.. highlight:: sh

Installation
=================
============

Set Up Multinet/Girder
----------------------
Expand Down
3 changes: 3 additions & 0 deletions graphiql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
node_modules/
yarn-error.log
36 changes: 36 additions & 0 deletions graphiql/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "multinet-graphiql",
"version": "1.0.0",
"description": "GraphiQL client for Multinet client application",
"main": "index.js",
"scripts": {
"build": "webpack",
"serve": "webpack-dev-server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Kitware Inc.",
"license": "Apache-2.0",
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
},
"dependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.6",
"css-loader": "^3.0.0",
"graphiql": "^0.13.2",
"graphql": "^14.4.0",
"html-webpack-plugin": "^3.2.0",
"isomorphic-fetch": "^2.2.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"style-loader": "^0.23.1",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.5",
"webpack-dev-server": "^3.7.2"
}
}
35 changes: 35 additions & 0 deletions graphiql/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import ReactDOM from 'react-dom';
import GraphiQL from 'graphiql';
import fetch from 'isomorphic-fetch';

import 'graphiql/graphiql.css';

const HOST = 'http://localhost:9090';

function graphQLFetcher(graphQLParams) {
console.log(graphQLParams);

const json = JSON.stringify({
'query': graphQLParams.query,
'variables': graphQLParams.variables
});

return fetch(`${HOST}/api/v1/multinet/graphql`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: json,
}).then(response => response.json());
}

// Use a 500ms timeout to avoid a problem of the actual query editor being
// hidden otherwise (see
// https://github.com/graphql/graphiql/issues/770#issuecomment-505699802).
window.setTimeout(() => {
ReactDOM.render(
<div style={{ height: '100vh' }}>
<GraphiQL fetcher={graphQLFetcher} />
</div>, document.body);
}, 500);
40 changes: 40 additions & 0 deletions graphiql/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './src/index.js',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
{
test: /\.css$/,
include: /node_modules/,
use: ['style-loader', 'css-loader'],
}
],
},
resolve: {
extensions: ['*', '.js', '.jsx', '.mjs'],
},
output: {
path: __dirname + '/build',
publicPath: '/',
filename: 'bundle.js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'GraphiQL/Multinet',
}),
],
devServer: {
contentBase: './build',
},
};

0 comments on commit 5263fd1

Please sign in to comment.