在IOS上,应用程序运行正常。但在Android上,我得到了这个错误。这是我在客户端和服务器端的配置。请帮帮我!
错误:Error image
以下是客户端的配置:
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
发布于 2018-03-15 19:07:05
基本上,您必须将lochalhost替换为您计算机的IP地址。此问题已在此处报告,https://github.com/apollographql/apollo-client/issues/1757
要检查您的IP地址,请参阅此视频https://www.youtube.com/watch?v=TRFtQzx0Y0M
发布于 2017-09-03 01:42:51
我也有同样的问题,我在这里找到了我的解决方案https://github.com/apollographql/apollo-client/issues/1757
基本上,您需要在createNetworkInterface函数中使用计算机的ip地址,因此请更改以下内容:
const networkInterface = createNetworkInterface({ uri: 'http://localhost:3000/graphql' });要这样做:
const networkInterface = createNetworkInterface({ uri: 'http://YOURIPADDRESS:3000/graphql' });发布于 2018-06-07 17:24:00
由于我是在模拟器上工作,因此将localhost更改为127.0.0.1对我很有效:
const link = new HttpLink({ uri: 'http://127.0.0.1:3500/graphql' });
const client = new ApolloClient({
link,
cache
})https://stackoverflow.com/questions/45455877
复制相似问题