From 04a3bebf5810734a63e70f8b236df9e582363fe1 Mon Sep 17 00:00:00 2001 From: Bram Borggreve Date: Tue, 6 Aug 2024 21:32:57 +0100 Subject: [PATCH] refactor: use sdk without provider --- libs/sdk/src/lib/get-graphql-sdk.ts | 1 + .../web/auth/data-access/src/lib/auth.provider.tsx | 6 ++---- libs/web/auth/data-access/src/lib/use-me.ts | 4 ++-- libs/web/core/data-access/src/index.ts | 1 - libs/web/core/data-access/src/lib/sdk-provider.tsx | 14 -------------- .../core/feature/src/lib/web-core-providers.tsx | 14 ++++++-------- .../src/lib/identity-provider-solana-link.tsx | 4 +--- .../src/lib/identity-provider-solana-login.tsx | 4 +--- .../src/lib/use-admin-find-many-identity.ts | 11 +++++++---- .../src/lib/use-user-find-many-identity.ts | 4 +--- .../src/lib/use-admin-find-many-user.ts | 4 +--- .../data-access/src/lib/use-admin-find-one-user.ts | 4 +--- .../data-access/src/lib/use-user-find-many-user.ts | 4 +--- .../data-access/src/lib/use-user-fine-one-user.ts | 3 +-- .../user/data-access/src/lib/use-user-profile.ts | 6 ++---- package.json | 3 ++- 16 files changed, 29 insertions(+), 58 deletions(-) delete mode 100644 libs/web/core/data-access/src/lib/sdk-provider.tsx diff --git a/libs/sdk/src/lib/get-graphql-sdk.ts b/libs/sdk/src/lib/get-graphql-sdk.ts index e3b43c2..10434ec 100644 --- a/libs/sdk/src/lib/get-graphql-sdk.ts +++ b/libs/sdk/src/lib/get-graphql-sdk.ts @@ -4,3 +4,4 @@ import { getGraphQLClient } from './get-graphql-client' export function getGraphQLSdk(url: string): Sdk { return getSdk(getGraphQLClient(url)) } +export const sdk: Sdk = getGraphQLSdk('/graphql') diff --git a/libs/web/auth/data-access/src/lib/auth.provider.tsx b/libs/web/auth/data-access/src/lib/auth.provider.tsx index 99b87ab..a399194 100644 --- a/libs/web/auth/data-access/src/lib/auth.provider.tsx +++ b/libs/web/auth/data-access/src/lib/auth.provider.tsx @@ -1,5 +1,4 @@ -import { LoginInput, RegisterInput, User } from '@pubkey-stack/sdk' -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { LoginInput, RegisterInput, sdk, User } from '@pubkey-stack/sdk' import { toastError, toastSuccess } from '@pubkey-ui/core' import { createContext, ReactNode, useContext, useEffect, useReducer } from 'react' import { useMe } from './use-me' @@ -62,8 +61,7 @@ function authReducer(state: AuthState, { type, payload }: AuthAction): AuthState } export function AuthProvider({ children }: { children: ReactNode }) { - const sdk = useSdk() - const me = useMe(sdk) + const me = useMe() const [state, dispatch] = useReducer(authReducer, { status: 'loading' }) diff --git a/libs/web/auth/data-access/src/lib/use-me.ts b/libs/web/auth/data-access/src/lib/use-me.ts index d91f084..2b93955 100644 --- a/libs/web/auth/data-access/src/lib/use-me.ts +++ b/libs/web/auth/data-access/src/lib/use-me.ts @@ -1,7 +1,7 @@ -import { Sdk } from '@pubkey-stack/sdk' +import { sdk } from '@pubkey-stack/sdk' import { useQuery } from '@tanstack/react-query' -export function useMe(sdk: Sdk) { +export function useMe() { return useQuery({ queryKey: ['me'], queryFn: async () => { diff --git a/libs/web/core/data-access/src/index.ts b/libs/web/core/data-access/src/index.ts index 97f5a24..3099671 100644 --- a/libs/web/core/data-access/src/index.ts +++ b/libs/web/core/data-access/src/index.ts @@ -1,2 +1 @@ export * from './lib/app-config.provider' -export * from './lib/sdk-provider' diff --git a/libs/web/core/data-access/src/lib/sdk-provider.tsx b/libs/web/core/data-access/src/lib/sdk-provider.tsx deleted file mode 100644 index a4754e8..0000000 --- a/libs/web/core/data-access/src/lib/sdk-provider.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { getGraphQLSdk, Sdk } from '@pubkey-stack/sdk' -import { createContext, ReactNode, useContext } from 'react' - -const Context = createContext({} as Sdk) - -export function SdkProvider({ children }: { children: ReactNode }) { - const sdk: Sdk = getGraphQLSdk('/graphql') - - return {children} -} - -export function useSdk() { - return useContext(Context) -} diff --git a/libs/web/core/feature/src/lib/web-core-providers.tsx b/libs/web/core/feature/src/lib/web-core-providers.tsx index 44b1036..43384e8 100644 --- a/libs/web/core/feature/src/lib/web-core-providers.tsx +++ b/libs/web/core/feature/src/lib/web-core-providers.tsx @@ -2,7 +2,7 @@ import '@pubkey-ui/core' import '@pubkey-ui/core/index.esm.css' import 'mantine-datatable/styles.layer.css' import { AuthProvider } from '@pubkey-stack/web-auth-data-access' -import { AppConfigProvider, SdkProvider } from '@pubkey-stack/web-core-data-access' +import { AppConfigProvider } from '@pubkey-stack/web-core-data-access' import { SolanaClusterProvider } from '@pubkey-stack/web-solana-data-access' import { toastError, UiTheme, UiThemeProvider } from '@pubkey-ui/core' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' @@ -23,13 +23,11 @@ export function WebCoreProviders({ children, theme }: { children: ReactNode; the return ( {children}} theme={theme}> - - - - {children} - - - + + + {children} + + ) diff --git a/libs/web/identity/data-access/src/lib/identity-provider-solana-link.tsx b/libs/web/identity/data-access/src/lib/identity-provider-solana-link.tsx index 890f43f..dcbfce1 100644 --- a/libs/web/identity/data-access/src/lib/identity-provider-solana-link.tsx +++ b/libs/web/identity/data-access/src/lib/identity-provider-solana-link.tsx @@ -1,5 +1,4 @@ -import { IdentityProvider } from '@pubkey-stack/sdk' -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { IdentityProvider, sdk } from '@pubkey-stack/sdk' import { toastError, toastSuccess } from '@pubkey-ui/core' import { useWallet } from '@solana/wallet-adapter-react' import { createContext, ReactNode, useContext } from 'react' @@ -17,7 +16,6 @@ export interface IdentityProviderSolanaContext { const Context = createContext({} as IdentityProviderSolanaContext) export function IdentityProviderSolanaLink({ children, refresh }: { children: ReactNode; refresh: () => void }) { - const sdk = useSdk() const { signMessage } = useWallet() const createSignature = useCreateSignature() async function linkIdentity({ publicKey }: { publicKey: string }) { diff --git a/libs/web/identity/data-access/src/lib/identity-provider-solana-login.tsx b/libs/web/identity/data-access/src/lib/identity-provider-solana-login.tsx index 1582847..2d9ffe8 100644 --- a/libs/web/identity/data-access/src/lib/identity-provider-solana-login.tsx +++ b/libs/web/identity/data-access/src/lib/identity-provider-solana-login.tsx @@ -1,5 +1,4 @@ -import { IdentityProvider } from '@pubkey-stack/sdk' -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { IdentityProvider, sdk } from '@pubkey-stack/sdk' import { toastError, toastSuccess } from '@pubkey-ui/core' import { useWallet } from '@solana/wallet-adapter-react' import { createContext, ReactNode, useContext } from 'react' @@ -13,7 +12,6 @@ export interface IdentityProviderSolanaLoginContext { const Context = createContext({} as IdentityProviderSolanaLoginContext) export function IdentityProviderSolanaLogin({ children, refresh }: { children: ReactNode; refresh: () => void }) { - const sdk = useSdk() const { signMessage } = useWallet() const createSignature = useCreateSignature() diff --git a/libs/web/identity/data-access/src/lib/use-admin-find-many-identity.ts b/libs/web/identity/data-access/src/lib/use-admin-find-many-identity.ts index c02c384..6273d44 100644 --- a/libs/web/identity/data-access/src/lib/use-admin-find-many-identity.ts +++ b/libs/web/identity/data-access/src/lib/use-admin-find-many-identity.ts @@ -1,13 +1,16 @@ import { modals } from '@mantine/modals' -import { Identity, IdentityAdminCreateInput, IdentityAdminFindManyInput, IdentityProvider } from '@pubkey-stack/sdk' -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { + Identity, + IdentityAdminCreateInput, + IdentityAdminFindManyInput, + IdentityProvider, + sdk, +} from '@pubkey-stack/sdk' import { toastError, toastSuccess } from '@pubkey-ui/core' import { useQuery } from '@tanstack/react-query' import { useState } from 'react' export function useAdminFindManyIdentity({ ownerId, provider }: { ownerId?: string; provider?: IdentityProvider }) { - const sdk = useSdk() - const [input] = useState({ ownerId: ownerId, provider: provider, diff --git a/libs/web/identity/data-access/src/lib/use-user-find-many-identity.ts b/libs/web/identity/data-access/src/lib/use-user-find-many-identity.ts index 0beffb6..8cd7b1a 100644 --- a/libs/web/identity/data-access/src/lib/use-user-find-many-identity.ts +++ b/libs/web/identity/data-access/src/lib/use-user-find-many-identity.ts @@ -1,11 +1,9 @@ -import { Identity, IdentityProvider, IdentityUserFindManyInput } from '@pubkey-stack/sdk' -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { Identity, IdentityProvider, IdentityUserFindManyInput, sdk } from '@pubkey-stack/sdk' import { toastError, toastSuccess } from '@pubkey-ui/core' import { useQuery } from '@tanstack/react-query' import { useMemo } from 'react' export function useUserFindManyIdentity({ username }: { username: string }) { - const sdk = useSdk() const input: IdentityUserFindManyInput = useMemo(() => ({ username }), [username]) const query = useQuery({ queryKey: ['user', 'find-many-identity', input], diff --git a/libs/web/user/data-access/src/lib/use-admin-find-many-user.ts b/libs/web/user/data-access/src/lib/use-admin-find-many-user.ts index 50c4443..2d83cff 100644 --- a/libs/web/user/data-access/src/lib/use-admin-find-many-user.ts +++ b/libs/web/user/data-access/src/lib/use-admin-find-many-user.ts @@ -1,11 +1,9 @@ -import { UserAdminCreateInput, UserAdminFindManyInput, UserRole, UserStatus } from '@pubkey-stack/sdk' -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { sdk, UserAdminCreateInput, UserAdminFindManyInput, UserRole, UserStatus } from '@pubkey-stack/sdk' import { toastError, toastSuccess } from '@pubkey-ui/core' import { useQuery } from '@tanstack/react-query' import { useState } from 'react' export function useAdminFindManyUser(props?: UserAdminFindManyInput) { - const sdk = useSdk() const [role, setRole] = useState(undefined) const [status, setStatus] = useState(undefined) const [limit, setLimit] = useState(props?.limit ?? 10) diff --git a/libs/web/user/data-access/src/lib/use-admin-find-one-user.ts b/libs/web/user/data-access/src/lib/use-admin-find-one-user.ts index 7586aab..c09d73c 100644 --- a/libs/web/user/data-access/src/lib/use-admin-find-one-user.ts +++ b/libs/web/user/data-access/src/lib/use-admin-find-one-user.ts @@ -1,10 +1,8 @@ -import { UserAdminUpdateInput } from '@pubkey-stack/sdk' -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { sdk, UserAdminUpdateInput } from '@pubkey-stack/sdk' import { toastError, toastSuccess } from '@pubkey-ui/core' import { useQuery } from '@tanstack/react-query' export function useAdminFindOneUser({ userId }: { userId: string }) { - const sdk = useSdk() const query = useQuery({ queryKey: ['admin', 'find-one-user', userId], queryFn: () => sdk.adminFindOneUser({ userId }).then((res) => res.data), diff --git a/libs/web/user/data-access/src/lib/use-user-find-many-user.ts b/libs/web/user/data-access/src/lib/use-user-find-many-user.ts index 9ec7bf1..49727a9 100644 --- a/libs/web/user/data-access/src/lib/use-user-find-many-user.ts +++ b/libs/web/user/data-access/src/lib/use-user-find-many-user.ts @@ -1,10 +1,8 @@ -import { UserUserFindManyInput } from '@pubkey-stack/sdk' -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { sdk, UserUserFindManyInput } from '@pubkey-stack/sdk' import { useQuery } from '@tanstack/react-query' import { useState } from 'react' export function useUserFindManyUser(props?: UserUserFindManyInput) { - const sdk = useSdk() const [limit, setLimit] = useState(props?.limit ?? 10) const [page, setPage] = useState(props?.page ?? 1) const [search, setSearch] = useState('') diff --git a/libs/web/user/data-access/src/lib/use-user-fine-one-user.ts b/libs/web/user/data-access/src/lib/use-user-fine-one-user.ts index c042977..75e43fd 100644 --- a/libs/web/user/data-access/src/lib/use-user-fine-one-user.ts +++ b/libs/web/user/data-access/src/lib/use-user-fine-one-user.ts @@ -1,8 +1,7 @@ -import { useSdk } from '@pubkey-stack/web-core-data-access' +import { sdk } from '@pubkey-stack/sdk' import { useQuery } from '@tanstack/react-query' export function useUserFineOneUser({ username }: { username: string }) { - const sdk = useSdk() const query = useQuery({ queryKey: ['user', 'find-one-user', username], queryFn: () => sdk.userFindOneUser({ username }).then((res) => res.data), diff --git a/libs/web/user/data-access/src/lib/use-user-profile.ts b/libs/web/user/data-access/src/lib/use-user-profile.ts index d32dcd0..e629bad 100644 --- a/libs/web/user/data-access/src/lib/use-user-profile.ts +++ b/libs/web/user/data-access/src/lib/use-user-profile.ts @@ -1,12 +1,10 @@ -import { UserUserUpdateInput } from '@pubkey-stack/sdk' +import { sdk, UserUserUpdateInput } from '@pubkey-stack/sdk' import { useAuth, useMe } from '@pubkey-stack/web-auth-data-access' -import { useSdk } from '@pubkey-stack/web-core-data-access' import { toastError, toastSuccess } from '@pubkey-ui/core' import { useUserFineOneUser } from './use-user-fine-one-user' export function useUserProfile() { - const sdk = useSdk() - const me = useMe(sdk) + const me = useMe() const { user } = useAuth() const { query } = useUserFineOneUser({ username: user?.username as string }) diff --git a/package.json b/package.json index 153ccb7..35d5978 100644 --- a/package.json +++ b/package.json @@ -188,5 +188,6 @@ "*.{js,json,css,scss,md,ts,tsx,html,graphql}": [ "pnpm nx format --uncommitted" ] - } + }, + "packageManager": "pnpm@9.6.0+sha256.dae0f7e822c56b20979bb5965e3b73b8bdabb6b8b8ef121da6d857508599ca35" }