Skip to content

Commit ad03fff

Browse files
taymoor89barsukov
andauthored
feat(heureka): integrate GraphQL backend (#779)
* chore(heureka): codegen integration * feat(heureka): list services * test(heureka): supply mock data instead of mocking component --------- Co-authored-by: Wowa <[email protected]>
1 parent 392055e commit ad03fff

File tree

21 files changed

+4755
-175
lines changed

21 files changed

+4755
-175
lines changed

.changeset/many-jars-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"heureka-next": minor
3+
---
4+
5+
The app is now able to communicate with the GraphQL backend.

.github/workflows/deploy-pr-preview.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ jobs:
155155
env:
156156
PACKAGE_PATH: apps/heureka-next
157157
TARGET_FOLDER: heureka_next
158-
APP_PROPS_BASE64: ${{ secrets.HEUREKA_NEXT_APP_PROPS_BASE64 }}
158+
APP_PROPS_BASE64: ${{ secrets.HEUREKA_APP_PROPS_BASE64 }}
159159
continue-on-error: true
160160

161161
- name: Generate index.html for Deployed Apps

apps/heureka-next/.env.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
API_ENDPOINT=SOME_URL

apps/heureka-next/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,52 @@
44

55
This app will eventually become a successor to the existing Heureka app.
66

7+
## How to run locally?
8+
9+
1. Go to app directory:
10+
```bash
11+
cd apps/heureka-next
12+
```
13+
2. If you are running the app for the first time, follow these steps. Otherwise, skip to step 3:
14+
1. Create `appProps.json` and change the configurations accordingly:
15+
```bash
16+
cp appProps.template.json appProps.json
17+
```
18+
2. Create `.env` file and change configurations accordingly:
19+
```bash
20+
cp .env.template .env
21+
```
22+
3. Install dependencies:
23+
```bash
24+
npm i
25+
```
26+
4. Run the development server:
27+
```bash
28+
npm run dev
29+
```
30+
31+
## How to update GraphQL types?
32+
33+
1. Go to app directory:
34+
```bash
35+
cd apps/heureka-next
36+
```
37+
2. Update GraphQL types from the latest GraphQL schema:
38+
```bash
39+
npm run generate:types
40+
```
41+
42+
## How to run tests?
43+
44+
1. Go to app directory:
45+
```bash
46+
cd apps/heureka-next
47+
```
48+
2. Run tests:
49+
```bash
50+
npm run test
51+
```
52+
753
## Contributing
854

955
We welcome contributions from the community. Please follow our [contribution guidelines] to contribute to this project.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"apiEndpoint": "YOUR_GRAPHQL_API_ENDPOINT",
3+
"embedded": false,
4+
"theme": "light"
5+
}

apps/heureka-next/codegen.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { CodegenConfig } from "@graphql-codegen/cli"
2+
import * as dotenv from "dotenv"
3+
4+
// Load environment variables from .env file
5+
dotenv.config()
6+
7+
const config: CodegenConfig = {
8+
schema: process.env.API_ENDPOINT,
9+
documents: "src/**/*.graphql",
10+
11+
generates: {
12+
"src/generated/graphql.tsx": {
13+
plugins: ["typescript", "typescript-operations", "typescript-react-apollo"],
14+
config: {
15+
withHooks: true,
16+
withHOC: false,
17+
withComponent: false,
18+
},
19+
},
20+
},
21+
}
22+
23+
export default config

apps/heureka-next/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
<title>Heureka Next</title>
88
</head>
99
<body>
10+
<script type="module">
11+
// appProps are excluded from standalone build and should be generated from outside
12+
fetch("./appProps.json")
13+
.then((res) => res.json())
14+
.catch((error) => {
15+
console.warn("No appProps found, using default props", error.message)
16+
})
17+
.then((props) => {
18+
import("./src/index").then((app) => {
19+
app.mount(document.getElementById("root"), props)
20+
})
21+
})
22+
</script>
1023
<div id="root"></div>
1124
<script type="module" src="/src/index.tsx"></script>
1225
</body>

apps/heureka-next/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dev": "vite",
1818
"build": "vite build",
1919
"build:static": "vite build --mode static",
20+
"generate:types": "graphql-codegen --config codegen.ts",
2021
"serve": "vite preview",
2122
"test": "vitest run",
2223
"lint": "eslint",
@@ -31,6 +32,11 @@
3132
"react-dom": "18.3.1"
3233
},
3334
"devDependencies": {
35+
"@apollo/client": "^3.11.10",
36+
"@graphql-codegen/cli": "^5.0.3",
37+
"@graphql-codegen/typescript": "^4.1.2",
38+
"@graphql-codegen/typescript-operations": "^4.4.0",
39+
"@graphql-codegen/typescript-react-apollo": "^4.3.2",
3440
"@cloudoperators/juno-config": "*",
3541
"@testing-library/jest-dom": "6.6.3",
3642
"@testing-library/react": "16.2.0",

apps/heureka-next/src/App.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@ import React from "react"
77
import { AppShellProvider } from "@cloudoperators/juno-ui-components"
88
import { ErrorBoundary } from "./components/ErrorBoundary"
99
import { Shell } from "./components/Shell"
10+
import { ApolloProvider } from "@apollo/client"
11+
import { getClient } from "./apollo-client"
1012

1113
export type AppProps = {
1214
theme?: "theme-dark" | "theme-light"
15+
apiEndpoint?: string
1316
embedded?: boolean
1417
}
1518

16-
export const App = (props: AppProps) => (
17-
<AppShellProvider theme={`${props.theme ? props.theme : "theme-dark"}`}>
18-
<ErrorBoundary>
19-
<Shell {...props} />
20-
</ErrorBoundary>
21-
</AppShellProvider>
19+
const App = (props: AppProps) => (
20+
<ApolloProvider client={getClient({ uri: props.apiEndpoint })}>
21+
<AppShellProvider theme={`${props.theme ? props.theme : "theme-dark"}`}>
22+
<ErrorBoundary>
23+
<Shell {...props} />
24+
</ErrorBoundary>
25+
</AppShellProvider>
26+
</ApolloProvider>
2227
)
28+
29+
export default App
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ApolloClient, InMemoryCache } from "@apollo/client"
2+
3+
type ClientOptions = {
4+
uri?: string
5+
}
6+
7+
export const getClient = ({ uri }: ClientOptions) => {
8+
if (typeof uri === "undefined") {
9+
throw new Error("No API endpoint provided.")
10+
}
11+
return new ApolloClient({
12+
uri,
13+
cache: new InMemoryCache(),
14+
})
15+
}

0 commit comments

Comments
 (0)