Skip to content

Instantly share code, notes, and snippets.

@dabit3
Last active October 22, 2020 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabit3/331460795c0022308bc61ed4b0421c03 to your computer and use it in GitHub Desktop.
Save dabit3/331460795c0022308bc61ed4b0421c03 to your computer and use it in GitHub Desktop.
Next.js + Amplify - pages/api/pages.js
// 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