Skip to content

Commit

Permalink
Merge pull request #278 from pantheon-systems/ag/pcc-1388/site-conten…
Browse files Browse the repository at this point in the history
…t-structure-management

[PCC-1388] Add methods for fetching site data
  • Loading branch information
a11rew authored Jun 24, 2024
2 parents 6dd9f45 + edf7252 commit 2b3f273
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/four-beers-draw.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .changeset/tender-poets-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-sdk-core": patch
---

Added queries and helper methods for fetching site information
3 changes: 2 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 4 additions & 2 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/helpers/convenience.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -149,4 +157,5 @@ export const PCCConvenienceFunctions = {
getRecommendedArticles,
getPaginatedArticles,
getTags,
getSite,
};
1 change: 1 addition & 0 deletions packages/core/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./convenience";
export * from "./errors";
export * from "./metadata";
export * from "./validator";
export * from "./site";
14 changes: 14 additions & 0 deletions packages/core/src/helpers/site.ts
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/lib/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
`;
10 changes: 10 additions & 0 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export enum SortOrder {
DESC = "DESC",
}

export interface Site {
id: string;
name: string;
url: string;
domain: string;
tags: string[];
contentStructure: Record<string, unknown> | null;
metadataFields: Record<string, unknown>;
}

export interface TreePantheonContent {
tag: string;
attrs: {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions packages/react-sdk/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 2 additions & 0 deletions packages/react-sdk/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export {
getArticleBySlugOrId,
PCCConvenienceFunctions,
updateConfig,
GQL,
getSite,
} from "@pantheon-systems/pcc-sdk-core";
export * from "@pantheon-systems/pcc-sdk-core/types";

Expand Down
2 changes: 2 additions & 0 deletions packages/vue-sdk/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { useArticle } from "./use-article";
export { useArticles } from "./use-articles";

export { useQuery } from "@vue/apollo-composable";

0 comments on commit 2b3f273

Please sign in to comment.