Steams / ra-data-hasura-graphql

React-admin data provider for Hasura GraphQL endpoints
MIT License
211 stars 33 forks source link

Doc improvement: Passing headers in the GraphQL requests #45

Closed csadai closed 4 years ago

csadai commented 4 years ago

Hi,

I've read the README which invites me to create a dedicated Apollo Boost instantiation in order to pass some headers to my requests.

It's actually possible to pass those using the default connection, by supplying a GraphQL-Link object in lieu of the uri parameter.

e.g.

import { HttpLink } from 'apollo-link-http'
(....)
 componentDidMount() {
    buildHasuraProvider({
      clientOptions: {
        link: new HttpLink({
          uri: "http://localhost:8080/v1/graphql",
          headers: {
            "x-hasura-admin-secret": "my-password",
          }
        })
      }
    })
    .then(dataProvider => this.setState({ dataProvider }));
}

You may want to update the documentation with it, as it's probably easier than redoing the whole connection (handling cache, etc.)

webdeb commented 4 years ago

Its already there: https://github.com/Steams/ra-data-hasura-graphql#customize-the-apollo-client

webdeb commented 4 years ago

Probably making the word "otherApolloOptions" to be a link to https://www.apollographql.com/docs/react/api/apollo-client/#ApolloClientOptions is a good idea.

csadai commented 4 years ago

Yes, but as stated in my ticket, the recommendation to bring your own client is overkill, when you can benefit from all the underlying client of ra-data-graphql by just providing a httpLink. This is not a bug nor a problem, just a recommendation for those finding this ticket while searching for something simpler.

csadai commented 4 years ago

Probably making the word "otherApolloOptions" to be a link to https://www.apollographql.com/docs/react/api/apollo-client/#ApolloClientOptions is a good idea.

Absolutely