Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 97049ec

Browse files
committedAug 11, 2023
feat: deployment-specific codegen.ts, fixed graphqlQueryFnHelper not picking up the env vars
1 parent f6000a0 commit 97049ec

File tree

8 files changed

+66
-16
lines changed

8 files changed

+66
-16
lines changed
 

‎scripts/tmux-local-stack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if [ $? != 0 ]; then
3636
(( ++index ))
3737
tmux select-pane -t $index -T "WEB"
3838
tmux send-keys -t $index 'cd web' Enter
39-
tmux send-keys -t $index 'yarn generate && yarn start-local'
39+
tmux send-keys -t $index 'yarn start-local'
4040
fi
4141

4242
tmux attach-session -t $session

‎web/.env.devnet.public

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Do not enter sensitive information here.
2+
export REACT_APP_DEPLOYMENT=devnet
3+
export REACT_APP_KLEROS_CORE_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/alcercu/kleroscoredev
4+
export REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/alcercu/disputetemplateregistryarbgrli

‎web/.env.local.public

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Do not enter sensitive information here.
2+
export REACT_APP_DEPLOYMENT=devnet
3+
export REACT_APP_KLEROS_CORE_SUBGRAPH_DEVNET=http://localhost:8000/subgraphs/name/kleros/kleros-v2-core-local
4+
export REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/alcercu/disputetemplateregistryarbgrli2

‎web/.env.testnet.public

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Do not enter sensitive information here.
2+
export REACT_APP_DEPLOYMENT=testnet
3+
export REACT_APP_KLEROS_CORE_SUBGRAPH_TESTNET=https://api.thegraph.com/subgraphs/name/alcercu/kleroscoretest
4+
export REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_TESTNET=https://api.thegraph.com/subgraphs/name/alcercu/disputetemplateregistryarbgrli

‎web/codegen.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import type { CodegenConfig } from "@graphql-codegen/cli";
2+
import { graphqlUrl } from "utils/graphqlQueryFnHelper";
23

34
const config: CodegenConfig = {
45
overwrite: true,
5-
schema: [
6-
"https://api.thegraph.com/subgraphs/name/alcercu/kleroscoretest",
7-
"https://api.thegraph.com/subgraphs/name/alcercu/disputetemplateregistryarbgrli",
8-
],
6+
schema: [graphqlUrl(false), graphqlUrl(true)],
97
documents: "./src/hooks/queries/*.ts",
108
generates: {
119
"./src/graphql/": {

‎web/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
"packageManager": "yarn@3.3.1",
2525
"scripts": {
2626
"clear": "rm -fr ../.parcel-cache dist/bundle.js",
27-
"start": "yarn generate && parcel",
28-
"start-local": "REACT_APP_KLEROS_CORE_SUBGRAPH_TESTNET=http://localhost:8000/subgraphs/name/kleros/kleros-v2-core-local parcel",
29-
"build": "yarn generate && yarn parcel build",
27+
"start": "scripts/runEnv.sh devnet 'yarn generate && parcel'",
28+
"start-testnet": "scripts/runEnv.sh testnet 'yarn generate && parcel'",
29+
"start-local": "scripts/runEnv.sh local 'yarn generate && parcel'",
30+
"build": "yarn generate && parcel build",
31+
"build-devnet": "scripts/runEnv.sh devnet 'yarn generate && parcel build'",
32+
"build-testnet": "scripts/runEnv.sh testnet 'yarn generate && parcel build'",
3033
"check-style": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
3134
"check-types": "tsc --noEmit",
3235
"generate": "yarn generate:gql && yarn generate:hooks",
33-
"generate:gql": "graphql-codegen",
36+
"generate:gql": "graphql-codegen --require tsconfig-paths/register",
3437
"generate:hooks": "NODE_NO_WARNINGS=1 wagmi generate"
3538
},
3639
"prettier": "@kleros/kleros-v2-prettier-config",

‎web/scripts/runEnv.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
deployment="$1"
6+
shift
7+
commands="$@"
8+
9+
if [[ -z "$deployment" ]]; then
10+
echo "usage: $(basename $0) <local|devnet|testnet|mainnet>"
11+
exit 1
12+
fi
13+
14+
valid_deployments=("local" "devnet" "testnet" "mainnet")
15+
if [[ ! " ${valid_deployments[@]} " =~ " ${deployment} " ]]; then
16+
echo "Invalid deployment option. Please choose either: ${valid_deployments[@]}."
17+
exit 1
18+
fi
19+
20+
. $SCRIPT_DIR/../.env.${deployment}.public
21+
eval "$commands"

‎web/src/utils/graphqlQueryFnHelper.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
import request from "graphql-request";
22
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
33

4-
const DEPLOYMENT = process.env["REACT_APP_DEPLOYMENT"]?.toUpperCase() ?? "TESTNET";
4+
const DEPLOYMENT = process.env.REACT_APP_DEPLOYMENT?.toUpperCase() ?? "TESTNET";
55

6-
const CHAINID_TO_DISPUTETEMPLATE_SUBGRAPH = {
6+
const DEPLOYMENTS_TO_KLEROS_CORE_SUBGRAPHS = {
7+
MAINNET: process.env.REACT_APP_KLEROS_CORE_SUBGRAPH_MAINNET,
8+
TESTNET: process.env.REACT_APP_KLEROS_CORE_SUBGRAPH_TESTNET,
9+
DEVNET: process.env.REACT_APP_KLEROS_CORE_SUBGRAPH_DEVNET,
10+
};
11+
12+
const DEPLOYMENTS_TO_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPHS = {
13+
MAINNET: process.env.REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_MAINNET,
14+
TESTNET: process.env.REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_TESTNET,
15+
DEVNET: process.env.REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_DEVNET,
16+
};
17+
18+
const CHAINID_TO_DISPUTE_TEMPLATE_SUBGRAPH = {
719
421613:
8-
process.env[`REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_${DEPLOYMENT}`] ??
20+
DEPLOYMENTS_TO_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPHS[DEPLOYMENT] ??
921
"https://api.thegraph.com/subgraphs/name/alcercu/disputetemplateregistryarbgrli",
1022
};
1123

24+
export const graphqlUrl = (isDisputeTemplate = false, chainId = 421613) => {
25+
const coreUrl =
26+
DEPLOYMENTS_TO_KLEROS_CORE_SUBGRAPHS[DEPLOYMENT] ??
27+
"https://api.thegraph.com/subgraphs/name/alcercu/kleroscoretest";
28+
return isDisputeTemplate ? CHAINID_TO_DISPUTE_TEMPLATE_SUBGRAPH[chainId] : coreUrl;
29+
};
30+
1231
export const graphqlQueryFnHelper = async (
1332
query: TypedDocumentNode<any, any>,
1433
parametersObject: Record<string, any>,
1534
isDisputeTemplate = false,
1635
chainId = 421613
1736
) => {
18-
const coreUrl =
19-
process.env[`REACT_APP_KLEROS_CORE_SUBGRAPH_${DEPLOYMENT}`] ??
20-
"https://api.thegraph.com/subgraphs/name/alcercu/kleroscoretest";
21-
const url = isDisputeTemplate ? CHAINID_TO_DISPUTETEMPLATE_SUBGRAPH[chainId] : coreUrl;
37+
const url = graphqlUrl(isDisputeTemplate, chainId);
2238
return request(url, query, parametersObject);
2339
};

0 commit comments

Comments
 (0)
Please sign in to comment.