-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull-amplify.js
59 lines (51 loc) · 1.36 KB
/
full-amplify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const Amplify = require('@aws-amplify/core').default;
const Auth = require('aws-amplify').Auth;
const API = require('aws-amplify').API;
const graphqlOperation = require('aws-amplify').graphqlOperation;
Amplify.configure({
Auth: {
region: '',
userPoolId: '',
userPoolWebClientId: '',
},
API: {
aws_appsync_graphqlEndpoint: '',
aws_appsync_region: '',
aws_appsync_authenticationType: 'AMAZON_COGNITO_USER_POOLS'
}
});
async function signIn(username, password) {
try {
const user = await Auth.signIn(username, password);
console.log('User logged in:', user);
return user;
} catch (error) {
console.error('Error signing in:', error);
throw error;
}
}
async function fetchAppSyncData(query) {
try {
const data = await API.graphql(graphqlOperation(query));
return data;
} catch (error) {
console.error('Error fetching data from AppSync:', error);
throw error;
}
}
async function main() {
const username = '';
const password = '';
await signIn(username, password);
const sampleQuery = `
{
getItems(userId: "12") {
itemName
itemId
}
}
`;
const results = await fetchAppSyncData(sampleQuery);
console.log(JSON.stringify(results, null, 2));
}
main();