React-apollo: Issue when 'id' field in query data is null

Created on 9 Apr 2018  路  5Comments  路  Source: apollographql/react-apollo

Query:

    OperationLogList(input:$input){
        list {
            requestId
            userId

            source{
                id
                type
                children{
                    id
                    type
                }
            }

            destination{
                id
                type
                children{
                    id
                    type
                }
            }



        }
    }
}

GraphQL Server is returning the correct data even if source.id=null or destination.id=null But const withQuery = graphql(OPS_LOG_QUERY, {
props: function (data) {
console.log(data)
return data
},
options: ({match, location}) => ({
variables: {},
fetchPolicy: 'network-only'
}),
});

data returned in withQuery component is correct. I guess there'd be a problem with 'id' field being null as the props object having Symbol(id): OperationLogSource:null . Any soultion/hack to fix the issue?

All 5 comments

I have the same issue. Can anyone chime on this?

I'm getting the same problem here, if I have an id field and this field returns null, then the data prop returns the wrong data even though we have the correct data in the network request.

I have also same problem. i am using client.query({query: .., variables: ..}) method to fetch data.

Closing - housekeeping

If your id is null, you'll want to have your cache use some other key in your object to index against. See
https://www.apollographql.com/docs/react/advanced/caching#normalization

The other way is to set your fetchPolicy for the query to "no-cache" so that it bypasses InMemoryCache.

Was this page helpful?
0 / 5 - 0 ratings