From 423703d0073696de38bd920537e092f836ae2b65 Mon Sep 17 00:00:00 2001 From: Philipp Melab Date: Wed, 6 Dec 2023 10:21:57 +0000 Subject: [PATCH] WIP --- apps/website/src/layouts/index.tsx | 70 +++++++++---------- packages/schema/src/operations/Footer.gql | 4 +- packages/schema/src/operations/Frame.gql | 14 ++++ packages/schema/src/operations/Header.gql | 4 +- .../schema/src/operations/PreviewPage.gql | 5 -- packages/schema/src/operations/ViewPage.gql | 5 ++ packages/schema/src/schema.graphql | 14 +++- 7 files changed, 70 insertions(+), 46 deletions(-) create mode 100644 packages/schema/src/operations/Frame.gql delete mode 100644 packages/schema/src/operations/PreviewPage.gql create mode 100644 packages/schema/src/operations/ViewPage.gql diff --git a/apps/website/src/layouts/index.tsx b/apps/website/src/layouts/index.tsx index 4c1a309a3..e3903a014 100644 --- a/apps/website/src/layouts/index.tsx +++ b/apps/website/src/layouts/index.tsx @@ -1,57 +1,55 @@ import { SilverbackPageContext } from '@amazeelabs/gatsby-source-silverback'; -import { NavigationFragment } from '@custom/schema'; +import { + FooterQuery, + FrameQuery, + HeaderQuery, + registerOperator, +} from '@custom/schema'; import { IntlProvider } from '@custom/ui/intl'; import { Frame } from '@custom/ui/routes/Frame'; import { graphql, useStaticQuery, WrapPageElementNodeArgs } from 'gatsby'; import React, { PropsWithChildren } from 'react'; -function useFrameQuery() { - return useStaticQuery<{ - main_de: NavigationFragment; - main_en: NavigationFragment; - footer_de: NavigationFragment; - footer_en: NavigationFragment; - }>(graphql` +export default function Layout({ + children, + pageContext: { locale }, +}: PropsWithChildren< + WrapPageElementNodeArgs['props'] +>) { + // TODO: Remove duplication of queries here. + const data = useStaticQuery(graphql` query Frame { - main_de: mainNavigation(_langcode: { eq: "de" }) { + main_en: mainNavigation(locale: "en") { ...Navigation } - main_en: mainNavigation(_langcode: { eq: "en" }) { - items { - ...NavigationItem - } + main_de: mainNavigation(locale: "de") { + ...Navigation } - footer_de: footerNavigation(_langcode: { eq: "de" }) { - items { - ...NavigationItem - } + footer_de: footerNavigation(locale: "de") { + ...Navigation } - footer_en: footerNavigation(_langcode: { eq: "en" }) { - items { - ...NavigationItem - } + footer_en: footerNavigation(locale: "en") { + ...Navigation } } `); -} - -export default function Layout({ - children, - pageContext: { locale }, -}: PropsWithChildren< - WrapPageElementNodeArgs['props'] ->) { - const data = useFrameQuery(); const main = locale === 'de' ? data.main_de : data.main_en; const footer = locale === 'de' ? data.footer_de : data.footer_en; + registerOperator( + () => ({ + mainNavigation: main, + }), + HeaderQuery, + ); + registerOperator( + () => ({ + footerNavigation: footer, + }), + FooterQuery, + ); return ( - - {children} - + {children} ); } diff --git a/packages/schema/src/operations/Footer.gql b/packages/schema/src/operations/Footer.gql index 62e666e47..5fe18f95d 100644 --- a/packages/schema/src/operations/Footer.gql +++ b/packages/schema/src/operations/Footer.gql @@ -1,5 +1,5 @@ -query Footer { - footerNavigation { +query Footer($locale: String!) { + footerNavigation(locale: $locale) { ...Navigation } } diff --git a/packages/schema/src/operations/Frame.gql b/packages/schema/src/operations/Frame.gql new file mode 100644 index 000000000..47a72f859 --- /dev/null +++ b/packages/schema/src/operations/Frame.gql @@ -0,0 +1,14 @@ +query Frame { + main_en: mainNavigation(locale: "en") { + ...Navigation + } + main_de: mainNavigation(locale: "de") { + ...Navigation + } + footer_en: footerNavigation(locale: "en") { + ...Navigation + } + footer_de: footerNavigation(locale: "de") { + ...Navigation + } +} diff --git a/packages/schema/src/operations/Header.gql b/packages/schema/src/operations/Header.gql index 7654ad3b5..863c92a33 100644 --- a/packages/schema/src/operations/Header.gql +++ b/packages/schema/src/operations/Header.gql @@ -1,5 +1,5 @@ -query Header { - mainNavigation { +query Header($locale: String!) { + mainNavigation(locale: $locale) { ...Navigation } } diff --git a/packages/schema/src/operations/PreviewPage.gql b/packages/schema/src/operations/PreviewPage.gql deleted file mode 100644 index 1f12d1e31..000000000 --- a/packages/schema/src/operations/PreviewPage.gql +++ /dev/null @@ -1,5 +0,0 @@ -query PreviewPage($id: ID!, $rid: ID!, $locale: String!) { - previewPage(id: $id, rid: $rid, locale: $locale) { - ...Page - } -} diff --git a/packages/schema/src/operations/ViewPage.gql b/packages/schema/src/operations/ViewPage.gql new file mode 100644 index 000000000..19b3c0626 --- /dev/null +++ b/packages/schema/src/operations/ViewPage.gql @@ -0,0 +1,5 @@ +query ViewPage($id: ID!, $rid: ID!, $locale: String!) { + page(id: $id, rid: $rid, locale: $locale) { + ...Page + } +} diff --git a/packages/schema/src/schema.graphql b/packages/schema/src/schema.graphql index 0f5bacb15..e33888abf 100644 --- a/packages/schema/src/schema.graphql +++ b/packages/schema/src/schema.graphql @@ -2,6 +2,11 @@ scalar Url @default @value(json: "\"\"") scalar Markup @default @value(json: "\"\"") scalar ImageSource @default @value(json: "\"\"") +""" +implementation(gatsby): @custom/schema#fetchNavigation +""" +directive @fetchNavigation(type: String!, locale: String!) on FIELD_DEFINITION + enum Locale @default @value(json: "\"en\"") { en de @@ -127,8 +132,15 @@ input PaginationInput { } type Query { - previewPage(id: ID!, rid: ID, locale: String!): Page + mainNavigation(locale: String!): MainNavigation + @fetchNavigation(type: "MainNavigation", locale: "$locale") + + footerNavigation(locale: String!): FooterNavigation + @fetchNavigation(type: "FooterNavigation", locale: "$locale") + + page(id: ID!, rid: ID, locale: String!): Page @fetchEntity(type: "node", id: "$id", rid: "$rid", language: "$locale") + contentHub(query: String, pagination: PaginationInput!): ContentHubResult! @contentHub(query: "$query", pagination: "$pagination") }