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
  • 440
  • 1
  • 10
  • 23

1 Answers1

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
  • 1,902
  • 20
  • 34