Skip to content

Commit d8355cf

Browse files
authored
Merge pull request #61 from HSLdevcom/DT-6515
DT-6515 Start using vite and fix subpath issue
2 parents 7acbea4 + ed9567a commit d8355cf

27 files changed

+3001
-10399
lines changed

.eslintrc.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
// react
2020
'react/button-has-type': 'warn',
2121
'react/destructuring-assignment': 'off',
22-
'react/jsx-filename-extension': ['error', { extensions: ['.js'] }],
22+
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.jsx'] }],
2323
'react/jsx-fragments': 'off',
2424
'react/jsx-key': 'error',
2525
'react/jsx-props-no-spreading': 'off',
@@ -62,8 +62,12 @@ module.exports = {
6262
},
6363
env: {
6464
browser: true,
65-
jest: true,
6665
},
66+
overrides: [
67+
{
68+
files: ['*.jsx', '*.js'],
69+
},
70+
],
6771
plugins: ['react', 'compat', 'prettier', 'jsx-a11y'],
6872
settings: {
6973
polyfills: ['fetch', 'promises'],

.github/workflows/dev-pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +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 }}
56+
VITE_API_SUBSCRIPTION_KEY: ${{ secrets.VITE_API_SUBSCRIPTION_KEY }}
57+
VITE_DEV_API_SUBSCRIPTION_KEY: ${{ secrets.VITE_DEV_API_SUBSCRIPTION_KEY }}

.github/workflows/prod-pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +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 }}
26+
VITE_API_SUBSCRIPTION_KEY: ${{ secrets.VITE_API_SUBSCRIPTION_KEY }}
27+
VITE_DEV_API_SUBSCRIPTION_KEY: ${{ secrets.VITE_DEV_API_SUBSCRIPTION_KEY }}

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ COPY . .
88

99
# None of these are secrets, the env parameter can be visible in public.
1010
# 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
11+
ARG VITE_DEV_API_SUBSCRIPTION_KEY=""
12+
ARG VITE_API_SUBSCRIPTION_KEY=""
13+
ARG VITE_API_SUBSCRIPTION_KEY_PARAM=""
14+
ENV VITE_API_SUBSCRIPTION_KEY_PARAM=$VITE_API_SUBSCRIPTION_KEY_PARAM
15+
ENV VITE_DEV_API_SUBSCRIPTION_KEY=$VITE_DEV_API_SUBSCRIPTION_KEY
16+
ENV VITE_API_SUBSCRIPTION_KEY=$VITE_API_SUBSCRIPTION_KEY
1717

1818
RUN yarn install
1919
RUN yarn build

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ Deployment for HSL version of [GraphiQL](https://github.com/graphql/graphiql). P
55
## Start server
66

77
```sh
8-
REACT_APP_DEV_API_SUBSCRIPTION_KEY=key REACT_APP_API_SUBSCRIPTION_KEY=key REACT_APP_API_SUBSCRIPTION_KEY_PARAM=digitransit-subscription-key yarn start
8+
VITE_DEV_API_SUBSCRIPTION_KEY=key VITE_API_SUBSCRIPTION_KEY=key VITE_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 in the GraphQL request query string for the authorization gateway service.
11+
Environment variables `VITE_DEV_API_SUBSCRIPTION_KEY`, `VITE_API_SUBSCRIPTION_KEY`, and `VITE_API_SUBSCRIPTION_KEY_PARAM` are set in the GraphQL request query string for the authorization gateway service.
1212

1313
## Docker
1414

1515
### Build
1616
```sh
1717
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 \
18+
--build-arg VITE_DEV_API_SUBSCRIPTION_KEY=key \
19+
--build-arg VITE_API_SUBSCRIPTION_KEY=key \
20+
--build-arg VITE_API_SUBSCRIPTION_KEY_PARAM=digitransit-subscription-key \
2121
-t graphiql .
2222
```
2323

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="/static/favicon.png" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<title>GraphiQL deployment</title>
8+
</head>
9+
<body>
10+
<noscript>You need to enable JavaScript to run this app.</noscript>
11+
<div id="root"></div>
12+
<script type="module" src="/src/main.jsx"></script>
13+
</body>
14+
</html>

nginx/nginx.conf

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
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-
}
2+
listen 8080;
3+
root /usr/share/nginx/html;
4+
index index.html;
5+
6+
location /graphiql {
7+
rewrite ^/graphiql(/.*) $1 break;
8+
try_files $uri /index.html =404;
9+
}
10+
}

package.json

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@
1212
"graphql": "^16.9.0",
1313
"react": "^18.3.1",
1414
"react-dom": "^18.3.1",
15-
"react-router-dom": "^6.28.0",
16-
"react-scripts": "^5.0.1",
17-
"web-vitals": "^2.1.0"
15+
"react-router-dom": "^6.28.0"
1816
},
1917
"scripts": {
20-
"start": "PORT=8080 react-scripts start",
21-
"build": "react-scripts build",
22-
"test": "react-scripts test --watchAll=false --coverage",
23-
"test:watch": "react-scripts test",
24-
"eject": "react-scripts eject",
25-
"lint": "eslint .",
18+
"start": "vite",
19+
"build": "vite build",
20+
"preview": "vite preview",
21+
"test": "vitest run",
22+
"lint": "eslint src",
2623
"lint:fix": "eslint --fix ."
2724
},
2825
"eslintConfig": {
@@ -46,15 +43,24 @@
4643
"@babel/eslint-parser": "^7.25.9",
4744
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
4845
"@babel/preset-env": "^7.26.0",
46+
"@babel/preset-react": "^7.25.9",
47+
"@vitejs/plugin-react": "^4.3.3",
4948
"babel-plugin-dynamic-import-node": "^2.3.3",
5049
"babel-plugin-relay": "^18.1.0",
5150
"eslint": "8.56.0",
5251
"eslint-config-airbnb": "19.0.4",
5352
"eslint-config-prettier": "9.1.0",
54-
"eslint-config-react-app": "^7.0.1",
5553
"eslint-plugin-compat": "^6.0.1",
54+
"eslint-plugin-import": "^2.31.0",
55+
"eslint-plugin-jsx-a11y": "^6.10.2",
5656
"eslint-plugin-prettier": "^5.2.1",
57+
"eslint-plugin-react": "^7.37.2",
58+
"eslint-plugin-react-hooks": "^4.3.0",
5759
"graphql-ws": "^5.16.0",
58-
"prettier": "^3.3.3"
60+
"jsdom": "^25.0.1",
61+
"prettier": "^3.3.3",
62+
"vite": "^5.4.11",
63+
"vite-tsconfig-paths": "^5.1.2",
64+
"vitest": "^2.1.5"
5965
}
6066
}

public/index.html

Lines changed: 0 additions & 37 deletions
This file was deleted.

public/manifest.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

serve.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/App.js renamed to src/App.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import * as React from 'react';
22
import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom';
33

44
import { API_VERSION_1, API_VERSION_2, DEFAULT_PATH } from './config';
@@ -8,16 +8,16 @@ import Version2ApiRoute from './graphiql/Version2ApiRoute';
88

99
export default () => {
1010
return (
11-
<BrowserRouter>
11+
<BrowserRouter basename="/graphiql">
1212
<Routes>
1313
<Route path="*" element={<Navigate to={DEFAULT_PATH} />} />
14-
<Route path="/graphiql/:router" element={<DefaultApiRoute />}>
14+
<Route path="/:router" element={<DefaultApiRoute />}>
1515
<Route
16-
path={`/graphiql/:router/${API_VERSION_1}`}
16+
path={`/:router/${API_VERSION_1}`}
1717
element={<Version1ApiRoute />}
1818
/>
1919
<Route
20-
path={`/graphiql/:router/${API_VERSION_2}/:dialect/:dialectVersion`}
20+
path={`/:router/${API_VERSION_2}/:dialect/:dialectVersion`}
2121
element={<Version2ApiRoute />}
2222
/>
2323
</Route>

src/App.test.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/api/graphQLFetcher.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import {
23
addSubscriptionKey,
34
buildHeaders,

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const API_VERSION_1 = 'v1';
22
export const API_VERSION_2 = 'v2';
33
export const DIALECT_VERSION_1 = 'v1';
44
export const PRODUCTION_API_URL = 'api.digitransit.fi';
5-
export const DEFAULT_PATH = '/graphiql/hsl';
5+
export const DEFAULT_PATH = '/hsl';
66
export const API_TYPE = Object.freeze({
77
DEV: 'dev',
88
PROD: 'prod',

src/graphiql/CustomGraphiQL.js renamed to src/graphiql/CustomGraphiQL.jsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import * as React from 'react';
22
import { useLocation, useNavigate } from 'react-router-dom';
33
import GraphiQL from 'graphiql';
44
import { ToolbarMenu } from '@graphiql/react';
@@ -113,9 +113,11 @@ const useQuery = location => {
113113
)
114114
: {};
115115

116-
const [query, setQuery] = useState(initial.query);
117-
const [variables, setVariables] = useState(initial.variables);
118-
const [operationName, setOperationName] = useState(initial.operationName);
116+
const [query, setQuery] = React.useState(initial.query);
117+
const [variables, setVariables] = React.useState(initial.variables);
118+
const [operationName, setOperationName] = React.useState(
119+
initial.operationName,
120+
);
119121

120122
return {
121123
query,
@@ -145,14 +147,14 @@ const CustomGraphiQLWrapper = ({
145147
setOperationName,
146148
} = useQuery(location);
147149

148-
const [apiType, setApiType] = useState(
150+
const [apiType, setApiType] = React.useState(
149151
location.state?.apiType ||
150152
(window.location.hostname === PRODUCTION_API_URL
151153
? API_TYPE.PROD
152154
: API_TYPE.DEV),
153155
);
154156

155-
useEffect(() => {
157+
React.useEffect(() => {
156158
const queryString = getQueryString(query, variables, operationName);
157159
navigate(queryString, { replace: true });
158160
}, [query, variables, operationName]);
@@ -206,9 +208,9 @@ export default ({ config, configList }) => {
206208
<CustomGraphiQLWrapper
207209
configList={configList}
208210
config={config}
209-
prodSubscriptionKey={process.env.REACT_APP_API_SUBSCRIPTION_KEY}
210-
devSubscriptionKey={process.env.REACT_APP_DEV_API_SUBSCRIPTION_KEY}
211-
subscriptionKeyParam={process.env.REACT_APP_API_SUBSCRIPTION_KEY_PARAM}
211+
prodSubscriptionKey={import.meta.env.VITE_API_SUBSCRIPTION_KEY}
212+
devSubscriptionKey={import.meta.env.VITE_DEV_API_SUBSCRIPTION_KEY}
213+
subscriptionKeyParam={import.meta.env.VITE_API_SUBSCRIPTION_KEY_PARAM}
212214
/>
213215
);
214216
};

src/graphiql/DefaultApiRoute.js renamed to src/graphiql/DefaultApiRoute.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import * as React from 'react';
22
import { useParams, Navigate } from 'react-router-dom';
33
import {
44
API_VERSION_2,

src/graphiql/Version1ApiRoute.js renamed to src/graphiql/Version1ApiRoute.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import * as React from 'react';
22
import { useParams, Navigate } from 'react-router-dom';
33
import { API_VERSION_1, CONFIG_LIST, DEFAULT_PATH } from '../config';
44
import { getApiConfig } from './utils';

src/graphiql/Version2ApiRoute.js renamed to src/graphiql/Version2ApiRoute.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import * as React from 'react';
22
import { useParams, Navigate } from 'react-router-dom';
33
import { API_VERSION_2, CONFIG_LIST, DEFAULT_PATH } from '../config';
44
import { getApiConfig } from './utils';

0 commit comments

Comments
 (0)