2021-02-03 11:49:51 -08:00
|
|
|
import React, { useMemo } from 'react';
|
2021-01-17 12:54:49 -08:00
|
|
|
import { BrowserRouter as Router } from 'react-router-dom';
|
|
|
|
import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client';
|
|
|
|
import { MockedProvider } from '@apollo/client/testing';
|
|
|
|
import './App.css';
|
|
|
|
import { Routes } from './components/Routes';
|
|
|
|
import { mocks } from './Mocks';
|
2021-02-03 11:49:51 -08:00
|
|
|
import EntityRegistry from './components/entity/EntityRegistry';
|
|
|
|
import { DatasetEntity } from './components/entity/dataset/DatasetEntity';
|
|
|
|
import { UserEntity } from './components/entity/user/User';
|
|
|
|
import { EntityRegistryContext } from './entityRegistryContext';
|
2021-01-17 12:54:49 -08:00
|
|
|
|
|
|
|
// Enable to use the Apollo MockProvider instead of a real HTTP client
|
|
|
|
const MOCK_MODE = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Construct Apollo Client
|
|
|
|
*/
|
|
|
|
const client = new ApolloClient({
|
|
|
|
uri: 'http://localhost:9001/api/v2/graphql',
|
|
|
|
cache: new InMemoryCache({
|
|
|
|
typePolicies: {
|
|
|
|
Dataset: {
|
|
|
|
keyFields: ['urn'], // TODO: Set this as the default across the app.
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
credentials: 'include',
|
|
|
|
});
|
|
|
|
|
|
|
|
const App: React.VFC = () => {
|
2021-02-05 12:56:07 -08:00
|
|
|
// TODO: Explore options to dynamically configure this.
|
2021-02-03 11:49:51 -08:00
|
|
|
const entityRegistry = useMemo(() => {
|
|
|
|
const register = new EntityRegistry();
|
|
|
|
register.register(new DatasetEntity());
|
|
|
|
register.register(new UserEntity());
|
|
|
|
return register;
|
|
|
|
}, []);
|
2021-01-17 12:54:49 -08:00
|
|
|
return (
|
|
|
|
<Router>
|
2021-02-03 11:49:51 -08:00
|
|
|
<EntityRegistryContext.Provider value={entityRegistry}>
|
|
|
|
{/* Temporary: For local testing during development. */}
|
|
|
|
{MOCK_MODE ? (
|
|
|
|
<MockedProvider mocks={mocks} addTypename={false}>
|
|
|
|
<Routes />
|
|
|
|
</MockedProvider>
|
|
|
|
) : (
|
|
|
|
<ApolloProvider client={client}>
|
|
|
|
<Routes />
|
|
|
|
</ApolloProvider>
|
|
|
|
)}
|
|
|
|
</EntityRegistryContext.Provider>
|
2021-01-17 12:54:49 -08:00
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|