2023-03-02 11:01:17 +00:00
|
|
|
import { useAppBridge } from "@saleor/app-sdk/app-bridge";
|
|
|
|
import { PropsWithChildren } from "react";
|
|
|
|
import { Provider } from "urql";
|
|
|
|
|
2023-06-19 13:59:27 +00:00
|
|
|
import { createGraphQLClient } from "@saleor/apps-shared";
|
2023-03-02 11:01:17 +00:00
|
|
|
|
2023-04-05 18:27:23 +00:00
|
|
|
export function GraphQLProvider(props: PropsWithChildren<{}>) {
|
2023-03-02 11:01:17 +00:00
|
|
|
const { appBridgeState } = useAppBridge();
|
|
|
|
|
|
|
|
if (!appBridgeState?.saleorApiUrl) {
|
|
|
|
return <div {...props}></div>;
|
|
|
|
}
|
|
|
|
|
2023-06-19 13:59:27 +00:00
|
|
|
const client = createGraphQLClient({
|
|
|
|
saleorApiUrl: appBridgeState.saleorApiUrl,
|
|
|
|
token: appBridgeState.token,
|
|
|
|
});
|
2023-03-02 11:01:17 +00:00
|
|
|
|
|
|
|
return <Provider value={client} {...props} />;
|
|
|
|
}
|