反应本机Apollo错误:“网络错误:网络请求失败"; [英] React Native Apollo error: "Network error: Network request failed"

查看:84
本文介绍了反应本机Apollo错误:“网络错误:网络请求失败";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IOS上,应用程序正确运行.但是在Android上,我收到此错误.这是我在客户端和服务器中的配置.请帮忙!

On IOS, the application runs correctly. But on Android I get this error. Here's my config in client and server. Please help!

错误:错误图片

这是客户端上的配置:

import ApolloClient, { createNetworkInterface } from 'apollo-client';
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws';

const networkInterface = createNetworkInterface({ uri: 'http://localhost:3000/graphql' });

const wsClient = new SubscriptionClient('ws://localhost:3000/subscriptions', {
  reconnect: true,
});

const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
  networkInterface,
  wsClient,
);

export const client = new ApolloClient({
  networkInterface: networkInterfaceWithSubscriptions,
});

这是服务器上的配置:

import express from 'express';
import {
  graphqlExpress,
  graphiqlExpress,
} from 'graphql-server-express';
import bodyParser from 'body-parser';
import cors from 'cors';
import { execute, subscribe } from 'graphql';
import { createServer } from 'http';
import { SubscriptionServer } from 'subscriptions-transport-ws';
import { schema } from './schema';

const PORT = 3000;
const server = express();

server.use('*', cors({ origin: 'http://localhost:8081' }));
server.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
server.use('/graphiql', graphiqlExpress({
  endpointURL: '/graphql',
  subscriptionsEndpoint: 'ws://localhost:3000/subscriptions',
}));

// We wrap the express server so that we can attach the WebSocket for subscriptions
const ws = createServer(server);
ws.listen(PORT, () => {
  console.log('GraphQL Server is running');
  // Set up the WebSocket for handling GraphQL subscriptions
  new SubscriptionServer({
    execute,
    subscribe,
    schema
  }, {
    server: ws,
    path: '/subscriptions',
  });
});

我正在使用react-apollo:1.4.10,apollo-client:1.9.0-0

I'm using react-apollo: 1.4.10, apollo-client: 1.9.0-0

推荐答案

基本上,您必须用计算机的IP地址替换lochalhost.该问题在这里重新提出, https://github.com/apollographql/apollo-client/第/1757期

Basically, you have to replace lochalhost with your machine's IP address. The issue was reporeted here, https://github.com/apollographql/apollo-client/issues/1757

要检查您的IP地址,请参阅此视频 https://www.youtube.com/watch?v = TRFtQzx0Y0M

To check your IP address, refer to this video https://www.youtube.com/watch?v=TRFtQzx0Y0M

这篇关于反应本机Apollo错误:“网络错误:网络请求失败";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆