Skip to content

Commit

Permalink
add integration for react-query and swr
Browse files Browse the repository at this point in the history
  • Loading branch information
openint-bot committed Dec 23, 2024
1 parent edb39a6 commit f3501d7
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 12 deletions.
76 changes: 76 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sdks/sdk-openint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
"@opensdks/runtime": "workspace:*",
"concurrently": "^8.2.2",
"openapi-fetch": "^0.13.3",
"openapi-react-query": "^0.2.8",
"openapi-typescript": "6.7.1",
"prettier": "^3.1.0"
"prettier": "^3.1.0",
"swr-openapi": "^5.1.2"
},
"peerDependencies": {
"@opensdks/runtime": "workspace:*"
Expand Down
11 changes: 0 additions & 11 deletions sdks/sdk-openint/src/index.spec.ts

This file was deleted.

51 changes: 51 additions & 0 deletions sdks/sdk-openint/src/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {jest} from '@jest/globals'
import createReactQuery from 'openapi-react-query'
import {createQueryHook} from 'swr-openapi'
import initOpenIntSDK from './index.js'

jest.setTimeout(70 * 15 * 1000) // In case of cold start

const openint = initOpenIntSDK({headers: {}})

test('healthcheck with default init', async () => {
expect(await openint['/health'].GET().then((r) => r.data)).toBeTruthy()
expect(await openint.GET('/health').then((r) => r.data)).toBeTruthy()
})

test('openapi-react-query integration works', () => {
const $api = createReactQuery(openint.fetchClient)

const MyComponent = () => {
const {data, error, isLoading} = $api.useQuery(
'get',
'/core/connection/{id}',
{params: {path: {id: 'my-connection-id'}}},
)

if (isLoading || !data) return 'Loading...'

if (error) return `An error occured: ${error.message}`

return data.displayName
}

expect(MyComponent).toBeTruthy()
})

test('swr-openapi integration does not work yet', () => {
const useQuery = createQueryHook(openint.fetchClient, 'openint-api')

const MyComponent = () => {
const {data, error, isLoading} = useQuery('/core/connection/{id}')

if (isLoading || !data) return 'Loading...'

if (error) return `An error occured: ${error}`

// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return data.displayName
}

expect(MyComponent).toBeTruthy()
})

0 comments on commit f3501d7

Please sign in to comment.