Skip to content

Commit

Permalink
partialize graphql to separate customizations from core
Browse files Browse the repository at this point in the history
  • Loading branch information
ccorda committed Oct 5, 2021
1 parent c5ce6c5 commit 77ec44e
Show file tree
Hide file tree
Showing 12 changed files with 629 additions and 528 deletions.
528 changes: 0 additions & 528 deletions website/src/lib/wordpress.js

This file was deleted.

20 changes: 20 additions & 0 deletions website/src/lib/wordpress/graphql/flexHero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sectionOptions from './fragmentSectionOptions';

export function flexHero(template = 'Flex') {
const fragment = /* GraphQL */ `
... on Template_${template}_Acfflex_FlexContent_Hero {
heroHeading
heroSubheading
heroImage {
sourceUrl
mediaDetails {
width
height
}
}
${sectionOptions}
}
`;

return fragment;
}
30 changes: 30 additions & 0 deletions website/src/lib/wordpress/graphql/flexMedia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sectionOptions from './fragmentSectionOptions';

export function flexMedia(template = 'Flex') {
const fragment = /* GraphQL */ `
... on Template_${template}_Acfflex_FlexContent_Media {
youtubeUrl
variant
width
backgroundVideo {
mediaItemUrl
mediaDetails {
width
height
}
}
image {
altText
mediaDetails {
width
height
}
sourceUrl(size: _1600_WIDE)
mediaItemUrl
}
${sectionOptions}
}
`;

return fragment;
}
14 changes: 14 additions & 0 deletions website/src/lib/wordpress/graphql/flexWysiwygContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sectionOptions from './fragmentSectionOptions';

export function flexWysiwygContent(template = 'Flex') {
const fragment = /* GraphQL */ `
... on Template_${template}_Acfflex_FlexContent_WysiwygContent {
# contentWidth
sectionHeading
wysiwygContent
${sectionOptions}
}
`;

return fragment;
}
11 changes: 11 additions & 0 deletions website/src/lib/wordpress/graphql/fragmentCategories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fragmentCategories = /* GraphQL */ `
categories {
nodes {
name
slug
uri
}
}
`;

export default fragmentCategories;
12 changes: 12 additions & 0 deletions website/src/lib/wordpress/graphql/fragmentPageOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fragmentPageOptions = /* GraphQL */ `
acfPageOptions {
footerHideNav
footerHideSearch
footerHideSignup
footerHideSocial
footerStyle
headerHideNav
}
`;

export default fragmentPageOptions;
9 changes: 9 additions & 0 deletions website/src/lib/wordpress/graphql/fragmentSectionOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const sectionOptions = /* GraphQL */ `
backgroundColor
hideSection
fieldGroupName
sectionClasses
sectionSlug
`;

export default sectionOptions;
33 changes: 33 additions & 0 deletions website/src/lib/wordpress/graphql/fragmentSeo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const fragmentSeo = /* GraphQL */ `
seo {
breadcrumbs {
text
url
}
canonical
metaDesc
metaRobotsNofollow
metaRobotsNoindex
opengraphImage {
sourceUrl
mediaDetails {
height
width
}
}
opengraphDescription
opengraphTitle
twitterDescription
title
twitterTitle
twitterImage {
sourceUrl
mediaDetails {
height
width
}
}
}
`;

export default fragmentSeo;
88 changes: 88 additions & 0 deletions website/src/lib/wordpress/graphql/queryContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { flexHero } from './flexHero';
import { flexMedia } from './flexMedia';
import { flexWysiwygContent } from './flexWysiwygContent';
import pageOptions from './fragmentPageOptions';
import seo from './fragmentSeo';

export const queryContent = /* GraphQL */ `
query GetContent($slug: ID!, $preview: Boolean) {
contentNode(id: $slug, idType: URI, asPreview: $preview) {
__typename
id
databaseId
isPreview
link
slug
uri
date
template {
... on Template_Flex {
acfFlex {
fieldGroupName
flexContent {
${flexHero()}
${flexMedia()}
${flexWysiwygContent()}
}
}
}
}
... on NodeWithTitle {
title
}
... on NodeWithFeaturedImage {
featuredImage {
node {
caption
sourceUrl
mediaDetails {
height
width
}
}
}
}
... on NodeWithTemplate {
template {
__typename
templateName
}
}
... on NodeWithAuthor {
authorId
author {
node {
id
name
nicename
lastName
}
}
}
... on NodeWithExcerpt {
excerpt
}
... on Page {
isFrontPage
content
${seo}
${pageOptions}
}
... on Post {
content
${seo}
${pageOptions}
}
... on PressRelease {
content
${seo}
# $ {pageOptions}
}
... on Action {
content
${seo}
# $ {pageOptions}
}
}
}
`;
91 changes: 91 additions & 0 deletions website/src/lib/wordpress/graphql/queryGlobals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const fragmentMenu = /* GraphQL */ `
nodes {
id
databaseId
label
parentId
url
path
cssClasses
}
`;

const redirectsRedirection = /* GraphQL */ `
redirection {
redirects {
origin
target
type
matchType
statusCode: code
}
}
`;

const menus = /* GraphQL */ `
menuHeader: menuItems(where: { location: HEADER }, first: 100) {
${fragmentMenu}
}
menuFooter: menuItems(where: { location: FOOTER }, first: 100) {
${fragmentMenu}
}
menuFooterSocial: menuItems(where: { location: FOOTER_SOCIAL }, first: 100) {
${fragmentMenu}
}
menuFooterSecondary: menuItems(where: { location: FOOTER_SECONDARY }, first: 100) {
${fragmentMenu}
}
`;

const globalOptions = /* GraphQL */ `
themeSettings: acfOptionsThemeSettings {
acfGlobalOptions {
fieldGroupName
footer {
footerCopyright
copyrightAppend
copyrightPrepend
}
}
}
`;

const seoGlobal = /* GraphQL */ `
seo {
openGraph {
defaultImage {
mediaDetails {
width
height
}
sourceUrl
}
}
}
`;

export const queryGlobals = /* GraphQL */ `
fragment Redirects on RootQuery {
redirection: ${redirectsRedirection}
}
fragment GlobalOptions on RootQuery {
${globalOptions}
}
fragment SEO on RootQuery {
${seoGlobal}
}
fragment Menus on RootQuery {
${menus}
}
query AllGlobals {
...Menus
...SEO
...Redirects
...GlobalOptions
}
`;
72 changes: 72 additions & 0 deletions website/src/lib/wordpress/graphql/queryPosts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// import pageOptions from './fragmentPageOptions';
import categories from './fragmentCategories';
// import seo from './fragmentSeo';

export function queryPosts(taxonomyType, taxonomyTerms) {
const taxonomyQuery =
'taxQuery: {taxArray: { taxonomy: $taxonomyType, terms: $taxonomyTerms, field: SLUG }},';

const taxonomyParams = `
$taxonomyType: TaxonomyEnum!
$taxonomyTerms: [String]`;

const query = /* GraphQL */ `
# query GetPosts($first: Int, $contentTypes: Array) {
query GetPosts(
$ids: [ID]
$first: Int
$after: String
$contentTypes: [ContentTypeEnum!]!
$searchQuery: String
$orderField: PostObjectsConnectionOrderbyEnum!
$orderDirection: OrderEnum!
${taxonomyType && taxonomyTerms ? taxonomyParams : ''}
) {
contentNodes(
first: $first
after: $after
where: {
${taxonomyType && taxonomyTerms ? taxonomyQuery : ''}
in: $ids,
search: $searchQuery,
contentTypes: $contentTypes,
orderby: {field: $orderField, order: $orderDirection}}
) {
pageInfo {
hasNextPage
endCursor
}
nodes {
date
slug
uri
... on NodeWithFeaturedImage {
featuredImage {
node {
caption
sourceUrl(size: SOCIAL)
mediaDetails {
height
width
}
}
}
}
... on NodeWithTitle {
title
}
contentType {
node {
name
}
}
... on Post {
${categories}
}
}
}
}
`;

return query;
}

0 comments on commit 77ec44e

Please sign in to comment.