-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (51 loc) · 1.77 KB
/
index.js
File metadata and controls
61 lines (51 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import { App } from './App'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import pluralize from 'pluralize'
import { GET_LIST, GET_ONE, GET_MANY, GET_MANY_REFERENCE, CREATE, UPDATE, DELETE, DELETE_MANY } from 'react-admin'
import { queryBuilder } from './query-builder'
const link = new HttpLink({ uri: 'http://localhost:3421' })
const cache = new InMemoryCache()
const client = new ApolloClient({ cache, link })
const operationName = fn => ({ name }) => fn({ singular: name, name, plural: pluralize(name) })
const introspection = {
operationNames: {
[CREATE]: operationName(({ name }) => `create${name}`),
[DELETE]: operationName(({ plural }) => `delete${plural}`),
[DELETE_MANY]: operationName(({ plural }) => `delete${plural}`),
[GET_LIST]: operationName(({ plural }) => plural),
[GET_MANY]: operationName(({ plural }) => plural),
[GET_MANY_REFERENCE]: operationName(({ plural }) => plural),
[GET_ONE]: operationName(({ singular }) => singular),
[UPDATE]: operationName(({ name }) => `update${name}`),
},
exclude: undefined,
include: undefined,
}
class DataProvider extends React.Component {
constructor() {
super()
this.state = { dataProvider: null }
}
componentDidMount() {
queryBuilder({
client,
introspection,
}).then(dataProvider => {
this.setState({ dataProvider })
})
}
render() {
const { dataProvider } = this.state
if (!dataProvider) {
return <div>Loading</div>
}
return <App dataProvider={dataProvider} />
}
}
ReactDOM.render(<DataProvider />, document.getElementById('root'))
// registerServiceWorker()