@shopify/koa-shopify-graphql-proxy
A wrapper around `koa-better-http-proxy` which allows easy proxying of GraphQL requests from an embedded Shopify app
Last updated 11 days ago by shopify-dep .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @shopify/koa-shopify-graphql-proxy 
SYNC missed versions from official npm registry.

@shopify/koa-shopify-graphql-proxy

Build Status License: MIT npm version

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
import koa from 'koa';
import session from 'koa-session';
import createShopifyAuth from '@shopify/koa-shopify-auth';
import proxy, {ApiVersion} from '@shopify/koa-shopify-graphql-proxy';

const app = koa();

app.use(session());

app.use(
  createShopifyAuth({
    /* your config here */
  }),
);

app.use(proxy({version: ApiVersion.Unstable}));

This allows client side scripts to query a logged in merchant's shop without needing to know the users access token.

fetch('/graphql', {credentials: 'include', body: mySerializedGraphQL});

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
import mount from 'koa-mount';

//....

app.use(mount('/shopify', proxy({version: ApiVersion.Unstable}));
// client/some-component.js
fetch('/shopify/graphql', {credentials: 'include', body: mySerializedGraphQL});

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
import koa from 'koa';
import session from 'koa-session';
import proxy, {ApiVersion} from '@shopify/koa-shopify-graphql-proxy';

const app = koa();

app.use(session());

app.use(
  proxy({
    version: ApiVersion.Unstable,
    shop: '<my-shop-name>.myshopify.com',
    password: '<your-app-password>',
  }),
);

Current Tags

  • 4.0.1                                ...           latest (11 days ago)

29 Versions

  • 4.0.1                                ...           11 days ago
  • 4.0.0                                ...           2 months ago
  • 3.3.1                                ...           3 months ago
  • 3.3.0                                ...           4 months ago
  • 3.2.5                                ...           5 months ago
  • 3.2.4                                ...           6 months ago
  • 3.2.3                                ...           7 months ago
  • 3.2.2                                ...           8 months ago
  • 3.2.1                                ...           9 months ago
  • 3.2.0                                ...           9 months ago
  • 3.1.2                                ...           10 months ago
  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.3                                ...           a year ago
  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.1.5                                ...           a year ago
  • 2.1.3                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.1                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
Downloads
Today 0
This Week 8
This Month 3
Last Day 1
Last Week 23
Last Month 40
Dependencies (3)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |