infinitered / ignite-andross

The original React Native boilerplate from Infinite Red - Redux, React Navigation, & more
https://infinite.red/ignite
MIT License
474 stars 150 forks source link

Error occurred when using with Apollo: Cannot read property 'data' of null #283

Open vfa-tienhnm-os opened 5 years ago

vfa-tienhnm-os commented 5 years ago

Hello all!

I'm having trouble using ignite with apollo graphql.

I'm also not sure if this error of ignite or apollo, but when I use react-native init to create the project, the apollo works as expected.

The problem only occurs on Android, when I turn off the graphQL server (create network error), the application will appear a red screen when cannot query to server.

Screenshot_1562320865

Steps to reproduce

  1. Create new ignite project
  2. Install apollo-boost, react-apollo and graphql
  3. This is the content of the file App.js:
    
    import React from 'react'
    import { Text } from 'react-native'
    import ApolloClient, { gql } from 'apollo-boost'
    import { ApolloProvider, Query } from 'react-apollo'

const client = new ApolloClient({ uri: 'http://192.168.4.111:4000' })

const READ_TODOS = gql query {a readTodos { id, title, completed } }

export default DemoScreen = () => { return (

{({ loading, error, data }) => { if (loading) return Loading... if (error) return Error :( return data.readTodos.map(({ id, title }) => ( {title} )) }}
);

}

4. Make sure that graphQL server is turned off and run project on Android
## `ignite doctor` results:

System platform darwin

arch x64
cpu 4 cores Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz directory /Users/tienhnm/Workspaces/corporation4d

JavaScript node 10.16.0 /usr/local/bin/node npm 6.9.2 /usr/local/bin/npm
yarn 1.16.0 /usr/local/bin/yarn

React Native react-native-cli 2.0.1
app rn version 0.59.3

Ignite ignite-cli 3.1.3 /usr/local/bin/ignite createdWith 3.1.3
boilerplate ignite-andross
examples classic
navigation react-navigation
askToOverwrite true
generators {"component":"ignite-andross","container":"ignite-andross","listview":"ignite-andross","list":"ignite-andross","redux":"ignite-andross","saga":"ignite-andross","screen":"ignite-andross"}
boilerplateVersion 4.0.5

Android java 1.8.0_212 /usr/bin/java
android home - /Users/tienhnm/Library/Android/sdk

iOS xcode 10.1

jamonholmgren commented 5 years ago

Hey @vfa-tienhnm-os , thanks for the issue! We'd love a PR from the community, as we're focused on Bowser currently.