q3e / react-native-github-graphql-app

React Native App that searches github projects and their contributors[WIP]
MIT License
2 stars 0 forks source link

Cant get Query response into data prop when using react-apollo HoC wrapper #8

Closed q3e closed 6 years ago

q3e commented 6 years ago

The RepoOwnerProfile component that renders a github user profile. The apollo HoC wrapper did inject the correct query variable. However doesnt make sense why user is missing from the data For example if the variable is facebook, its successfully added to the data prop from the query fetch but query results don't contain the actual user profile of facebook image

` import React from 'react' import { View, Text } from 'react-native' import gql from 'graphql-tag' import { graphql } from 'react-apollo'

const RepoOwnerProfile = ({ data, navigation: { state: { params: { username } } } }) => { console.log(data) return Profile @{username}

}

const getUserProfile = gql query getUserProfile($login:String!){ user(login: $login) { name bio avatarUrl followers { totalCount } starredRepositories { totalCount } following{ totalCount } repositories{ totalCount } } }

export default graphql(getUserProfile, { options: ({ navigation: { state: { params: { username }}} }) => ({ variables: { login: username } }), notifyOnNetworkStatusChange: true })(RepoOwnerProfile) `

q3e commented 6 years ago

Question on SO https://stackoverflow.com/questions/47023644/how-to-query-2-endpoints-in-graphql-and-ignore-one-when-wrapping-with-react-apol

q3e commented 6 years ago

Similar issue https://github.com/apollographql/react-docs/issues/56

q3e commented 6 years ago

A good SO answer https://stackoverflow.com/questions/43380704/react-apollo-make-multiple-queries

q3e commented 6 years ago

even if using 2 queries and fetching at the same time. it still would show the error because for every user search, there is an organization search error

graphql(
    queries.fetchUser,
    {
      name: "fetchUser",
      options: ({ navigation: { state: { params: { username }}} }) => ({ variables: { login: username } }),
      notifyOnNetworkStatusChange: true
    }
  ),
graphql(
  // the GraphQL document
  queries.fetchOrg,
  // the config object
  {
    name: "fetchOrg", // attaches response of this query to props of component not the general data prop
    // compute options from props - query variable computed from the navigation prop
    options: ({ navigation: { state: { params: { username }}} }) => ({ variables: { login: username } }),
    notifyOnNetworkStatusChange: true
  }
)
q3e commented 6 years ago

Just learned that there is a __typename node in REPOSITORY search query for github API. That should close this flippin issue. Coming ...

q3e commented 6 years ago

fixed by https://github.com/bnovf/react-native-github-graphql-app/commit/805bc56050e71afd6eeb05839433700e67d3db24