Skip to content

Instantly share code, notes, and snippets.

@phawk
Created August 23, 2019 17:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phawk/1a410ec6a2f34066538e0141aff49e9d to your computer and use it in GitHub Desktop.
Save phawk/1a410ec6a2f34066538e0141aff49e9d to your computer and use it in GitHub Desktop.
Lambda Shopify graphql proxy endpoint
const https = require("https")
const fetch = require("isomorphic-fetch")
const Account = require("./models/account")
const authenticated = require("./lib/auth")
exports.handler = authenticated(async (event, context) => {
const { id: shopId, shopifyToken } = context.account
try {
const resp = await fetch(`https://${shopId}/admin/api/2019-07/graphql.json`, {
method: "POST",
headers: {
"X-Shopify-Access-Token": shopifyToken,
"Accept": "application/json",
"Content-Type": "application/json"
},
body: event.body,
agent: new https.Agent({
ca: require("ssl-root-cas/latest").create()
})
})
const text = await resp.text()
return {
statusCode: resp.status,
headers: { "Content-Type": "application/json" },
body: text
}
} catch(e) {
return {
statusCode: 400,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
error: "Bad request",
message: e.message
})
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment