import { GRAPHQL_CONTEXT, memoizedGraphQLClient, useTenantAlias, useToken, } from "@saasquatch/component-boilerplate";
import { useDomContextState } from "@saasquatch/stencil-hooks";
import { useEffect } from "@saasquatch/universal-hooks";
export async function useGraphQLClientProvider({ domain }) {
  const token = useToken();
  const appDomain = domain;
  const tenantAlias = useTenantAlias();
  // Memoization is shared. One client per domain, tenant and token (or null)
  const managedIdentityClient = memoizedGraphQLClient(appDomain, tenantAlias, token);
  const [, setGraphQLClient] = useDomContextState(GRAPHQL_CONTEXT, managedIdentityClient);
  useEffect(() => {
    setGraphQLClient(managedIdentityClient);
  }, [managedIdentityClient]);
}
