2017-12-22 6 views
11

私のミドルウェアサーバーでリモートスキーマステッチングを使用しています。私は、ミドルウェアサーバー上でこのように自分のルートを定義し、ミドルウェアサーバー上でリモートからスキーマを取得することができます。1つのサーバーからミドルウェアサーバーに拡張子を転送する方法

app.use('/graphql', graphqlHTTP((request,res) => { 
const startTime = Date.now(); 
return { 
    schema: remoteSchema 
    graphiql: false, 
    extensions({ document, variables, operationName, result }) { 
    return { 
     // here I am not getting extensions which I have on my another server as below. 
     console.log(res); // this does not have additional info and response headers 
     console.log(result); // this only has response against the query 
    } 
    }; 
})); 

私は結果で、クエリの結果を得ることが、私はリゾルバがある私の他のサーバー上に追加してい拡張の一部である応答ヘッダや追加情報を取得しておりません。

{ 
    "data": { 
     "records": { 
      "record": [{ 
        "id": 1, 
       }, 
       { 
        "id": 2, 
       } 
      ], 
     }, 
     "additionalInfo": {} 
    }, 
    "extensions": { 
     "info": {} 
    } 
} 

何が問題になりますか?これは、拡張機能で別のサーバーに応答ヘッダーと追加情報を追加する方法です。私は拡張データが利用できるコードの下でデバッグします。これはミドルウェアサーバーに渡されていません。

extensions({ document, variables, operationName, result }) { 
    result.data.additionalInfo = res.additionalInfo; 
    // extension to write api headers in response 
    var headerObj = {}; 
    res.apiHeaders.forEach(element => { 
    merge(headerObj, element); 
    }); 
    result.headerObj = headerObj; 
    return { 
     information: headerObj 
    }; 
} 

私のアプリケーションの流れは、私がミドルウェアルートを呼び出してから別のサーバールートをリモートスキーマステッチングを使って呼び出すことです。私は別のサーバー上に追加する拡張機能を、ミドルウェアサーバーに転送する必要があります。

答えて

2

あなたはconsole.log()リクエストをしていますか?私はあなたがアウトプットしようとしているヘッダに関する拡張機能では、サーバ上のミドルウェアであるため、リクエストに含まれるものはどれも、レスポンスはあなたが次の関数に送る前に変更するものか、クライアントに返します。

extensions({ document, variables, operationName, result }) { 
    // console.log the request object to check the header information from the request. 
    console.log(request); 
    return { 
     // This will fill the information key with all the headers in the request. 
     information: reaquest.header 
    }; 
} 
+0

':'と '=>'は必要ありません。元のサンプルコードでは、メソッド定義のオブジェクトリテラルを省略して使用しています。 – aaronjkrause

+0

@aaronjkrause私はドキュメントの中でそれを指摘してくれてありがとう。 – RickyM

+0

@RickyMリクエストが表示されますが、 'apiHeaders:[]、 additionalInfo:{}、'は空です。 –

関連する問題