Last active
October 22, 2020 06:42
-
-
Save dabit3/331460795c0022308bc61ed4b0421c03 to your computer and use it in GitHub Desktop.
Next.js + Amplify - pages/api/pages.js
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
// pages/api/pages.js | |
import { API } from 'aws-amplify'; | |
import { listPosts } from '../../src/graphql/queries'; | |
export default async (_, res) => { | |
try { | |
const postData = await API.graphql({ query: listPosts }); | |
res.json({ posts: postData.data.listPosts.items}); | |
} catch (err) { | |
res.json({ error: true }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment