- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 with-apollo-auth 之后例子执行客户端 ApolloConsumer 查询时的成功行为。我通过客户端并查询工作。
当我尝试通过 getInitialProps 进行服务器端查询时出现不成功行为。我通过调用相同查询的处理程序传递客户端,我收到 ECONN 拒绝错误,如下所示。
重现该行为的步骤:
我在 init-apollo 文件中设置我的 ApolloClient 如下:
const httpLink = createHttpLink({
uri: 'http://localhost:8080/api/graphql',
credentials: 'same-origin'
})
const authLink = setContext((_, { headers }) => {
const token = getToken()
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : ''
}
}
})
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
link: ApolloLink.from([ authLink, httpLink ]),
cache: new InMemoryCache().restore(initialState || {})
})
我按如下方式设置我的查询:
import gql from 'graphql-tag'
export default apolloClient => {
apolloClient
.query({
query: gql`
{
getUser {
id
}
}
`
})
.then(({data}) => {
console.log(data);
return { userDetails: data.getUser }
})
.catch((err) => {
// Fail gracefully
console.log(err);
return { userDetails: {} }
})
}
我在 pages 目录中的 index.js 文件中设置了我的 getInitialProps 函数:
import getUser from '../shared/services/get-user';
static async getInitialProps (context) {
const results = await getUser(context.apolloClient)
console.log(results);
return {}
}
预期行为我希望看到返回的用户日志,但是我收到如上所示的 ECONNREFUSED 错误。
系统信息操作系统:macOS Mojave浏览器(如果适用)ChromeNext.js 版本:7.0.2ApolloClient 版本:2.4.12l附加上下文使用 Absinthe (Elixir+Phoenix) GraphQL API,指定 url:http://localhost:8080/api/graphq使用 docker-compose 启动多个容器。 API 和 NextJS 客户端位于位于 nginx 服务器后面的单独容器中。 Nginx 服务器根据指定的 url 端点路由到相关容器。 这很可能是问题所在,但我似乎找不到解决方案。如果 url 包含 api,客户端将被路由到我的 API 容器。
这是我的 nginx 配置设置:
upstream client {
server client:3000;
}
upstream api {
server api:4000;
}
server {
listen 80;
location / {
proxy_pass http://client;
}
location /sockjs-node {
proxy_pass http://client;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://api;
}
}
最佳答案
虽然回答晚了,但您应该提供有关后端 API 框架的更多信息,即您正在运行哪个框架?我相信前端是 nextjs。尽管如此,我认为您的问题出在 nginx 配置上。请通过端口号而不是 \location
proxy_pass
您的 url,因为它们是两种不同的网络服务。试试这个配置,注意标题。同时将您的操作系统配置为监听端口 8030。
server { listen 80; location / { proxy_pass http://client; proxy_pass_request_headers on; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect off; }}server { listen 8030; location / { proxy_pass http://api; proxy_pass_request_headers on; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect off; }}
关于nginx - 使用 apollo 客户端从 nextjs 中的 getInitialProps 方法执行 graphQL 查询时出现 ECONNREFUSED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54411045/
有没有全局loading react-apollo 客户端在任何地方都可以使用标志吗?我有一个“页面包装器”组件,我想在所有子组件都收到它们的数据后应用 ui 效果。 我已经使用 redux 设置了
我试图通过 React 了解 Apollo。如何将状态添加到我本地的 Apollo 商店? 我正在使用 meteor 。它在客户端提供了一个功能来测试用户是否登录并返回他们的 id 如果他们是 Met
我有一个关于 cacheRedirects 的问题在 Apollo 中,我有项目概览和详细 View 。我希望将 detailview 缓存重定向到概览中的一个项目(如文档中的 the book ex
我们可以使用查询和变异向服务器发出一些请求。在这些查询中,我们可以传递一些参数,并且在这两种情况下我们都会从服务器获得一些结果。唯一的一个强制性区别是,我们可以从 props 中调用突变,例如“thi
我正在使用 @apollo/client 实现,但我没有看到任何完整的 @apollo/client 示例与 react . 如果我搜索,我会得到示例 apollo-client和 apollo bo
我正在使用 apollo-client、apollo-link 和 react-apollo,我想完全禁用缓存,但不知道该怎么做。 我看了apollo-cache-inmemory的来源,它有一个 c
我正在构建基于 JWT 的身份验证系统. JWT已过期。当JWT过期,我 catch JWT使用 apollo-link-error 的过期错误.我想调用 apolloClient.resetStor
Apollo 文档 discusses the use of cacheRedirects 告诉 Apollo 如何从其他查询访问缓存中的数据。 它给出了一个例子: In some cases, a
react-apollo的Query组件可以使用Recompose吗? ? https://www.apollographql.com/docs/react/essentials/queries.ht
我正在尝试从“ apollo-server”更新:“^2.9.4”和 “阿波罗服务器 express ” :“^2.9.4”到 2.12.0 版本 在 typescript 中,在应用程序的构建过程中
http://dev.apollodata.com/react/mutations.html 我正在尝试使用 optimisticResponse,但我很困惑...无法让它在我的本地运行。 我的问题是
我正在制作一个社交网站。当任何用户在站点上更新或创建新内容时,我需要查看站点的任何其他用户来查看更改更新。 我有一些需要低延迟的评论,因此建议为此订阅。 我也有事件,但这些不需要这么低的延迟。每 10
我在一个简单的 React 应用程序中使用最新版本的 Apollo Client,我试图从用于显示返回的记录集大小的响应中提取 header 值。 我很欣赏这不是提供结果集大小的最优雅的方式,但这就是
我想在突变后使用乐观 UI 更新:https://www.apollographql.com/docs/react/basics/mutations.html 我对“乐观响应”和“更新”之间的关系感到
在 Apollo 服务器中,当客户端用户订阅订阅(使用 WebSocket)时,我们可以使用订阅解析器检测到这一点。 但是有没有办法检测取消订阅? 我看到 WebSocket 发送了一个 {"id":
我创建这个问题是为了防止有人对如何在 Apollo 中添加 union/多态类型感到好奇。希望这会让他们更容易。 在此示例中,我希望响应为 Worksheet 或 ApiError // typede
我的项目目录结构是这样的: - schema.graphql - package.json - packages -- types --- package.json --- src ---- grap
我想知道当订阅接收到新数据时是否有一种优雅的方式来触发react-apollo中查询的重新获取(数据在这里并不重要,将与前一个相同)。我只是在这里使用订阅作为通知触发器,告诉 Query 重新获取。
我使用 Apollo、React 和 Graphcool。我有一个查询来获取登录的用户 ID: const LoginServerQuery = gql` query LoginServerQ
出于分析目的,我想跟踪所有 graphql 操作的客户端(包括 @client 操作)。我无法在 API 中找到合适的选项,想知道这在 apollo 客户端级别是否可行,或者我是否需要引入一些代理来拦
我是一名优秀的程序员,十分优秀!