Skip to content

Commit 7acbea4

Browse files
authored
Merge pull request #60 from HSLdevcom/DT-6515
Update GraphiQL to use new API path
2 parents 4d2359d + da2fce7 commit 7acbea4

32 files changed

+16804
-9669
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
build

.eslintrc.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
module.exports = {
2+
parser: '@babel/eslint-parser',
3+
extends: [
4+
'plugin:compat/recommended',
5+
'plugin:jsx-a11y/recommended',
6+
'airbnb',
7+
'plugin:prettier/recommended',
8+
],
9+
rules: {
10+
curly: ['error', 'all'],
11+
'lines-between-class-members': 'warn',
12+
'no-else-return': 'warn',
13+
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
14+
'no-console': 'error',
15+
'no-restricted-exports': 'off',
16+
'import/no-extraneous-dependencies': 'off',
17+
'import/no-named-default': 'off',
18+
'import/extensions': 'off',
19+
// react
20+
'react/button-has-type': 'warn',
21+
'react/destructuring-assignment': 'off',
22+
'react/jsx-filename-extension': ['error', { extensions: ['.js'] }],
23+
'react/jsx-fragments': 'off',
24+
'react/jsx-key': 'error',
25+
'react/jsx-props-no-spreading': 'off',
26+
'react/forbid-prop-types': ['warn', { forbid: ['any', 'array', 'object'] }],
27+
'react/require-default-props': 'warn',
28+
'react/sort-comp': 'off',
29+
'react/state-in-constructor': 'off',
30+
'react/static-property-placement': 'off',
31+
'react/function-component-definition': 'off',
32+
'react/prop-types': 'off',
33+
34+
// jsx-a11y
35+
'jsx-a11y/anchor-is-valid': [
36+
'error',
37+
{
38+
components: ['Link'],
39+
specialLink: ['to'],
40+
aspects: ['noHref', 'invalidHref', 'preferButton'],
41+
},
42+
],
43+
'jsx-a11y/label-has-associated-control': 'off', // this has a bug with FormattedMessage
44+
'jsx-a11y/label-has-for': 'off', // deprecated in 6.1.0, does not support select tags
45+
'jsx-a11y/control-has-associated-label': 'off', // this has a bug with FormattedMessage
46+
47+
// compat
48+
'compat/compat': 'warn',
49+
50+
// prettier
51+
'prettier/prettier': [
52+
'error',
53+
{
54+
arrowParens: 'avoid',
55+
endOfLine: 'auto',
56+
singleQuote: true,
57+
trailingComma: 'all',
58+
},
59+
],
60+
61+
'no-shadow': 'off',
62+
},
63+
env: {
64+
browser: true,
65+
jest: true,
66+
},
67+
plugins: ['react', 'compat', 'prettier', 'jsx-a11y'],
68+
settings: {
69+
polyfills: ['fetch', 'promises'],
70+
},
71+
};

.github/workflows/dev-pipeline.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [16.x]
14+
node-version: [20.x]
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v3
@@ -53,3 +53,5 @@ jobs:
5353
env:
5454
DOCKER_USER: ${{ secrets.DOCKER_USER }}
5555
DOCKER_AUTH: ${{ secrets.DOCKER_AUTH }}
56+
REACT_APP_API_SUBSCRIPTION_KEY: ${{ secrets.REACT_APP_API_SUBSCRIPTION_KEY }}
57+
REACT_APP_DEV_API_SUBSCRIPTION_KEY: ${{ secrets.REACT_APP_DEV_API_SUBSCRIPTION_KEY }}

.github/workflows/prod-pipeline.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ jobs:
2323
env:
2424
DOCKER_USER: ${{ secrets.DOCKER_USER }}
2525
DOCKER_AUTH: ${{ secrets.DOCKER_AUTH }}
26+
REACT_APP_API_SUBSCRIPTION_KEY: ${{ secrets.REACT_APP_API_SUBSCRIPTION_KEY }}
27+
REACT_APP_DEV_API_SUBSCRIPTION_KEY: ${{ secrets.REACT_APP_DEV_API_SUBSCRIPTION_KEY }}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@ node_modules/
1818
.env.development.local
1919
.env.test.local
2020
.env.production.local
21+
22+
# VSCode
2123
.vscode
2224

2325
npm-debug.log*
2426
yarn-debug.log*
2527
yarn-error.log*
28+
29+
# yarn
30+
.pnp.*
31+
.yarn/*
32+
!.yarn/patches
33+
!.yarn/plugins
34+
!.yarn/releases
35+
!.yarn/sdks
36+
!.yarn/versions

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20

.yarn/releases/yarn-4.5.1.cjs

Lines changed: 934 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
compressionLevel: mixed
2+
3+
enableGlobalCache: false
4+
5+
nodeLinker: node-modules
6+
7+
yarnPath: .yarn/releases/yarn-4.5.1.cjs

Dockerfile

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
FROM node:16-alpine3.16
1+
FROM node:20-alpine AS builder
22
LABEL maintainer="Digitransit <digitransit@HSL.fi>"
33

44
WORKDIR /opt/digitransit-graphql
55

6-
COPY . ./
7-
RUN yarn
6+
# Copy files to build container, install dependencies, and build application.
7+
COPY . .
8+
9+
# None of these are secrets, the env parameter can be visible in public.
10+
# These are for more configurability (as opposed to having keys directly in code).
11+
ARG REACT_APP_DEV_API_SUBSCRIPTION_KEY=""
12+
ARG REACT_APP_API_SUBSCRIPTION_KEY=""
13+
ARG REACT_APP_API_SUBSCRIPTION_KEY_PARAM=""
14+
ENV REACT_APP_API_SUBSCRIPTION_KEY_PARAM=$REACT_APP_API_SUBSCRIPTION_KEY_PARAM
15+
ENV REACT_APP_DEV_API_SUBSCRIPTION_KEY=$REACT_APP_DEV_API_SUBSCRIPTION_KEY
16+
ENV REACT_APP_API_SUBSCRIPTION_KEY=$REACT_APP_API_SUBSCRIPTION_KEY
17+
18+
RUN yarn install
19+
RUN yarn build
20+
21+
22+
FROM nginx:1.27.2-alpine
23+
WORKDIR /usr/share/nginx/html
24+
25+
# Remove default nginx files, copy built files, and copy nginx configuration.
26+
RUN rm -rf ./*
27+
COPY --from=builder /opt/digitransit-graphql/build .
28+
COPY --from=builder /opt/digitransit-graphql/nginx/nginx.conf /etc/nginx/conf.d/default.conf
829

930
EXPOSE 8080
10-
ENV REACT_APP_DISABLE_LIVE_RELOAD=true
11-
ENTRYPOINT ["yarn", "start"]
31+
ENTRYPOINT ["nginx", "-g", "daemon off;"]

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@ Deployment for HSL version of [GraphiQL](https://github.com/graphql/graphiql). P
88
REACT_APP_DEV_API_SUBSCRIPTION_KEY=key REACT_APP_API_SUBSCRIPTION_KEY=key REACT_APP_API_SUBSCRIPTION_KEY_PARAM=digitransit-subscription-key yarn start
99
```
1010

11-
Environment variables `REACT_APP_DEV_API_SUBSCRIPTION_KEY`, `REACT_APP_API_SUBSCRIPTION_KEY` and `REACT_APP_API_SUBSCRIPTION_KEY_PARAM` are set to GraphQL request query string for authorization gateway service.
11+
Environment variables `REACT_APP_DEV_API_SUBSCRIPTION_KEY`, `REACT_APP_API_SUBSCRIPTION_KEY`, and `REACT_APP_API_SUBSCRIPTION_KEY_PARAM` are set in the GraphQL request query string for the authorization gateway service.
1212

13-
## Run in docker
13+
## Docker
1414

15+
### Build
1516
```sh
16-
docker build -t graphiql .
17-
docker run -it \
18-
-p 8099:8080 \
19-
-e REACT_APP_DEV_API_SUBSCRIPTION_KEY=key \
20-
-e REACT_APP_API_SUBSCRIPTION_KEY=key \
21-
-e REACT_APP_API_SUBSCRIPTION_KEY_PARAM=digitransit-subscription-key \
22-
graphiql
17+
docker build \
18+
--build-arg REACT_APP_DEV_API_SUBSCRIPTION_KEY=key \
19+
--build-arg REACT_APP_API_SUBSCRIPTION_KEY=key \
20+
--build-arg REACT_APP_API_SUBSCRIPTION_KEY_PARAM=digitransit-subscription-key \
21+
-t graphiql .
2322
```
2423

25-
## Code formatting
26-
27-
Format source codebase:
24+
### Run
25+
```sh
26+
docker run -it -p 8099:8080 graphiql
27+
```
2828

29+
## Code formatting
2930
```sh
30-
yarn format
31+
yarn lint
3132
```

babel.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current',
8+
browsers: [],
9+
},
10+
},
11+
],
12+
'@babel/preset-react',
13+
],
14+
plugins: [
15+
'dynamic-import-node',
16+
'relay',
17+
'@babel/plugin-syntax-dynamic-import',
18+
'@babel/plugin-transform-class-properties',
19+
'@babel/plugin-transform-json-strings',
20+
],
21+
};

nginx/nginx.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
server {
2+
listen 8080;
3+
location / {
4+
root /usr/share/nginx/html;
5+
index index.html index.htm;
6+
try_files $uri $uri/ /index.html =404;
7+
}
8+
}

package.json

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22
"name": "graphiql-deployment",
33
"version": "1.0.0",
44
"engines": {
5-
"node": ">=16.16.0 <17.0.0"
5+
"node": ">=16.17",
6+
"npm": ">=3.0"
67
},
8+
"packageManager": "yarn@4.5.1",
79
"private": true,
8-
"homepage": "/graphiql",
910
"dependencies": {
10-
"graphiql": "^1.11.4",
11-
"graphql": "^16.5.0",
12-
"react": "^16.8.6",
13-
"react-dom": "^16.8.6",
14-
"react-router-dom": "^5.0.0",
15-
"react-scripts": "^5.0.0"
11+
"graphiql": "^3.7.1",
12+
"graphql": "^16.9.0",
13+
"react": "^18.3.1",
14+
"react-dom": "^18.3.1",
15+
"react-router-dom": "^6.28.0",
16+
"react-scripts": "^5.0.1",
17+
"web-vitals": "^2.1.0"
1618
},
1719
"scripts": {
1820
"start": "PORT=8080 react-scripts start",
1921
"build": "react-scripts build",
2022
"test": "react-scripts test --watchAll=false --coverage",
2123
"test:watch": "react-scripts test",
2224
"eject": "react-scripts eject",
23-
"lint": "eslint src/**/*.js",
24-
"lint:fix": "eslint --fix src/**/*.js"
25+
"lint": "eslint .",
26+
"lint:fix": "eslint --fix ."
2527
},
2628
"eslintConfig": {
2729
"extends": "react-app"
@@ -39,8 +41,20 @@
3941
]
4042
},
4143
"devDependencies": {
42-
"eslint": "^8.19.0",
44+
"@babel/cli": "^7.25.9",
45+
"@babel/core": "^7.26.0",
46+
"@babel/eslint-parser": "^7.25.9",
47+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
48+
"@babel/preset-env": "^7.26.0",
49+
"babel-plugin-dynamic-import-node": "^2.3.3",
50+
"babel-plugin-relay": "^18.1.0",
51+
"eslint": "8.56.0",
52+
"eslint-config-airbnb": "19.0.4",
53+
"eslint-config-prettier": "9.1.0",
4354
"eslint-config-react-app": "^7.0.1",
44-
"graphql-ws": "^5.9.1"
55+
"eslint-plugin-compat": "^6.0.1",
56+
"eslint-plugin-prettier": "^5.2.1",
57+
"graphql-ws": "^5.16.0",
58+
"prettier": "^3.3.3"
4559
}
4660
}

public/favicon.png

2.77 KB
Loading

public/index.html

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
56
<meta name="viewport" content="width=device-width, initial-scale=1" />
6-
<title>GraphiQL</title>
7-
<% if (process.env.REACT_APP_DISABLE_LIVE_RELOAD === "true") { %>
87
<!--
9-
Disable devserver Live Reload it by starting the app with REACT_APP_DISABLE_LIVE_RELOAD=true
8+
manifest.json provides metadata used when your web app is installed on a
9+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1010
-->
11-
<script>
12-
var WS = window.WebSocket;
13-
function DevWebSocket(s) {
14-
if (s === 'ws://localhost:8080/ws') {
15-
return {};
16-
} else {
17-
// Pass through other usage of sockets
18-
return new WS(s);
19-
}
20-
}
21-
window.WebSocket = DevWebSocket;
22-
</script>
23-
<% } %>
11+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
12+
<!--
13+
Notice the use of %PUBLIC_URL% in the tags above.
14+
It will be replaced with the URL of the `public` folder during the build.
15+
Only files inside the `public` folder can be referenced from the HTML.
16+
17+
Unlike "/favicon.png" or "favicon.png", "%PUBLIC_URL%/favicon.png" will
18+
work correctly both with client-side routing and a non-root public URL.
19+
Learn how to configure a non-root public URL by running `npm run build`.
20+
-->
21+
<title>GraphiQL deployment</title>
2422
</head>
2523
<body>
2624
<noscript>You need to enable JavaScript to run this app.</noscript>

public/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "graphiql-deployment",
3+
"name": "GraphiQL deployment",
4+
"icons": [
5+
{
6+
"src": "favicon.png",
7+
"sizes": " 96x96 64x64 32x32 24x24 16x16",
8+
"type": "image/png"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

0 commit comments

Comments
 (0)