httpapolloapollo-clientapollo-serverapp-transport-security

Cannot connect to GraphQL server using Apollo-Client HttpLink


Running on simulator.

Error: Network error: Network request failed
    at new ApolloError (bundle.umd.js:92)
    at Object.error (bundle.umd.js:1323)
    at notifySubscription (Observable.js:134)
    at onNotify (Observable.js:165)
    at SubscriptionObserver.error (Observable.js:224)
    at bundle.umd.js:1100
    at Set.forEach (<anonymous>)
    at Object.error (bundle.umd.js:1099)
    at notifySubscription (Observable.js:134)
    at onNotify (Observable.js:165)
import ApolloClient, { gql, HttpLink, ApolloLink , concat } from "apollo-boost";
const httpLink = new HttpLink({ 
    uri: 'http://localhost:4000' 
});
const client = new ApolloClient({ 
    link:  httpLink, //using uri: 'http://localhost:4000' works.
});
"apollo-boost": "^0.4.3",
"react-apollo": "^2.5.8",
"graphql": "^14.4.2",
        <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>

Solution

  • Apollo Boost explicitly does not accept links. It's meant to be a quick way to get started with Apollo Client without downloading all packages normally needed. Apollo Boost creates all your links for you under the hood. If you want to explicitly define them yourself, migrate to the regular client.