diff --git a/client/src/apollo/client.ts b/client/src/apollo/client.ts new file mode 100644 index 0000000..4bd2d72 --- /dev/null +++ b/client/src/apollo/client.ts @@ -0,0 +1,9 @@ +import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'; + +//GraphQL server address. Override with VITE_GRAPHQL_URL in .env (e.g. on the VM) +const uri = import.meta.env.VITE_GRAPHQL_URL ?? 'http://localhost:3001/graphql'; + +export const client = new ApolloClient({ + link: new HttpLink({ uri }), //how requests reach the server + cache: new InMemoryCache(), //where query results are stored +}); diff --git a/client/src/main.tsx b/client/src/main.tsx index 57df51d..14f640d 100644 --- a/client/src/main.tsx +++ b/client/src/main.tsx @@ -1,10 +1,15 @@ import { StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; +import { ApolloProvider } from '@apollo/client/react'; +import { client } from './apollo/client'; import './styles/index.css'; import { App } from './App.tsx'; createRoot(document.getElementById('root')!).render( - + {/*makes the GraphQL client available for every component*/} + + + , );