4.0.0 • Published 1 year ago

fastify-shopify-graphql-proxy v4.0.0

Weekly downloads
1
License
Hippocratic-3.0
Repository
github
Last release
1 year ago

fastify-shopify-graphql-proxy

License: Hippocratic 3.0 code style: prettier npm version codecov Main WorkFlow CodeQL WorkFlow

fastify-shopify-graphql-proxy is a plugin for the Fastify framework that is based on koa-shopify-graphql-proxy. It allows for proxying of GraphQL requests from an embedded Shopify app to Shopify's GraphQL API.

Any POST request made to /graphql will be proxied to Shopify's GraphQL API and the response will be returned.

Supported Fastify versions

  • Fastify v4.x

Supported Node.js versions

The latest versions of the following Node.js versions are tested and supported.

  • 16
  • 18

Quick Start

Install the package using npm:

npm i --save-exact fastify-shopify-graphql-proxy

or yarn:

yarn add fastify-shopify-graphql-proxy

or pnpm:

pnpm add --save-exact fastify-shopify-graphql-proxy

Code Examples

Custom App

If you are creating a Custom Shopify app, you can skip over the auth step and provide the shop URL and accessToken.

import shopifyGraphQLProxy, { ApiVersion } from "fastify-shopify-graphql-proxy";
import Fastify from "fastify";

const server = Fastify({
  logger: true,
});

await server.register(shopifyGraphQLProxy, {
  shop: "https://my-shopify-store.myshopify.com",
  version: ApiVersion.Stable,
  accessToken: "SHOPIFY_API_ACCESS_TOKEN",
});

server.listen({ port: 3000 }, function (err, address) {
  if (err) {
    server.log.error(err);
    process.exit(1);
  }

  server.log.info(`server listening on ${address}`);
});

Public App (Not currently possible)

This Fastify plugin will get the shop url and AccessToken from the current session of the logged-in store. Note: You will need to use fastify-session for this to work.

import fastifyCookie from "fastify-cookie";
import fastifySession from "@fastify/session";
import createShopifyAuth from "fastify-shopify-auth";
import shopifyGraphQLProxy, { ApiVersion } from "fastify-shopify-graphql-proxy";
import Fastify from "fastify";

const server = Fastify({
  logger: true,
});

await server.register(fastifyCookie);
await server.register(fastifySession, { secret: "a secret with a minimum length of 32 characters" });

await server.register(
  await createShopifyAuth({
    /* your config here */
  }),
);

await server.register(shopifyGraphQLProxy, {
  version: ApiVersion.Stable, // API Version "2022-04"
});

server.listen({ port: 3000 }, function (err, address) {
  if (err) {
    server.log.error(err);
    process.exit(1);
  }

  server.log.info(`server listening on ${address}`);
});

API

shopifyGraphQLProxy(opts)

Options:

  • shop (Optional): a string value that is the Shopify URL for your store. Gets value from session if available.
  • accessToken (Optional): a string value that is the Custom App API Key. Gets value from session if available.
  • version (Optional): Shopify GraphQL version (example: "2022-04").
  • prefix (Optional): You can set a custom path for the shopifyGraphQLProxy GraphQL endpoint by specifying a route prefix.

Here are all the Shopify API GraphQL versions that can be imported from the enum ApiVersion and used such as ApiVersion.April22:

October22 = "2022-10"
July22 = "2022-07"
April22 = "2022-04"
January22 = "2022-01"
October21 = "2021-10"
Stable = "2022-10"
Unstable = 'Unstable'
Unversioned = 'unversioned'
4.0.0

1 year ago

3.0.0

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-1

2 years ago

1.0.0-0

2 years ago

0.15.0

2 years ago

0.16.0

2 years ago

0.17.0

2 years ago

0.18.0

2 years ago

0.14.0

3 years ago

0.13.0

3 years ago

0.12.2

3 years ago

0.11.0

3 years ago

0.12.0

3 years ago

0.11.1

3 years ago

0.12.1

3 years ago

0.9.0

3 years ago

0.8.0

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago