2016-06-24 5 views
2

でGraphiQLを使用して、次のように渡すことができexpress-graphqlから graphQLHTTPがあります:NodeJSでフォックス

const {Schema} = require('./data/schema'); 
    const graphQLApp = express(); 
    graphQLApp.use('/', graphQLHTTP({ 
    graphiql: true, 
    pretty: true, 
    schema: Schema, 
    })); 

設定のようなものでは、我々はGraphiQLを使用することができます。どのようにFoxxでそれを達成するには? this repoから、私はFoxxがgraphql-syncを代わりに使用しているのを見ることができました。私は、ソースコードを閲覧し、私はここでそれを見つけた:

controller.js

'use strict'; 
const Foxx = require('org/arangodb/foxx'); 
const schema = require('./schema'); 
const graphql = require('graphql-sync').graphql; 
const formatError = require('graphql-sync').formatError; 

const ctrl = new Foxx.Controller(applicationContext); 

// This is a regular Foxx HTTP API endpoint. 
ctrl.post('/graphql', function (req, res) { 
    // By just passing the raw body string to graphql 
    // we let the GraphQL library take care of making 
    // sure the query is well-formed and valid. 
    // Our HTTP API doesn't have to know anything about 
    // GraphQL to handle it. 
    const result = graphql(schema, req.rawBody(), null, req.parameters); 
    console.log(req.parameters); 
    if (result.errors) { 
    res.status(400); 
    res.json({ 
     errors: result.errors.map(function (error) { 
     return formatError(error); 
     }) 
    }); 
    } else { 
    res.json(result); 
    } 
}) 
.summary('GraphQL endpoint') 
.notes('GraphQL endpoint for the Star Wars GraphQL example.'); 

それはフォックスでGraphiQLを使用することは可能ですか? YESの場合、どうすれば達成できますか?何かご意見は?

ありがとうございました。

答えて

2

あなたはそれがサーバに組み込まれていない場合でも、任意のGraphQL APIでGraphiQLを使用することができます。あなたは実行することができますGraphiQL自分でいくつかの異なる方法で:

  1. スタンドアロンアプリケーションとして:https://github.com/skevy/graphiql-app
  2. 、アプリケーション内のコンポーネントを反応する:https://github.com/graphql/graphiql

あなたはNPMからリアクトコンポーネントとしてそれを使用している場合(オプション2)、実際に余分なオプションを使ってカスタマイズしたり、サーバに送信するリクエストを操作したりできます。

+0

うわー、それはクールです。ありがとうございました.. :) – asubanovsky

+0

実際にexpress-graphqlを調べて、ArangoDBに直接移植することを検討しています。その電話をかけるまでは、これが最善の解決策です。 +1 –

1

GraphiQLウィンドウを開くためのツールバーにボタンを追加しChromeiQL呼ばれるChromeの拡張機能があります。シンプルで簡単、任意のサーバーを実行する必要はありません