Skip to content

Commit

Permalink
Filtering fixes to document-field example (#6889)
Browse files Browse the repository at this point in the history
* Filtering tweaks to example.

* Create eleven-lemons-fetch.md
  • Loading branch information
bladey authored Nov 7, 2021
1 parent 3614757 commit 191c468
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-lemons-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/example-document-field': patch
---

Updated GraphQL filters to use most recent API.
10 changes: 5 additions & 5 deletions examples/document-field/src/pages/author/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export default function Post({ author }: { author: any }) {
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
const data = await fetchGraphQL(gql`
query {
allAuthors {
authors {
id
}
}
`);
return {
paths: data.allAuthors.map((post: any) => ({ params: { id: post.id } })),
paths: data.authors.map((post: any) => ({ params: { id: post.id } })),
fallback: 'blocking',
};
}
Expand All @@ -42,12 +42,12 @@ export async function getStaticProps({ params }: GetStaticPropsContext) {
const data = await fetchGraphQL(
gql`
query ($id: ID!) {
Author(where: { id: $id }) {
author(where: { id: $id }) {
name
bio {
document
}
posts {
posts(where: { status: { equals: published } }, orderBy: { publishDate: desc }) {
id
title
slug
Expand All @@ -57,5 +57,5 @@ export async function getStaticProps({ params }: GetStaticPropsContext) {
`,
{ id: params!.id }
);
return { props: { author: data.Author }, revalidate: 60 };
return { props: { author: data.author }, revalidate: 60 };
}
6 changes: 3 additions & 3 deletions examples/document-field/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ export default function Index({ authors }: { authors: Author[] }) {
export async function getStaticProps() {
const data = await fetchGraphQL(gql`
query {
allAuthors {
authors {
id
name
posts(where: { status: published }, orderBy: { publishDate: desc }) {
posts(where: { status: { equals: published } }, orderBy: { publishDate: desc }) {
id
slug
title
}
}
}
`);
return { props: { authors: data.allAuthors }, revalidate: 30 };
return { props: { authors: data.authors }, revalidate: 30 };
}
8 changes: 4 additions & 4 deletions examples/document-field/src/pages/post/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ export default function Post({ post }: { post: any }) {
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
const data = await fetchGraphQL(gql`
query {
allPosts {
posts {
slug
}
}
`);
return {
paths: data.allPosts.map((post: any) => ({ params: { slug: post.slug } })),
paths: data.posts.map((post: any) => ({ params: { slug: post.slug } })),
fallback: 'blocking',
};
}
Expand All @@ -83,7 +83,7 @@ export async function getStaticProps({ params }: GetStaticPropsContext) {
const data = await fetchGraphQL(
gql`
query ($slug: String!) {
Post(where: { slug: $slug }) {
post(where: { slug: $slug }) {
title
content {
document(hydrateRelationships: true)
Expand All @@ -98,5 +98,5 @@ export async function getStaticProps({ params }: GetStaticPropsContext) {
`,
{ slug: params!.slug }
);
return { props: { post: data.Post }, revalidate: 60 };
return { props: { post: data.post }, revalidate: 60 };
}

0 comments on commit 191c468

Please sign in to comment.