@shopify/koa-shopify-graphql-proxy
A wrapper around koa-better-http-proxy which allows easy proxying of graphql requests from an embedded shopify app.
Installation
$ yarn add @shopify/koa-shopify-graphql-proxy
Usage
The module exports a proxy middleware as it's default export. It expects that you have other middleware set up (such as koa-shopify-auth) to authenticate requests with Shopify, and have session data stored on ctx.session
.
Basic
Attaching the middleware will proxy any requests sent to /graphql
on your app to the current logged in shop found in session.
// server/index.js;;;; const app = ; app; app; app;
This allows client side scripts to query a logged in merchant's shop without needing to know the users access token.
;
Custom path
If you have your own /graphql
route and don't want to clobber it, you can use a library like (koa-mount
)[https://github.com/koajs/mount] to namespace the middleware.
// server/index; //.... app
// client/some-component.js;
Private app
If you have a private shopify app, you can than skip over the auth step and use this library directly for setting up graphql proxy.
// server/index.js;;; const app = ; app; app;