From 847b7303278c7894e5d6b055e0e654f6cf809330 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 9 Mar 2022 23:23:47 +0100 Subject: refactor: update graphql queries (#14) * refactor: replace postBy query postBy is now deprecated in WPGraphQL v1.7 * refactor: update post comments query PostBy is deprecated and it is now possible to use the post ID to query comments. * refactor: update get topic by slug query topicBy is deprecated * refactor: update get thematic by slug query thematicBy is deprecated --- src/services/graphql/queries.ts | 52 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'src/services') diff --git a/src/services/graphql/queries.ts b/src/services/graphql/queries.ts index 8dd8563..9caf62b 100644 --- a/src/services/graphql/queries.ts +++ b/src/services/graphql/queries.ts @@ -163,8 +163,8 @@ export const getAllPostsSlug = async (): Promise => { export const getPostBySlug = async (slug: string): Promise
=> { const query = gql` - query PostBySlug($slug: String!) { - postBy(slug: $slug) { + query PostBySlug($slug: ID!) { + post(id: $slug, idType: SLUG) { acfPosts { postsInTopic { ... on Topic { @@ -226,7 +226,7 @@ export const getPostBySlug = async (slug: string): Promise
=> { const variables = { slug }; const response = await fetchApi(query, variables); - return getFormattedPost(response.postBy); + return getFormattedPost(response.post); }; //============================================================================== @@ -235,24 +235,22 @@ export const getPostBySlug = async (slug: string): Promise
=> { export const getCommentsByPostId = async (id: number): Promise => { const query = gql` - query MyQuery($id: Int) { - postBy(postId: $id) { - comments(where: { order: ASC, orderby: COMMENT_DATE }) { - nodes { - approved - author { - node { - gravatarUrl - id - name - url - } + query PostComments($id: ID!) { + comments(where: { contentId: $id, order: ASC, orderby: COMMENT_DATE }) { + nodes { + approved + author { + node { + databaseId + gravatarUrl + name + url } - commentId - content - date - parentDatabaseId } + content + databaseId + date + parentDatabaseId } } } @@ -260,9 +258,7 @@ export const getCommentsByPostId = async (id: number): Promise => { const variables = { id }; const response = await fetchApi(query, variables); - const formattedComments = getFormattedComments( - response.postBy.comments.nodes - ); + const formattedComments = getFormattedComments(response.comments.nodes); return buildCommentsTree(formattedComments); }; @@ -273,8 +269,8 @@ export const getCommentsByPostId = async (id: number): Promise => { export const getTopicBySlug = async (slug: string): Promise => { const query = gql` - query TopicBySlug($slug: String!) { - topicBy(slug: $slug) { + query TopicBySlug($slug: ID!) { + topic(id: $slug, idType: SLUG) { acfTopics { officialWebsite postsInTopic { @@ -358,7 +354,7 @@ export const getTopicBySlug = async (slug: string): Promise => { const variables = { slug }; const response = await fetchApi(query, variables); - return getFormattedTopic(response.topicBy); + return getFormattedTopic(response.topic); }; export const getAllTopicsSlug = async (): Promise => { @@ -400,8 +396,8 @@ export const getAllTopics = async (): Promise => { export const getThematicBySlug = async (slug: string): Promise => { const query = gql` - query ThematicBySlug($slug: String!) { - thematicBy(slug: $slug) { + query ThematicBySlug($slug: ID!) { + thematic(id: $slug, idType: SLUG) { acfThematics { postsInThematic { ... on Post { @@ -477,7 +473,7 @@ export const getThematicBySlug = async (slug: string): Promise => { const variables = { slug }; const response = await fetchApi(query, variables); - return getFormattedThematic(response.thematicBy); + return getFormattedThematic(response.thematic); }; export const getAllThematicsSlug = async (): Promise => { -- cgit v1.2.3