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

22 lines
583 B
TypeScript
Raw Normal View History

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