Created
June 23, 2021 04:36
-
-
Save JakeTrock/613a80db4875ef0fee84a6904e019e27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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