Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prep FE codebase for 2 API URLs #1126

Merged
merged 13 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/frontend-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ jobs:
working-directory: frontend/packages/data-portal
env:
API_URL: ${{ vars.API_URL }}
API_URL_V2: ${{ vars.API_URL_V2 }}
ENV: ${{ inputs.environment }}

- name: Run E2E tests
run: pnpm e2e --shard ${{ matrix.shardCurrent }}/${{ matrix.shardTotal }}
working-directory: frontend/packages/data-portal
env:
API_URL: ${{ vars.API_URL }}
API_URL_V2: ${{ vars.API_URL_V2 }}
E2E_BROWSER: ${{ matrix.browser }}
E2E_CONFIG: ${{ secrets.E2E_CONFIG }}
CI: true
Expand Down
1 change: 1 addition & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__generated__
__generated_v2__
.env.example
.eslintignore
.gitignore
Expand Down
1 change: 1 addition & 0 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
API_URL=https://graphql-cryoet-api.cryoet.prod.si.czi.technology/v1/graphql
API_URL_V2=https://graphql.cryoetdataportal.czscience.com/graphql
CLOUDWATCH_RUM_APP_ID=value
CLOUDWATCH_RUM_APP_NAME=value
CLOUDWATCH_RUM_IDENTITY_POOL_ID=value
Expand Down
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__generated__
__generated_v2__
**/*.module.css.d.ts
node_modules/
4 changes: 4 additions & 0 deletions frontend/.happy/terraform/envs/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
data "aws_ssm_parameter" "graphql_endpoint" {
name = "/cryoet-dev/graphql_endpoint"
}
data "aws_ssm_parameter" "graphql_endpoint_v2" {
name = "/cryoet-dev/graphql_endpoint_v2"
}

module "stack" {
source = "git@github.com:chanzuckerberg/happy//terraform/modules/happy-stack-eks?ref=happy-stack-eks-v4.31.0"
Expand All @@ -15,6 +18,7 @@ module "stack" {
deployment_stage = "dev"
additional_env_vars = {
API_URL = data.aws_ssm_parameter.graphql_endpoint.value
API_URL_V2 = data.aws_ssm_parameter.graphql_endpoint_v2.value
ENV = "dev"
}
services = {
Expand Down
4 changes: 4 additions & 0 deletions frontend/.happy/terraform/envs/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
data "aws_ssm_parameter" "graphql_endpoint" {
name = "/cryoet-prod/graphql_endpoint"
}
data "aws_ssm_parameter" "graphql_endpoint_v2" {
name = "/cryoet-prod/graphql_endpoint_v2"
}

module "stack" {
source = "git@github.com:chanzuckerberg/happy//terraform/modules/happy-stack-eks?ref=happy-stack-eks-v4.31.0"
Expand All @@ -16,6 +19,7 @@ module "stack" {
additional_env_vars = {
ENV = "prod"
API_URL = data.aws_ssm_parameter.graphql_endpoint.value
API_URL_V2 = data.aws_ssm_parameter.graphql_endpoint_v2.value
}
services = {
frontend = {
Expand Down
4 changes: 4 additions & 0 deletions frontend/.happy/terraform/envs/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
data "aws_ssm_parameter" "graphql_endpoint" {
name = "/cryoet-staging/graphql_endpoint"
}
data "aws_ssm_parameter" "graphql_endpoint_v2" {
name = "/cryoet-staging/graphql_endpoint_v2"
}

module "stack" {
source = "git@github.com:chanzuckerberg/happy//terraform/modules/happy-stack-eks?ref=happy-stack-eks-v4.31.0"
Expand All @@ -15,6 +18,7 @@ module "stack" {
deployment_stage = "staging"
additional_env_vars = {
API_URL = data.aws_ssm_parameter.graphql_endpoint.value
API_URL_V2 = data.aws_ssm_parameter.graphql_endpoint_v2.value
ENV = "staging"
}
services = {
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/data-portal/.env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
API_URL=https://graphql-cryoet-api.cryoet.prod.si.czi.technology/v1/graphql
API_URL_V2=https://graphql.cryoetdataportal.czscience.com/graphql
E2E_CONFIG={}
LOCALHOST_PLAUSIBLE_TRACKING=false

Expand Down
1 change: 1 addition & 0 deletions frontend/packages/data-portal/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.cache/
app/__generated__
app/__generated_v2__
app/**/*.module.css.d.ts
build/
node_modules/
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/data-portal/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__generated__/
__generated_v2__/
**/*.module.css.d.ts
build/
public/build/
Expand Down
13 changes: 13 additions & 0 deletions frontend/packages/data-portal/app/apollo.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ export const apolloClient = new ApolloClient({
uri: process.env.API_URL ?? ENVIRONMENT_CONTEXT_DEFAULT_VALUE.API_URL,
}),
})

export const apolloClientV2 = new ApolloClient({
ssrMode: true,
defaultOptions: {
query: {
fetchPolicy: 'no-cache',
},
},
cache: new InMemoryCache(),
link: createHttpLink({
uri: process.env.API_URL_V2 ?? ENVIRONMENT_CONTEXT_DEFAULT_VALUE.API_URL_V2,
}),
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { createContext, useContext } from 'react'

export type EnvironmentContextValue = Required<
Pick<NodeJS.ProcessEnv, 'API_URL' | 'ENV' | 'LOCALHOST_PLAUSIBLE_TRACKING'>
Pick<
NodeJS.ProcessEnv,
'API_URL' | 'API_URL_V2' | 'ENV' | 'LOCALHOST_PLAUSIBLE_TRACKING'
>
>

export const ENVIRONMENT_CONTEXT_DEFAULT_VALUE: EnvironmentContextValue = {
API_URL:
'https://graphql-cryoet-api.cryoet.prod.si.czi.technology/v1/graphql',
API_URL_V2: 'https://graphql.cryoetdataportal.czscience.com/graphql',
ENV: 'local',
LOCALHOST_PLAUSIBLE_TRACKING: 'false',
}
Expand Down
24 changes: 24 additions & 0 deletions frontend/packages/data-portal/app/graphql/getRunByIdV2.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
ApolloClient,
ApolloQueryResult,
NormalizedCacheObject,
} from '@apollo/client'

import { gql } from 'app/__generated_v2__'
import { GetRunByIdV2Query } from 'app/__generated_v2__/graphql'

const GET_RUN_BY_ID_QUERY_V2 = gql(`
query GetRunByIdV2 {
__typename
}
`)

export async function getRunById({
client,
}: {
client: ApolloClient<NormalizedCacheObject>
}): Promise<ApolloQueryResult<GetRunByIdV2Query>> {
return client.query({
query: GET_RUN_BY_ID_QUERY_V2,
})
}
1 change: 1 addition & 0 deletions frontend/packages/data-portal/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
ENV: defaults(
{
API_URL: process.env.API_URL,
API_URL_V2: process.env.API_URL_V2,
ENV: process.env.ENV,
LOCALHOST_PLAUSIBLE_TRACKING: process.env.LOCALHOST_PLAUSIBLE_TRACKING,
},
Expand Down
26 changes: 24 additions & 2 deletions frontend/packages/data-portal/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,33 @@ const SCHEMA_URL =
process.env.API_URL ||
'https://graphql-cryoet-api.cryoet.prod.si.czi.technology/v1/graphql'

const SCHEMA_URL_V2 =
process.env.API_URL_V2 ||
'https://graphql.cryoetdataportal.czscience.com/graphql'

const config: CodegenConfig = {
schema: SCHEMA_URL,
documents: ['app/**/*.{ts,tsx}'],
generates: {
'./app/__generated__/': {
schema: SCHEMA_URL,
documents: ['app/**/*!(V2)*.{ts,tsx}'],
preset: 'client',
plugins: [],

presetConfig: {
gqlTagName: 'gql',
},

config: {
scalars: {
date: 'string',
numeric: 'number',
_numeric: 'number[][]',
},
},
},
'./app/__generated_v2__/': {
schema: SCHEMA_URL_V2,
documents: ['app/**/*V2*.{ts,tsx}'],
preset: 'client',
plugins: [],

Expand Down
1 change: 1 addition & 0 deletions frontend/packages/data-portal/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare namespace NodeJS {
interface ProcessEnv {
readonly API_URL?: string
readonly API_URL_V2?: string
readonly CLOUDWATCH_RUM_APP_ID?: string
readonly CLOUDWATCH_RUM_APP_NAME?: string
readonly CLOUDWATCH_RUM_IDENTITY_POOL_ID?: string
Expand Down
Loading