Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/with-apollo-and-redux/components/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default function PostList() {

const loadingMorePosts = networkStatus === NetworkStatus.fetchMore;

if (error) return <ErrorMessage message="Error loading posts." />;
if (loading && !loadingMorePosts) return <div>Loading</div>;
if (!data) return null;

const { allPosts, _allPostsMeta } = data;

const loadMorePosts = () => {
Expand All @@ -45,9 +49,6 @@ export default function PostList() {
});
};

if (error) return <ErrorMessage message="Error loading posts." />;
if (loading && !loadingMorePosts) return <div>Loading</div>;

const areMorePosts = allPosts.length < _allPostsMeta.count;

return (
Expand Down
4 changes: 2 additions & 2 deletions examples/with-apollo-and-redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"dependencies": {
"@apollo/client": "^3.0.0",
"deepmerge": "^4.2.2",
"graphql": "14.5.8",
"lodash": "4.17.20",
"graphql": "16.13.1",
"lodash": "^4.17.23",
"next": "latest",
"prop-types": "^15.6.0",
"react": "^18.2.0",
Expand Down
13 changes: 9 additions & 4 deletions examples/with-apollo-and-redux/pages/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ const ApolloPage = () => (
export async function getStaticProps() {
const apolloClient = initializeApollo();

await apolloClient.query({
query: ALL_POSTS_QUERY,
variables: allPostsQueryVars,
});
try {
await apolloClient.query({
query: ALL_POSTS_QUERY,
variables: allPostsQueryVars,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you'd want to error at build time, not hide the error or hope to catch it during rendering. You might end up shipping bad UI

Copy link
Author

@ZaforAbdullah ZaforAbdullah Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It call https://nextjs-graphql-with-prisma-simple-foo.vercel.app/api endpoint which is empty, hence the example project can't be build at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm but that's another issue then, that project should serve data... I don't have time to look into at the moment - but I'll try later

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I asked them about it, they'll look into it. 🙏

} catch (_) {
// If the API is unavailable, fall back to an empty initial state.
// The PostList component will surface the error via its own useQuery call.
}

return {
props: {
Expand Down
13 changes: 9 additions & 4 deletions examples/with-apollo-and-redux/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ export async function getStaticProps() {
lastUpdate: Date.now(),
});

await apolloClient.query({
query: ALL_POSTS_QUERY,
variables: allPostsQueryVars,
});
try {
await apolloClient.query({
query: ALL_POSTS_QUERY,
variables: allPostsQueryVars,
});
} catch (_) {
// If the API is unavailable, fall back to an empty initial state.
// The PostList component will surface the error via its own useQuery call.
}

return {
props: {
Expand Down
Loading