Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

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

Open
vfa-tienhnm-os opened this issue Jul 8, 2019 · 1 comment

Comments

@vfa-tienhnm-os
Copy link

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 (
        <ApolloProvider client={client}>
            <Query query={READ_TODOS}>
                {({ loading, error, data }) => {
                    if (loading) return <Text>Loading...</Text>
                    if (error) return <Text>Error :(</Text>
                    return data.readTodos.map(({ id, title }) => (
                        <Text key={id}>{title}</Text>
                    ))
                }}
            </Query>
        </ApolloProvider>
    );
}
  1. 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 jamonholmgren transferred this issue from infinitered/ignite Jul 14, 2019
@jamonholmgren
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants