Skip to content

Instantly share code, notes, and snippets.

@JakeTrock
Created June 23, 2021 04:36
Show Gist options
  • Save JakeTrock/613a80db4875ef0fee84a6904e019e27 to your computer and use it in GitHub Desktop.
Save JakeTrock/613a80db4875ef0fee84a6904e019e27 to your computer and use it in GitHub Desktop.
/* Amplify Params - DO NOT EDIT
API_name_GRAPHQLAPIENDPOINTOUTPUT
API_name_GRAPHQLAPIIDOUTPUT
ENV
REGION
Amplify Params - DO NOT EDIT */const axios = require('axios');
const gql = require('graphql-tag');
const graphql = require('graphql');
const { print } = graphql;
const updateUtil = gql`
mutation UpdateUtil(
$input: UpdateUtilInput!
$condition: ModelUtilConditionInput
) {
updateUtil(input: $input, condition: $condition) {
id
owner
title
description
numUses
}
`
exports.handler = event => {
//eslint-disable-line
try {
await axios({
url: event.API_URL,
method: 'post',
headers: {//TODO:this could be a bad/nonexistent key
'x-api-key': event.API_name_GRAPHQLAPIKEYOUTPUT
},
data: {
query: print(updateUtil),
variables: {
input: {
//TODO: I am unsure of how to get the current number of uses(int) so I just fudged it to show what id do
numUses: event.record.numUses++
}
}
}
});
return Promise.resolve();
} catch (e) {
return Promise.reject(e.message);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment