Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
86 stars 9 forks source link

Allow passing instance of `app` into `AppBridgeProvider` #218

Open par5er opened 1 year ago

par5er commented 1 year ago

Describe the feature you’d like

A way to pass an existing app instance into @shopify/app-bridge-react's AppBridge provider. Something like:

const app = createApp( ... );

const apiClient = new ApolloClient({
  link: new HttpLink({
    credentials: "same-origin",
    fetch: authenticatedFetch(app), // ensures that all requests triggered by the ApolloClient are authenticated
  }),
  cache: new InMemoryCache(),
});

ReactDOM.createRoot(root).render(
  <Provider app={app}> {/* passing app instead of config here */}
    <App />
  </Provider>
);

The authenticatedFetch example given in Shopify Docs will not work with @shopify/app-bridge-react because there is no way to access the app instance.

Describe alternatives you've considered

I can use @shopify/app-bridge directly (no provider), but I'm afraid it will break my app

Additional context