Why graphql query doesn't work in react?


Andre Mello

Second response errorIn my React project, I use query to search github user data. The query is as follows:

const GET_USER = (user) => `
{
  user(login: "${user}") {
    name
    login
    avatarUrl
    company
    gists{
     totalCount
   }
   following{
      totalCount
    }
    followers(last: 5){
      edges{
            node{
                id
            name
            avatarUrl
        }
      }
    }
    repositories(last: 5){
      edges{
        node{
          id
          name
        }
      }
    }
  }
}
`;

If I update the query by just adding a single field called emailin the followersreact app it stops working:


followers(last: 5){
      edges{
            node{
            id
            name
            avatarUrl
            email
        }
      }
    }

The same happens if I add data about the organization to the query, like this:

 organizations(last: 5){
      edges{
        node{
          id
          name
        }
      }
    }

However, when I do the same query in this link: [ https://developer.github.com/v4/explorer/] it works.

My react project is in the link: [ https://github.com/rvmelo/react-tech6-final-project] . Queries are in App.jsfiles inside srcfolders .

first-response error

Tico

It stopped working because the user might not have such information.

I cloned your repo and added the code

<div>email:{user.following.email}</div>

It did stop working then I added a fallback

<div>email:{user.following.email || ""}</div>

It worked.

You might want to check this information before rendering, e.g.

{user && user.following && user.following.email &&
  (<div>email:{user.following.email}</div>)
}

The same thingorganizations

<p>
  {user && user.organizations &&
    <div>Organization name:{user.organizations.name}</div>
  }
</p>

As for followers( updated )

const Followers = ({ followers }) => (
<div>

  <strong>Followers updated for SO:</strong>

  <ul>
    {followers.edges.map(follower => (
    <li key={follower.node.id}>
      <img src={follower.node.avatarUrl}/>
      <div>
        {follower && follower.node && follower.node.name && (
        <div>Name:{follower.node.name}</div>) }
      </div>
      <div>
        {follower && follower.node && follower.node.email && (
        <div>Email:{follower.node.email}</div>) }
      </div>
    </li>
    ))}
  </ul>
</div>
);

Screenshot of my profile. One has email followers, the other doesn't.enter image description here

I went ahead and forked your repo, which is a clone of my repo from your question. Make sure your token has the permissions. On a whim, I can totally use my keys. Check yours!

Related


Why graphql query doesn't work in react?

Andre Mello In my React project, I use query to search github user data. The query is as follows: const GET_USER = (user) => ` { user(login: "${user}") { name login avatarUrl company gists{ totalCount } following{ totalCo

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

Why scalar date GraphQL doesn't work

Ramzan Chasygov graphqlI need to provide date ideas in a project I'm using graphql, when I use type date Stringcorrectly in the parser it shows the date, but when I use it scalar Datein the parser I get an falseinteger date. Couldn't find anything in the docum

why this query doesn't work

Nicoletta Sotiri I'm new to SQL so I don't understand why this query doesn't work. Thank you in advance CREATE VIEW temp AS SELECT return_date_time, renting_date_time FROM renting; CREATE TRIGGER charge_calc AFTER UPDATE ON renting.return_date_time FOR EACH R

Why doesn't this query work?

username Why does the following query not work in SQL Server 2008? SELECT CONVERT(INT, TEMP.observ_value) AS value FROM (SELECT observ_value FROM LAB_RESULTS WHERE observ_value NOT LIKE '%[^0-9]%') TEMP WHERE observ_value >= 190 Her

Why doesn't this query work?

username Why does the following query not work in SQL Server 2008? SELECT CONVERT(INT, TEMP.observ_value) AS value FROM (SELECT observ_value FROM LAB_RESULTS WHERE observ_value NOT LIKE '%[^0-9]%') TEMP WHERE observ_value >= 190 Her

Why FireStore where query doesn't work?

TSR FireStore whereis not working, or I am doing something wrong. I am trying to email the user:[email protected] Here is the code: const admin = require('firebase-admin'); var serviceAccount = require('../secret/nicecode-e3e53-2ddaa9d588ea.json'); admin.ini

Why doesn't Solr query work on spaces?

Aswin Raghavan I'm a beginner in Solr and have the following set of indexes in my Soleserver: { "id": "book5", "title": [ "Five point someone" ], "author": "Chetan Bagat", "genere": "fantasy", "de