1

I keep geting this error:

Error: GraphQL error: Not Authorized!

Code is:

const queries = gql`
  query {
    mystreak
  }
`;

  render() {
    return (
      <Query query={queries}>
        {({ loading, error, data }) => {
          console.log(loading);
          console.log(error);
          console.log(data.mystreak);
        }}
      </Query>
)
}

App is built in React.js, and I am pretty new to GraphQL.

Also data is undefined.

Any ideas?

Thanks in advance

JozeV
  • 616
  • 3
  • 14
  • 27

2 Answers2

2

I'm guessing you use Apollo. We are lacking a lot of information, especially regarding your backend, but it looks like you are missing an Authorization header in your http requests:

https://www.apollographql.com/docs/link/links/http.html#options

const link = createHttpLink({
    uri: "/graphql",
    headers: {
        Authorization: 'Bearer <your token here>'
    }
});

Check the documentation of your backend for the token value.

Komo
  • 2,043
  • 1
  • 22
  • 35
0

I solved this issue by removing eas: projectId from app.json:

"extra": {
  "eas": {
    "projectId": "a1b2c3d4-e5f6-g7h8i9-j1k2-l3m4n5o6p7"
  }
}

I need a build for development, the company's Expo project ID is different than my account's project ID, thus the problem...

Caio Mar
  • 2,344
  • 5
  • 31
  • 37