2023-03-16 10:17:00 +00:00
|
|
|
import { useAppBridge } from "@saleor/app-sdk/app-bridge";
|
|
|
|
import { PropsWithChildren } from "react";
|
|
|
|
import { Provider } from "urql";
|
|
|
|
|
|
|
|
import { createClient } from "../lib/graphql";
|
|
|
|
|
2023-04-05 18:27:23 +00:00
|
|
|
export function GraphQLProvider(props: PropsWithChildren<{}>) {
|
2023-03-16 10:17:00 +00:00
|
|
|
const { appBridgeState } = useAppBridge();
|
|
|
|
const saleorApiUrl = appBridgeState?.saleorApiUrl!;
|
|
|
|
|
|
|
|
const client = createClient(saleorApiUrl, async () => ({
|
|
|
|
token: appBridgeState?.token!,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return <Provider value={client} {...props} />;
|
|
|
|
}
|