Auf IOS wird die Anwendung ordnungsgemäß ausgeführt. Aber auf Android bekomme ich diesen Fehler. Hier ist meine Konfiguration in Client und Server. Bitte helfen Sie!Reactive Native Apollo Fehler: "Netzwerkfehler: Netzwerkanforderung fehlgeschlagen"
Fehler: Error image
Hier ist die Konfiguration auf dem Client:
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,
});
Hier ist die Konfiguration auf dem Server:
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',
});
});
ich reagieren-apollo mit: 1.4.10, apollo-client: 1.9.0-0
Ich habe versucht, die IP-Adresse einstellen Es funktioniert auf einem echten Gerät. Aber auf Android-Emulator funktioniert es nicht. – linhnh
Aah yeah, tut mir leid, ich habe vergessen zu erwähnen, dass ich ein echtes Gerät benutzt habe. – Yellowhill