diff --git a/build/api/react-client-tenant.api.md b/build/api/react-client-tenant.api.md index b4848c62a..32a18a4b2 100644 --- a/build/api/react-client-tenant.api.md +++ b/build/api/react-client-tenant.api.md @@ -4,7 +4,7 @@ ```ts -import type { Fetcher } from 'graphql-ts-client-api'; +import { Fetcher } from 'graphql-ts-client-api'; import { ModelType } from 'graphql-ts-client-api'; export { ModelType } @@ -16,9 +16,6 @@ export const useTenantApi: () => Promise; - -export * from "@contember/graphql-client-tenant"; - // (No @packageDocumentation comment for this package) ``` diff --git a/packages/playground/admin/lib/components/dev/login-panel.tsx b/packages/playground/admin/lib/components/dev/login-panel.tsx index 4a8aee899..878df950e 100644 --- a/packages/playground/admin/lib/components/dev/login-panel.tsx +++ b/packages/playground/admin/lib/components/dev/login-panel.tsx @@ -4,7 +4,8 @@ import { FieldContainer } from '../form' import { Input } from '../ui/input' import { Button } from '../ui/button' import { useSessionTokenWithMeta, useSetSessionToken } from '@contember/react-client' -import * as TenantApi from '@contember/react-client-tenant' +import * as TenantApi from '@contember/graphql-client-tenant' +import { useTenantApi } from '@contember/react-client-tenant' export const LoginWithEmail = () => { const [email, setEmail] = useState('') @@ -12,7 +13,7 @@ export const LoginWithEmail = () => { const addToast = useShowToast() const [isSubmitting, setSubmitting] = useState(false) const setSessionToken = useSetSessionToken() - const api = TenantApi.useTenantApi() + const api = useTenantApi() const submit = useCallback(async (e: SyntheticEvent) => { e.preventDefault() diff --git a/packages/playground/admin/lib/hooks/useInvite.ts b/packages/playground/admin/lib/hooks/useInvite.ts index 443f13263..f95a47891 100644 --- a/packages/playground/admin/lib/hooks/useInvite.ts +++ b/packages/playground/admin/lib/hooks/useInvite.ts @@ -1,4 +1,5 @@ -import * as TenantApi from '@contember/react-client-tenant' +import * as TenantApi from '@contember/graphql-client-tenant' +import { useTenantApi } from '@contember/react-client-tenant' import { useCallback } from 'react' const InviteFetcher = TenantApi.inviteResponse$$ @@ -8,7 +9,7 @@ const InviteFetcher = TenantApi.inviteResponse$$ export type InviteErrorCodes = TenantApi.InviteErrorCode export const useInvite = () => { - const api = TenantApi.useTenantApi() + const api = useTenantApi() return useCallback(async (variables: { email: string, diff --git a/packages/playground/admin/lib/hooks/useInviteUser.tsx b/packages/playground/admin/lib/hooks/useInviteUser.tsx index bcc2b33a1..85aee7de0 100644 --- a/packages/playground/admin/lib/hooks/useInviteUser.tsx +++ b/packages/playground/admin/lib/hooks/useInviteUser.tsx @@ -4,7 +4,7 @@ import { useInvite } from './useInvite' import { ToastContent, useShowToast } from '../components/ui/toast' import { useProjectSlug } from '@contember/react-client' import { EntityAccessor } from '@contember/interface' -import * as TenantApi from '@contember/react-client-tenant' +import * as TenantApi from '@contember/graphql-client-tenant' import { useReferentiallyStableCallback } from '@contember/react-utils' import { dict } from '../dict' diff --git a/packages/react-client-tenant/package.json b/packages/react-client-tenant/package.json index 4a69ced92..0520155c0 100644 --- a/packages/react-client-tenant/package.json +++ b/packages/react-client-tenant/package.json @@ -40,7 +40,6 @@ "directory": "packages/react-client-tenant" }, "dependencies": { - "@contember/graphql-client-tenant": "^1.3.6", "@contember/react-client": "workspace:*", "graphql-ts-client-api": "^3.1.17" }, diff --git a/packages/react-client-tenant/src/hooks/useTenantApi.ts b/packages/react-client-tenant/src/hooks/useTenantApi.ts index f137cc7b4..a1c8f2dc5 100644 --- a/packages/react-client-tenant/src/hooks/useTenantApi.ts +++ b/packages/react-client-tenant/src/hooks/useTenantApi.ts @@ -1,7 +1,6 @@ -import { execute } from '@contember/graphql-client-tenant' import { useTenantGraphQlClient } from '@contember/react-client' import { useCallback } from 'react' -import type { Fetcher } from 'graphql-ts-client-api' +import { Fetcher, TextWriter, util } from 'graphql-ts-client-api' export const useTenantApi = () => { const client = useTenantGraphQlClient() @@ -15,15 +14,23 @@ export const useTenantApi = () => { }, ): Promise => { - return execute(fetcher, { - ...options, - executor: async (request, variables) => { - return await client.execute(request, { - variables, - headers: options?.headers, - apiToken: options?.apiToken, + const writer = new TextWriter() + writer.text(`${fetcher.fetchableType.name.toLowerCase()}`) + if (fetcher.variableTypeMap.size !== 0) { + writer.scope({ type: 'ARGUMENTS', multiLines: fetcher.variableTypeMap.size > 2, suffix: ' ' }, () => { + util.iterateMap(fetcher.variableTypeMap, ([name, type]) => { + writer.seperator() + writer.text(`$${name}: ${type}`) }) - }, + }) + } + writer.text(fetcher.toString()) + writer.text(fetcher.toFragmentString()) + + return client.execute(writer.toString(), { + variables: options?.variables, + headers: options?.headers, + apiToken: options?.apiToken, }) }, [client]) } diff --git a/packages/react-client-tenant/src/index.ts b/packages/react-client-tenant/src/index.ts index 5597ba19c..a9da8fe99 100644 --- a/packages/react-client-tenant/src/index.ts +++ b/packages/react-client-tenant/src/index.ts @@ -1,4 +1,3 @@ export * from './hooks' export type { ModelType } from 'graphql-ts-client-api' -export * from '@contember/graphql-client-tenant' diff --git a/packages/react-dataview/src/components/paging/DataViewSetItemsPerPageTrigger.tsx b/packages/react-dataview/src/components/paging/DataViewSetItemsPerPageTrigger.tsx index e8f7aeeec..c5659ec95 100644 --- a/packages/react-dataview/src/components/paging/DataViewSetItemsPerPageTrigger.tsx +++ b/packages/react-dataview/src/components/paging/DataViewSetItemsPerPageTrigger.tsx @@ -8,7 +8,7 @@ export interface DataViewSetItemsPerPageTriggerProps { value: number } -export const DataViewSetItemsPerPageTrigger = forwardRef(({ value, ...props }) => { +export const DataViewSetItemsPerPageTrigger = forwardRef(({ value, ...props }, ref) => { const { setItemsPerPage } = useDataViewPagingMethods() const { itemsPerPage: current } = useDataViewPagingState() @@ -18,6 +18,7 @@ export const DataViewSetItemsPerPageTrigger = forwardRef +export type FetchedIdentity = ModelType export const useFetchMe = () => { - const executor = TenantApi.useTenantApi() + const executor = useTenantApi() return useCallback(async () => { return (await executor(TenantApi.query$.me(identityFragment))).me }, [executor]) diff --git a/packages/react-identity/src/internal/hooks/useSignOut.ts b/packages/react-identity/src/internal/hooks/useSignOut.ts index 694560096..e065cf82e 100644 --- a/packages/react-identity/src/internal/hooks/useSignOut.ts +++ b/packages/react-identity/src/internal/hooks/useSignOut.ts @@ -1,12 +1,13 @@ -import * as TenantApi from '@contember/react-client-tenant' +import * as TenantApi from '@contember/graphql-client-tenant' +import { ModelType, useTenantApi } from '@contember/react-client-tenant' import { useCallback } from 'react' const signOutFragment = TenantApi.signOutResponse$$.error(TenantApi.signOutError$$) -export type SignOutResult = TenantApi.ModelType +export type SignOutResult = ModelType export const useSignOut = () => { - const api = TenantApi.useTenantApi() + const api = useTenantApi() return useCallback(async () => { return (await api(TenantApi.mutation$.signOut(signOutFragment))).signOut }, [api]) diff --git a/yarn.lock b/yarn.lock index ee6388c2e..b8e8e0732 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,7 +1463,6 @@ __metadata: version: 0.0.0-use.local resolution: "@contember/react-client-tenant@workspace:packages/react-client-tenant" dependencies: - "@contember/graphql-client-tenant": ^1.3.6 "@contember/react-client": "workspace:*" graphql-ts-client-api: ^3.1.17 react: ^18.2.0 @@ -1614,6 +1613,7 @@ __metadata: version: 0.0.0-use.local resolution: "@contember/react-identity@workspace:packages/react-identity" dependencies: + "@contember/graphql-client-tenant": ^1.3.6 "@contember/react-binding": "workspace:*" "@contember/react-client": "workspace:*" "@contember/react-client-tenant": "workspace:*"