graphql-engine/community/tools/ra-data-hasura
nizar-m f83a8e591f rename access-key to admin-secret (close #1347) (#1540)
Rename the admin secret key header used to access GraphQL engine from X-Hasura-Access-Key to X-Hasura-Admin-Secret.

Server CLI and console all support the older flag but marks it as deprecated.
2019-02-14 15:07:47 +05:30
..
src support any type for id column in ra-data-hasura (close #1443) (#1451) 2019-01-24 09:36:45 +05:30
.babelrc add react-admin data provider (close #783) (#1407) 2019-01-19 20:49:35 +05:30
.eslintrc add react-admin data provider (close #783) (#1407) 2019-01-19 20:49:35 +05:30
.gitignore add react-admin data provider (close #783) (#1407) 2019-01-19 20:49:35 +05:30
App.js.example.js add react-admin data provider (close #783) (#1407) 2019-01-19 20:49:35 +05:30
CHANGELOG.md support any type for id column in ra-data-hasura (close #1443) (#1451) 2019-01-24 09:36:45 +05:30
package-lock.json support any type for id column in ra-data-hasura (close #1443) (#1451) 2019-01-24 09:36:45 +05:30
package.json support any type for id column in ra-data-hasura (close #1443) (#1451) 2019-01-24 09:36:45 +05:30
README.md rename access-key to admin-secret (close #1347) (#1540) 2019-02-14 15:07:47 +05:30
webpack.config.js add react-admin data provider (close #783) (#1407) 2019-01-19 20:49:35 +05:30

ra-data-hasura

react-admin data provider for Hasura GraphQL Engine

Installation

$ npm install --save ra-data-hasura

Usage

The ra-data-hasura provider accepts two arguments:

  • serverEndpoint - The URL at which Hasura GraphQL Engine is running. (for example: http://localhost:8080). This is required.

  • headers - An optional argument. Pass your auth headers here.

hasuraDataProvider(serverEndpoint, headers)

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.

import React from 'react';
import PostIcon from '@material-ui/icons/Book';
import UserIcon from '@material-ui/icons/Group';
import { Admin, Resource, ListGuesser } from 'react-admin';
import hasuraDataProvider from 'ra-data-hasura';

import { PostList, PostEdit, PostCreate, PostShow } from './posts';
import { UserList } from './users';
import Dashboard from './Dashboard';
import authProvider from './authProvider';

const headers = {'content-type': 'application/json', 'authorization': 'bearer <token>'};
const App = () => (
  <Admin
    dataProvider={hasuraDataProvider('http://localhost:8080', headers)}
    authProvider={authProvider}
    dashboard={Dashboard}
  >
    <Resource
      name="posts"
      icon={PostIcon}
      list={PostList}
      edit={PostEdit}
      create={PostCreate}
      show={PostShow}
    />
    <Resource name="users" icon={UserIcon} list={UserList} />
    <Resource name="comments" list={ListGuesser} />
  </Admin>
);

export default App;

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

Known Issues

Filter as you type (search) functionality inside tables is not supported right now. It is a work in progress.

Contributing

To modify, extend and test this package locally,

$ cd ra-data-hasura
$ npm run link

Now use this local package in your react app for testing

$ cd my-react-app
$ npm link ra-data-hasura

Build the library by running npm run build and it will generate the transpiled version of the library under lib folder.