Skip to content

Commit c15198a

Browse files
upgrade manually graphql apollo client version 3 to 4
1 parent c5c2741 commit c15198a

File tree

8 files changed

+39
-33
lines changed

8 files changed

+39
-33
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ coverage
2727
# AI
2828
CLAUDE.md
2929

30-
src/graphql/*.ts
31-
src/graphql/*.js
30+
src/graphql/generated/*.ts
31+
src/graphql/generated/*.js
3232

3333
.env.*

bun.lockb

-1.52 KB
Binary file not shown.

codegen.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { CodegenConfig } from '@graphql-codegen/cli'
22

33
const config: CodegenConfig = {
44
schema: './src/graphql/schema.graphql',
5-
documents: './src/**/*.graphql',
5+
documents: ['./src/**/*.{ts,tsx,graphql}'],
6+
ignoreNoDocuments: true,
67
generates: {
7-
'./src/graphql/generated.ts': {
8-
plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
9-
config: {
10-
withHooks: true,
11-
withResultType: true,
8+
'./src/graphql/generated/': {
9+
preset: 'client',
10+
presetConfig: {
11+
fragmentMasking: { unmaskFunctionName: 'getFragmentData' },
1212
},
1313
},
1414
},

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"test": "vitest --run",
1313
"test:ui": "vitest --ui",
1414
"coverage": "vitest run --coverage",
15-
"generate:graphql": "graphql-codegen --config codegen.ts"
15+
"generate:graphql": "graphql-codegen --config codegen.ts --verbose"
1616
},
1717
"dependencies": {
18-
"@apollo/client": "^3.14.0",
18+
"@apollo/client": "^4.1.6",
1919
"@hookform/resolvers": "^5.2.2",
2020
"@radix-ui/react-dialog": "^1.1.15",
2121
"@radix-ui/react-dropdown-menu": "^2.1.16",
@@ -30,7 +30,7 @@
3030
"class-variance-authority": "^0.7.1",
3131
"clsx": "^2.1.1",
3232
"cmdk": "^1.1.1",
33-
"graphql": "^16.10.0",
33+
"graphql": "^16.13.0",
3434
"graphql-codegen": "^0.4.0",
3535
"i18next": "^25.8.7",
3636
"i18next-browser-languagedetector": "^8.2.1",
@@ -51,10 +51,10 @@
5151
"node": ">=22.12.0"
5252
},
5353
"devDependencies": {
54-
"@graphql-codegen/cli": "^5.0.7",
55-
"@graphql-codegen/client-preset": "^4.8.3",
56-
"@graphql-codegen/typescript-operations": "^4.6.1",
57-
"@graphql-codegen/typescript-react-apollo": "^4.3.3",
54+
"@graphql-codegen/cli": "^6.1.2",
55+
"@graphql-codegen/client-preset": "^5.2.3",
56+
"@graphql-codegen/typescript-operations": "^5.0.8",
57+
"@graphql-codegen/typescript-react-apollo": "^4.4.0",
5858
"@tailwindcss/postcss": "^4.1.18",
5959
"@tailwindcss/vite": "^4.1.18",
6060
"@testing-library/jest-dom": "^6.9.1",

src/main.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import ReactDOM from 'react-dom/client'
33
import { Provider } from 'react-redux'
44
import { persistor, store } from './store/store'
55
import { PersistGate } from 'redux-persist/integration/react'
6-
import { ApolloClient, ApolloProvider, createHttpLink, InMemoryCache } from '@apollo/client'
7-
import { setContext } from '@apollo/client/link/context'
6+
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
7+
import { SetContextLink } from '@apollo/client/link/context'
8+
import { ApolloProvider } from '@apollo/client/react'
89
import { ReactKeycloakProvider } from '@react-keycloak/web'
10+
import keycloak from '@/lib/keycloak'
911
import { AuthClientError, AuthClientEvent } from '@react-keycloak/core/lib/types'
1012
import { AuthClientTokens } from '@react-keycloak/core'
1113
import { BrowserRouter } from 'react-router-dom'
12-
import keycloak from '@/lib/keycloak'
14+
import { ThemeProvider } from '@/components/theme-provider'
1315
import App from './App'
1416
import '@/locales/i18n'
1517
import './App.css'
1618

17-
import { ThemeProvider } from '@/components/theme-provider'
18-
1919
const onKeycloakEvent = (_event: AuthClientEvent, error?: AuthClientError): void => {
2020
if (error) {
2121
console.error('Keycloak error: ' + JSON.stringify(error))
@@ -28,15 +28,16 @@ const onKeycloakTokens = (_tokens: AuthClientTokens): void => {
2828
// console.info("Keycloak token: " + JSON.stringify(tokens))
2929
}
3030

31-
const httpLink = createHttpLink({
31+
const httpLink = new HttpLink({
3232
uri: import.meta.env.VITE_APP_BACKEND_URL + '/graphql',
3333
})
3434

35-
const authLink = setContext((_, { headers }) => {
35+
const authLink = new SetContextLink((prevContext) => {
3636
const token = keycloak.token
37+
3738
return {
3839
headers: {
39-
...headers,
40+
...prevContext.headers,
4041
authorization: token ? `Bearer ${token}` : '',
4142
},
4243
}

src/pages/users/Users.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { beforeAll, afterAll, afterEach, describe, expect, it, vitest } from 'vi
22
import { render, screen, waitFor } from '@testing-library/react'
33
import React, { act } from 'react'
44
import { BrowserRouter } from 'react-router-dom'
5-
import { GetAllPermissionsDocument } from '@/graphql/generated'
5+
import { GetAllPermissionsDocument } from '@/graphql/generated/graphql'
66
import { store } from '@/store/store'
77
import { http, HttpResponse } from 'msw'
88
import { setupServer } from 'msw/node'
99
import { usersApi } from './api/usersApi'
1010
import { Provider } from 'react-redux'
1111
import '@/locales/i18n'
1212
import { ThemeProvider } from '@/components/theme-provider'
13-
import { MockedProvider } from '@apollo/client/testing'
13+
import { MockedProvider } from '@apollo/client/testing/react'
1414

1515
const mockedRolesGql = {
1616
request: {

src/pages/users/graphql/permissions.graphql

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

src/pages/users/hooks/useRolesGraphql.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import { useEffect, useState } from 'react'
22
import { Role } from '../api/usersApi.types'
3-
import { useGetAllPermissionsQuery } from '@/graphql/generated'
3+
import { graphql } from '@/graphql/generated/'
4+
import { useQuery } from '@apollo/client/react'
45

56
export const useRolesGraphql = () => {
67
const [roles, setRoles] = useState<Role[]>()
7-
const { loading, error, data } = useGetAllPermissionsQuery({
8+
9+
const GetAllPermissionsDocument = graphql(`
10+
query GetAllPermissions($page: Int, $size: Int, $sort: String, $direction: String) {
11+
getAllPermissions(page: $page, size: $size, sort: $sort, direction: $direction) {
12+
id
13+
name
14+
}
15+
}
16+
`)
17+
18+
const { loading, error, data } = useQuery(GetAllPermissionsDocument, {
819
variables: {
920
page: 0,
1021
size: 10,

0 commit comments

Comments
 (0)