Created
December 16, 2018 12:39
-
-
Save that-coder/6ed429e1c420e26239407d2ce97d1551 to your computer and use it in GitHub Desktop.
This file contains 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
'use strict'; | |
const aws_exports = require('./aws-export').default; | |
// CONFIG | |
const AppSync = { | |
"graphqlEndpoint": aws_exports.graphqlEndpoint, | |
"region": aws_exports.region, | |
"authenticationType": aws_exports.authenticationType, | |
"apiKey": aws_exports.apiKey, | |
}; | |
const ApiId = aws_exports.ApiId; | |
// POLYFILLS | |
global.WebSocket = require('ws'); | |
global.window = global.window || { | |
setTimeout: setTimeout, | |
clearTimeout: clearTimeout, | |
WebSocket: global.WebSocket, | |
ArrayBuffer: global.ArrayBuffer, | |
addEventListener: function () { }, | |
navigator: { onLine: true } | |
}; | |
global.localStorage = { | |
store: {}, | |
getItem: function (key) { | |
return this.store[key] | |
}, | |
setItem: function (key, value) { | |
this.store[key] = value | |
}, | |
removeItem: function (key) { | |
delete this.store[key] | |
} | |
}; | |
require('es6-promise').polyfill(); | |
require('isomorphic-fetch'); | |
// Require AppSync module | |
const AUTH_TYPE = require('aws-appsync/lib/link/auth-link').AUTH_TYPE; | |
const AWSAppSyncClient = require('aws-appsync').default; | |
// INIT | |
// Set up AppSync client | |
const client = new AWSAppSyncClient({ | |
url: AppSync.graphqlEndpoint, | |
region: AppSync.region, | |
auth: { | |
type: AUTH_TYPE.API_KEY, | |
apiKey: AppSync.apiKey | |
} | |
}); | |
// GRAPHQL | |
const gql = require('graphql-tag'); | |
const mutate = gql(` | |
mutation updatePost($updatepostinput: UpdatePostInput!) { | |
updatePost (input: $updatepostinput) { | |
author | |
id | |
url | |
content | |
title | |
} | |
} | |
`) | |
// APP CODE | |
client.hydrated().then(function (client) { | |
// Now run a mutation | |
const vari = { | |
"author": "Brady", | |
"id": "2", | |
"url": "nts.taxi" | |
} | |
client.mutate({ mutation: mutate, variables:{updatepostinput: vari} }) | |
.then(function logData(data) { | |
if(data) { | |
console.log('(Mutate): updating Data ----------->', data); | |
} | |
else { | |
console.log('Error!'); | |
} | |
}) | |
.catch(console.error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment