-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Sets up [Apollo Client](https://www.apollographql.com/docs/react/) for the frontend's GraphQL client. This sets up: - Apollo client with in memory cache - Sets up codegen tool for generating TypeScript types from the GraphQL schema - Implements example of fetching GraphQL data on `/datasets` route
- Loading branch information
1 parent
1709ab6
commit 1e18a16
Showing
10 changed files
with
2,158 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
__generated__ | ||
.env.example | ||
.eslintignore | ||
.gitignore | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
__generated__ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
__generated__/ | ||
build/ | ||
public/build/ | ||
pnpm-lock.yaml | ||
public/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.cache/ | ||
app/__generated__ | ||
app/**/*.module.css.d.ts | ||
build/ | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client' | ||
|
||
import { ENVIRONMENT_CONTEXT_DEFAULT_VALUE } from './context/Environment.context' | ||
|
||
export const apolloClient = new ApolloClient({ | ||
ssrMode: true, | ||
cache: new InMemoryCache(), | ||
link: createHttpLink({ | ||
uri: process.env.API_URL ?? ENVIRONMENT_CONTEXT_DEFAULT_VALUE.API_URL, | ||
}), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
import { useLoaderData } from '@remix-run/react' | ||
import { json } from '@remix-run/server-runtime' | ||
import { useEffect } from 'react' | ||
|
||
import { gql } from 'app/__generated__' | ||
import { apolloClient } from 'app/apollo.server' | ||
import { Demo } from 'app/components/Demo' | ||
|
||
const GET_ALL_DATASETS_QUERY = gql(` | ||
query GetDatasets { | ||
datasets { | ||
authors { | ||
name | ||
} | ||
} | ||
} | ||
`) | ||
|
||
export async function loader() { | ||
const { data } = await apolloClient.query({ | ||
query: GET_ALL_DATASETS_QUERY, | ||
}) | ||
|
||
return json(data.datasets) | ||
} | ||
|
||
export default function AllDatasetsPage() { | ||
const data = useLoaderData<typeof loader>() | ||
|
||
useEffect(() => { | ||
console.log('dataset authors', data) | ||
}, [data]) | ||
|
||
return <Demo>All Datasets Page</Demo> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CodegenConfig } from '@graphql-codegen/cli' | ||
|
||
const SCHEMA_URL = | ||
process.env.API_URL || | ||
'https://graphql.cryoetdataportal.cziscience.com/v1/graphql' | ||
|
||
const config: CodegenConfig = { | ||
schema: SCHEMA_URL, | ||
documents: ['app/**/*.{ts,tsx}'], | ||
generates: { | ||
'./app/__generated__/': { | ||
preset: 'client', | ||
plugins: [], | ||
presetConfig: { | ||
gqlTagName: 'gql', | ||
}, | ||
}, | ||
}, | ||
ignoreNoDocuments: true, | ||
} | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.