Search code examples
react-admin

react-admin ra-data-graphql-simple example and json-graphql-server


I followed the instructions to setup a react-admin + graphql proof-of-concept by using help from here - https://www.npmjs.com/package/ra-data-graphql-simple and here - https://github.com/marmelab/json-graphql-server

I'm running the json-graphql-server db.js

I seem to run into issues in getting this working -

$ create-react-app test-admin
$ cd test-admin
$ yarn add react-admin
$ yarn add graphql ra-data-graphql-simple

I then update App.js with code as shown in the ra-data-graphql-simple example and create posts.js from react-admin tutotial.

On running yarn start I get -

./src/App.js
 Line 7:  'ApolloClient' is not defined  no-undef

Does anyone know how to get the example working?


Solution

  • This worked with the example -

    import buildGraphQLProvider from 'ra-data-graphql-simple';
    import { Admin, Resource, Delete } from 'react-admin';
    import { PostCreate, PostEdit, PostList } from './posts';
    
    class App extends Component {
        constructor() {
            super();
            this.state = { dataProvider: null };
        }
    
        componentDidMount() {
            buildGraphQLProvider({ clientOptions: { uri: 'http://localhost:3000' }})
                .then(dataProvider => this.setState({ dataProvider }));
        }
    
        render() {
            const { dataProvider } = this.state;
    
            if (!dataProvider) {
                return <div>Loading</div>;
            }
    
            return (
                <Admin dataProvider={dataProvider}>
                    <Resource name="Post" list={PostList} edit={PostEdit} create={PostCreate} remove={Delete} />
                </Admin>
            );
        }
    }
    
    export default App;