diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-03-09 23:23:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-09 23:23:47 +0100 |
| commit | 847b7303278c7894e5d6b055e0e654f6cf809330 (patch) | |
| tree | 1145c488ee0580eeb0709863c98f6ef2f413f478 /src/services | |
| parent | 5b6639a3cf9b6c63045cb82e6ef1a43b0742c367 (diff) | |
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
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/graphql/queries.ts | 52 |
1 files changed, 24 insertions, 28 deletions
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<Slug[]> => { export const getPostBySlug = async (slug: string): Promise<Article> => { 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<Article> => { const variables = { slug }; const response = await fetchApi<PostBy>(query, variables); - return getFormattedPost(response.postBy); + return getFormattedPost(response.post); }; //============================================================================== @@ -235,24 +235,22 @@ export const getPostBySlug = async (slug: string): Promise<Article> => { export const getCommentsByPostId = async (id: number): Promise<Comment[]> => { 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<Comment[]> => { const variables = { id }; const response = await fetchApi<CommentsByPostId>(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<Comment[]> => { export const getTopicBySlug = async (slug: string): Promise<Topic> => { 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<Topic> => { const variables = { slug }; const response = await fetchApi<TopicBy>(query, variables); - return getFormattedTopic(response.topicBy); + return getFormattedTopic(response.topic); }; export const getAllTopicsSlug = async (): Promise<Slug[]> => { @@ -400,8 +396,8 @@ export const getAllTopics = async (): Promise<TopicPreview[]> => { export const getThematicBySlug = async (slug: string): Promise<Thematic> => { 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<Thematic> => { const variables = { slug }; const response = await fetchApi<ThematicBy>(query, variables); - return getFormattedThematic(response.thematicBy); + return getFormattedThematic(response.thematic); }; export const getAllThematicsSlug = async (): Promise<Slug[]> => { |
