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 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 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/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..9912ef88 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 | null; + metadataFields: Record; +} + export interface TreePantheonContent { tag: string; attrs: { 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] 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";