使用SSR时如何在ApolloClient中编辑标题?

时间:2020-02-20 15:28:37

标签: reactjs graphql apollo react-apollo apollo-client

我正在使用React.js在Web App的服务器端将此httpLink添加到我的ApolloClient

const httpLink = createHttpLink({
    uri: `${envConfigServer.endpointGraphql}/graphql`,
    headers: {
        'User-Agent': `web (SSR; ${envConfigServer.branch || 'local'})`,
        'X-Server': `web (SSR; ${envConfigServer.branch || 'local'})`,
        IBIMS: 'EINSHEADER',
    },
});

然后

const createServerApolloClient = (_initialState: any = {}) => {
    return new ApolloClient({
        cache,
        link,
    });
};

我正在使用ts-node在本地运行。 SSR已启用。标头被

覆盖
"userAgent":"node-fetch/1.0 ... "

我在做什么错?我从未在日志中看到服务器标头。看来阿波罗只是吞下他们。有任何解决方法的想法吗?

目标:在请求中将标头发送到API。

堆栈:React.js,GraphQL,ApolloClient,Express.js

0 个答案:

没有答案