2017-12-22 16 views
11

내 미들웨어 서버에서 원격 스키마 스티칭을 사용하고 있습니다. 미들웨어 서버에서 스키마를 원격으로 가져올 수 있으며 미들웨어 서버에서 내 경로를 정의했습니다.한 서버에서 미들웨어 서버로 확장을 전달하는 방법

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 : {},'는 비어 있습니다. –