From 27f414ca9dadc7430831c7bb608e3ff123ece566 Mon Sep 17 00:00:00 2001 From: Andrew Glago Date: Fri, 21 Jun 2024 16:00:54 +0000 Subject: [PATCH 1/5] feat: add helpers for fetching site data --- packages/core/src/helpers/convenience.ts | 9 +++++++++ packages/core/src/helpers/index.ts | 1 + packages/core/src/helpers/site.ts | 14 ++++++++++++++ packages/core/src/index.ts | 1 + packages/core/src/lib/gql.ts | 14 ++++++++++++++ packages/core/src/types/index.ts | 10 ++++++++++ packages/react-sdk/src/hooks/index.ts | 4 ++++ packages/react-sdk/src/server/index.ts | 2 ++ packages/vue-sdk/src/hooks/index.ts | 2 ++ 9 files changed, 57 insertions(+) create mode 100644 packages/core/src/helpers/site.ts diff --git a/packages/core/src/helpers/convenience.ts b/packages/core/src/helpers/convenience.ts index dceade7d..8d3f9c05 100644 --- a/packages/core/src/helpers/convenience.ts +++ b/packages/core/src/helpers/convenience.ts @@ -11,6 +11,7 @@ import { getArticlesWithSummary, } from "./articles"; import { getAllTags } from "./metadata"; +import { getSite as _getSite } from "./site"; const config = { // eslint-disable-next-line turbo/no-undeclared-env-vars @@ -141,6 +142,13 @@ async function getRecommendedArticles(id: number | string) { return article.data.recommendedArticles as Article[]; } +async function getSite() { + const client = buildPantheonClient({ isClientSide: false }); + const site = await _getSite(client, client.siteId); + + return site; +} + export const PCCConvenienceFunctions = { buildPantheonClient, getAllArticles, @@ -149,4 +157,5 @@ export const PCCConvenienceFunctions = { getRecommendedArticles, getPaginatedArticles, getTags, + getSite, }; diff --git a/packages/core/src/helpers/index.ts b/packages/core/src/helpers/index.ts index 6194d6ff..8d7dd2ec 100644 --- a/packages/core/src/helpers/index.ts +++ b/packages/core/src/helpers/index.ts @@ -3,3 +3,4 @@ export * from "./convenience"; export * from "./errors"; export * from "./metadata"; export * from "./validator"; +export * from "./site"; diff --git a/packages/core/src/helpers/site.ts b/packages/core/src/helpers/site.ts new file mode 100644 index 00000000..e281db76 --- /dev/null +++ b/packages/core/src/helpers/site.ts @@ -0,0 +1,14 @@ +import { PantheonClient } from "../core/pantheon-client"; +import { GET_SITE_QUERY } from "../lib/gql"; +import { Site } from "../types"; + +export async function getSite(client: PantheonClient, id: string) { + const site = await client.apolloClient.query({ + query: GET_SITE_QUERY, + variables: { + id, + }, + }); + + return site.data.site as Site; +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 58bc7de2..ab6b7aaa 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -3,6 +3,7 @@ export * from "./core/pantheon-api"; export * from "./lib/apollo-client"; export * from "./lib/gql"; +export * as GQL from "./lib/gql"; export * from "./lib/jwt"; export * from "./helpers"; diff --git a/packages/core/src/lib/gql.ts b/packages/core/src/lib/gql.ts index 7dd0a58e..821eea49 100644 --- a/packages/core/src/lib/gql.ts +++ b/packages/core/src/lib/gql.ts @@ -204,3 +204,17 @@ export const GET_RECOMMENDED_ARTICLES_QUERY = gql` } } `; + +export const GET_SITE_QUERY = gql` + query GetSite($id: String!) { + site(id: $id) { + id + name + url + domain + contentStructure + tags + metadataFields + } + } +`; diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 819c7644..149fcf04 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -48,6 +48,16 @@ export enum SortOrder { DESC = "DESC", } +export interface Site { + id: string; + name: string; + url: string; + domain: string; + tags: string[]; + contentStructure: Record; + metadataFields: Record; +} + export interface TreePantheonContent { tag: string; attrs: { diff --git a/packages/react-sdk/src/hooks/index.ts b/packages/react-sdk/src/hooks/index.ts index eec97e08..cea824e3 100644 --- a/packages/react-sdk/src/hooks/index.ts +++ b/packages/react-sdk/src/hooks/index.ts @@ -1,3 +1,7 @@ export { useArticle } from "./use-article"; export { useArticles } from "./use-articles"; export { usePagination } from "./use-pagination"; + +export { useQuery } from "@apollo/client/react/hooks/useQuery.js"; +export { useMutation } from "@apollo/client/react/hooks/useMutation.js"; +export { useSubscription } from "@apollo/client/react/hooks/useSubscription.js"; diff --git a/packages/react-sdk/src/server/index.ts b/packages/react-sdk/src/server/index.ts index 416413a0..fb905f0b 100644 --- a/packages/react-sdk/src/server/index.ts +++ b/packages/react-sdk/src/server/index.ts @@ -13,6 +13,8 @@ export { getArticleBySlugOrId, PCCConvenienceFunctions, updateConfig, + GQL, + getSite, } from "@pantheon-systems/pcc-sdk-core"; export * from "@pantheon-systems/pcc-sdk-core/types"; diff --git a/packages/vue-sdk/src/hooks/index.ts b/packages/vue-sdk/src/hooks/index.ts index 466831e1..96f3eb9e 100644 --- a/packages/vue-sdk/src/hooks/index.ts +++ b/packages/vue-sdk/src/hooks/index.ts @@ -1,2 +1,4 @@ export { useArticle } from "./use-article"; export { useArticles } from "./use-articles"; + +export { useQuery } from "@vue/apollo-composable"; From 0d57c5158b7337a94037fa61087f063f5b5e1733 Mon Sep 17 00:00:00 2001 From: Andrew Glago Date: Fri, 21 Jun 2024 16:22:46 +0000 Subject: [PATCH 2/5] fix: contentStructure can be null --- packages/core/src/types/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 149fcf04..9912ef88 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -54,7 +54,7 @@ export interface Site { url: string; domain: string; tags: string[]; - contentStructure: Record; + contentStructure: Record | null; metadataFields: Record; } From 05dcc96379656618659668923b27009f9d26e06f Mon Sep 17 00:00:00 2001 From: Andrew Glago Date: Fri, 21 Jun 2024 22:15:16 +0000 Subject: [PATCH 3/5] chore: fix lint issues --- packages/cli/CHANGELOG.md | 3 ++- packages/core/CHANGELOG.md | 6 ++++-- packages/react-sdk/CHANGELOG.md | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 8a43f257..f7862b37 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -5,7 +5,8 @@ ### Patch Changes - 3651708: Fix how protocols are being forwarded by API handler. -- 61363af: Removes inline sourcemaps. Sourcemaps are still provided, just linked in separate files instead. +- 61363af: Removes inline sourcemaps. Sourcemaps are still provided, just linked + in separate files instead. - Updated dependencies [61363af] - Updated dependencies [3651708] - Updated dependencies [61363af] diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index e02f6b9d..36f7cbca 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -4,9 +4,11 @@ ### Patch Changes -- 61363af: Fixes issue where redirects to local preview/publish targets would be redirected to https://localhost +- 61363af: Fixes issue where redirects to local preview/publish targets would be + redirected to https://localhost - 3651708: Fix how protocols are being forwarded by API handler. -- 61363af: Removes inline sourcemaps. Sourcemaps are still provided, just linked in separate files instead. +- 61363af: Removes inline sourcemaps. Sourcemaps are still provided, just linked + in separate files instead. ## 3.6.0-beta.3 diff --git a/packages/react-sdk/CHANGELOG.md b/packages/react-sdk/CHANGELOG.md index c215b437..f8351387 100644 --- a/packages/react-sdk/CHANGELOG.md +++ b/packages/react-sdk/CHANGELOG.md @@ -6,7 +6,8 @@ - 80ef092: Update preview bar copy and icons - 4ed0c05: Don't export pantheon-context in server export. -- 61363af: Removes inline sourcemaps. Sourcemaps are still provided, just linked in separate files instead. +- 61363af: Removes inline sourcemaps. Sourcemaps are still provided, just linked + in separate files instead. - 4ed0c05: Export pantheon-content from root entry point. - 14a968b: Make preview bar sticky at the top by default - Updated dependencies [61363af] From 183ad17f785f13cc9148ee202e253eb5b1b8c442 Mon Sep 17 00:00:00 2001 From: Andrew Glago Date: Mon, 24 Jun 2024 14:30:05 +0000 Subject: [PATCH 4/5] chore: add core changeset --- .changeset/tender-poets-sit.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tender-poets-sit.md diff --git a/.changeset/tender-poets-sit.md b/.changeset/tender-poets-sit.md new file mode 100644 index 00000000..e61d3fae --- /dev/null +++ b/.changeset/tender-poets-sit.md @@ -0,0 +1,5 @@ +--- +"@pantheon-systems/pcc-sdk-core": patch +--- + +Added queries and helper methods for fetching site information From edf725234cf251608a93728eafc22ca06afba7e1 Mon Sep 17 00:00:00 2001 From: Andrew Glago Date: Mon, 24 Jun 2024 14:31:47 +0000 Subject: [PATCH 5/5] chore: add react and vue sdk changesets --- .changeset/four-beers-draw.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/four-beers-draw.md diff --git a/.changeset/four-beers-draw.md b/.changeset/four-beers-draw.md new file mode 100644 index 00000000..cf016c7a --- /dev/null +++ b/.changeset/four-beers-draw.md @@ -0,0 +1,6 @@ +--- +"@pantheon-systems/pcc-react-sdk": patch +"@pantheon-systems/pcc-vue-sdk": patch +--- + +GraphQL queries and query hooks are now exposed for custom usage