Skip to content

Commit

Permalink
ra-data-hasura: filter for count query, add httpClient (close #2100, #…
Browse files Browse the repository at this point in the history
…2741, #2771) (#2727)

* filter for count in GET_LIST and GET_MANY_REFERENCE

* update deps, add httpClient argument, release new version
  • Loading branch information
praveenweb authored and shahidhk committed Sep 18, 2019
1 parent 3b5886e commit 0a64ef9
Show file tree
Hide file tree
Showing 5 changed files with 1,530 additions and 1,647 deletions.
6 changes: 6 additions & 0 deletions community/tools/ra-data-hasura/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.7 (September 17, 2019)

- Bug Fix: Re-build library to fix discrepancies. Pass `where` arguments to `count` query.
- Feature: Add support for httpClient to pass in dynamic headers. Backwards compatibility maintained for static headers.
- Update package dependencies.

## 0.0.6 (June 14, 2019)

- Bug Fix: Fix sort order, fix primary key when response not an array and add filters to GET_* operations.
Expand Down
20 changes: 18 additions & 2 deletions community/tools/ra-data-hasura/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ The `ra-data-hasura` provider accepts three arguments:

- `serverEndpoint` - The URL at which Hasura GraphQL Engine is running. (for example: http://localhost:8080). This is required. It should also expose `/v1/query` endpoint.

- `headers` - An optional argument. Pass your auth headers here.
- `httpClient` - HTTP Client function. To maintain backwards compatibility the `headers` object is supported.

- `config` - An optional argument. Pass your config here.

```
hasuraDataProvider(serverEndpoint, headers, config)
hasuraDataProvider(serverEndpoint, httpClient, config)
```

In the following example, we import `hasuraDataProvider` from `ra-data-hasura` and give it the hasura server endpoint (assumed to be running at http://localhost:8080) and an optional headers object.
Expand Down Expand Up @@ -62,6 +62,22 @@ export default App;

In case the server is configured with admin secret or auth, configure the appropriate headers and pass it to the provider.

### Adding Custom Headers

The above example showed a simple use case of adding static headers. In order to update headers dynamically, the data provider accepts an HTTP client function as the second argument. It uses react-admin's fetchUtils.fetchJson() as HTTP client. Hence to add custom headers to your requests, you just need to wrap the `fetchUtils.fetchJson()` call inside your own function:

```javascript
const httpClient = (url, options = {}) => {
if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' });
}
// add your own headers here
options.headers.set('Authorization', 'Bearer xxxxx');
return fetchUtils.fetchJson(url, options);
};
const dataProvider = hasuraDataProvider('http://localhost:8080', httpClient);
```

### Multiple schemas

To query schemas other than `public`, you can pass schema to resource in the format
Expand Down
Loading

0 comments on commit 0a64ef9

Please sign in to comment.