2017-11-03 5 views
0

Apollo Client에서 graphql 요청과 함께 쿠키를 전송하기위한 지침을 따라했지만 익스프레스 서버가 쿠키를받지 못하고 요청을 조사 할 때 쿠키가 전송되지 않았 음을 나타냅니다. 응답과 함께.React Apollo 클라이언트가 쿠키를 보내지 않음

이 페이지 다음은

https://www.apollographql.com/docs/react/recipes/authentication.html

내 코드가

const link = createHttpLink({ 
    uri: 'http://localhost:3000/api/graphql', 
    opts: { 
    credentials: 'include', 
    } 
}); 

const client = new ApolloClient({ 
    link, 
    cache: new InMemoryCache() 
}); 

내 설치가 매우 간단입니다, 난 그냥 로컬 호스트에 만들-반응-응용 프로그램을 서버를 사용하고 있습니다 : 3000, 전송 localhost에 api 요청 : 5000 (express api 서버). 다른 경로에서는 localhost : 3000을 통해 쿠키를 설정하고 검색 할 수 있습니다. Apollo Client만이이를 보내지 않습니다.

답변

1

더 많은 경험을 가진 개발자가 문제를 일으키지 않았지만 설명서에 그 이유가 무엇인지 밝히지는 않습니다.

const link = createHttpLink({ 
    uri: 'http://localhost:3000/api/graphql', 
    opts: { 
    credentials: 'include', 
    } 
}); 

는 그냥해야한다 : 즉

const httpLink = createHttpLink({ 
    uri: 'http://localhost:3000/api/graphql', 
    credentials: 'same-origin' 
}); 

의 createHttpLink 구성 개체 내에서 별도의 opts 개체가 없습니다 어쨌든

은 경험이 적은 개발자는 대신 점에 유의해야한다 .