saleor-apps-redis_apl/apps/taxes/src/providers/GraphQLProvider.tsx

21 lines
562 B
TypeScript
Raw Normal View History

import { useAppBridge } from "@saleor/app-sdk/app-bridge";
import { PropsWithChildren } from "react";
import { Provider } from "urql";
import { createGraphQLClient } from "@saleor/apps-shared";
export function GraphQLProvider(props: PropsWithChildren<{}>) {
const { appBridgeState } = useAppBridge();
if (!appBridgeState?.saleorApiUrl) {
return <div {...props}></div>;
}
const client = createGraphQLClient({
saleorApiUrl: appBridgeState.saleorApiUrl,
token: appBridgeState.token,
});
return <Provider value={client} {...props} />;
}