refactor: fieldGroupName => __typename
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 58s

This commit is contained in:
2025-09-25 15:30:10 -04:00
parent ed479312fa
commit e041408715
6 changed files with 89 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
fragment TheSection on GroupAbstractBuilderSections_Layout {
fieldGroupName
__typename
... on GroupAbstractBuilderSectionsTextBlockLayout {
...SectionTextBlock
}

View File

@@ -50,7 +50,7 @@ function ccat_acf_init() {
}
// Helper: Get GraphQL field group name for flexible content layout
function ccat_get_graphql_field_group_name( $field_group_key, $layout_name ) {
function ccat_get_graphql_layout_typename( $field_group_key, $layout_name ) {
$layout_type_name = \WPGraphQL\Utils\Utils::format_type_name( $layout_name );
return "GroupAbstractBuilderSections{$layout_type_name}Layout";
}
@@ -84,9 +84,9 @@ function ccat_get_graphql_preview_data() {
throw new Exception( "Erreur de prévisualisation (section invalide)" );
}
$result = array(
'fieldGroupName' => ccat_get_graphql_field_group_name( 'group_abstract_builder', $layout_name ),
'__typename' => ccat_get_graphql_layout_typename( 'group_abstract_builder', $layout_name ),
);
$format_value = $result['fieldGroupName'] !== 'GroupAbstractBuilderSectionsTemplateLayout';
$format_value = $result['__typename'] !== 'GroupAbstractBuilderSectionsTemplateLayout';
foreach ( get_row( $format_value ) ?: array() as $key => $value ) {
if ( strpos( $key, 'acf_fc_layout' ) !== 0 && strpos( $key, '_' ) !== 0 ) {
$result[ ccat_get_graphql_field_name( array( 'name' => $key ) ) ] = $value;

View File

@@ -1,7 +1,7 @@
<?php
$preview_url = ( defined( 'NUXT_PUBLIC_SITE_URL' ) ? NUXT_PUBLIC_SITE_URL : 'https://cultureat.ca' ) . '/api/preview';
$data = ccat_get_graphql_preview_data();
if ( $data['fieldGroupName'] === 'GroupAbstractBuilderSectionsTemplateLayout' ) {
if ( $data['__typename'] === 'GroupAbstractBuilderSectionsTemplateLayout' ) {
echo '<div style="font-weight: bold; padding: 16px;">' . get_the_title( $data['fieldTemplateId'] ) . '</div>';
return;
}

View File

@@ -6,11 +6,8 @@ export default defineEventHandler(async (event) => {
try {
const section = await readBody<TheSectionFragment>(event);
const { component, attrs } = useSection(section);
const app = createSSRApp({
render() {
return h(component, attrs);
},
});
// @ts-expect-error Properties from TheSectionFragment
const app = createSSRApp({ render: () => h(component, attrs) });
const html = await renderToString(app);
return html;
}

View File

@@ -143,7 +143,7 @@ type ACFE_Language {
}
"""
Connection between the GroupAbstractCreditsContributions_Fields type and the ContentNode type
Connection between the GroupAbstractBuilderSectionsTemplateLayout_Fields type and the ContentNode type
"""
type AcfContentNodeConnection implements Connection & ContentNodeConnection {
"""Edges for the AcfContentNodeConnection connection"""
@@ -6913,6 +6913,74 @@ interface GroupAbstractBuilderSectionsLayoutSettings_Fields implements AcfFieldG
fieldGroupName: String @deprecated(reason: "Use __typename instead")
}
"""
The &quot;GroupAbstractBuilderSectionsTemplateLayout&quot; Field Group. Added to the Schema by &quot;WPGraphQL for ACF&quot;.
"""
type GroupAbstractBuilderSectionsTemplateLayout implements AcfFieldGroup & AcfFieldGroupFields & GroupAbstractBuilderSectionsTemplateLayout_Fields & GroupAbstractBuilderSections_Layout {
"""
Field of the &quot;text&quot; Field Type added to the schema as part of the &quot;GroupAbstractBuilderSectionsTemplateLayout&quot; Field Group
"""
acfeFlexibleLayoutTitle: String
"""The name of the field group"""
fieldGroupName: String @deprecated(reason: "Use __typename instead")
"""
Field of the &quot;post_object&quot; Field Type added to the schema as part of the &quot;GroupAbstractBuilderSectionsTemplateLayout&quot; Field Group
"""
template(
"""
Cursor used along with the "first" argument to reference where in the dataset to get data
"""
after: String
"""
Cursor used along with the "last" argument to reference where in the dataset to get data
"""
before: String
"""The number of items to return after the referenced "after" cursor"""
first: Int
"""The number of items to return before the referenced "before" cursor"""
last: Int
): AcfContentNodeConnection
}
"""
Interface representing fields of the ACF &quot;GroupAbstractBuilderSectionsTemplateLayout&quot; Field Group
"""
interface GroupAbstractBuilderSectionsTemplateLayout_Fields implements AcfFieldGroup & AcfFieldGroupFields & GroupAbstractBuilderSections_Layout {
"""
Field of the &quot;text&quot; Field Type added to the schema as part of the &quot;GroupAbstractBuilderSectionsTemplateLayout&quot; Field Group
"""
acfeFlexibleLayoutTitle: String
"""The name of the field group"""
fieldGroupName: String @deprecated(reason: "Use __typename instead")
"""
Field of the &quot;post_object&quot; Field Type added to the schema as part of the &quot;GroupAbstractBuilderSectionsTemplateLayout&quot; Field Group
"""
template(
"""
Cursor used along with the "first" argument to reference where in the dataset to get data
"""
after: String
"""
Cursor used along with the "last" argument to reference where in the dataset to get data
"""
before: String
"""The number of items to return after the referenced "after" cursor"""
first: Int
"""The number of items to return before the referenced "before" cursor"""
last: Int
): AcfContentNodeConnection
}
"""
The &quot;GroupAbstractBuilderSectionsTextBlockLayout&quot; Field Group. Added to the Schema by &quot;WPGraphQL for ACF&quot;.
"""
@@ -7711,7 +7779,7 @@ type GroupPostContributor implements AcfFieldGroup & AcfFieldGroupFields & Group
"""
Field of the &quot;repeater&quot; Field Type added to the schema as part of the &quot;GroupPostContributor&quot; Field Group
"""
locality: [GroupPostContributorLocality]
localities: [GroupPostContributorLocalities]
"""
Field of the &quot;repeater&quot; Field Type added to the schema as part of the &quot;GroupAbstractGallery&quot; Field Group
@@ -7751,11 +7819,11 @@ interface GroupPostContributorAlternativeTitles_Fields implements AcfFieldGroup
}
"""
The &quot;GroupPostContributorLocality&quot; Field Group. Added to the Schema by &quot;WPGraphQL for ACF&quot;.
The &quot;GroupPostContributorLocalities&quot; Field Group. Added to the Schema by &quot;WPGraphQL for ACF&quot;.
"""
type GroupPostContributorLocality implements AcfFieldGroup & AcfFieldGroupFields & GroupPostContributorLocality_Fields {
type GroupPostContributorLocalities implements AcfFieldGroup & AcfFieldGroupFields & GroupPostContributorLocalities_Fields {
"""
Field of the &quot;acfe_address&quot; Field Type added to the schema as part of the &quot;GroupPostContributorLocality&quot; Field Group
Field of the &quot;acfe_address&quot; Field Type added to the schema as part of the &quot;GroupPostContributorLocalities&quot; Field Group
"""
address: Address!
@@ -7764,11 +7832,11 @@ type GroupPostContributorLocality implements AcfFieldGroup & AcfFieldGroupFields
}
"""
Interface representing fields of the ACF &quot;GroupPostContributorLocality&quot; Field Group
Interface representing fields of the ACF &quot;GroupPostContributorLocalities&quot; Field Group
"""
interface GroupPostContributorLocality_Fields implements AcfFieldGroup & AcfFieldGroupFields {
interface GroupPostContributorLocalities_Fields implements AcfFieldGroup & AcfFieldGroupFields {
"""
Field of the &quot;acfe_address&quot; Field Type added to the schema as part of the &quot;GroupPostContributorLocality&quot; Field Group
Field of the &quot;acfe_address&quot; Field Type added to the schema as part of the &quot;GroupPostContributorLocalities&quot; Field Group
"""
address: Address!
@@ -7827,7 +7895,7 @@ interface GroupPostContributor_Fields implements AcfFieldGroup & AcfFieldGroupFi
"""
Field of the &quot;repeater&quot; Field Type added to the schema as part of the &quot;GroupPostContributor&quot; Field Group
"""
locality: [GroupPostContributorLocality]
localities: [GroupPostContributorLocalities]
"""
Field of the &quot;repeater&quot; Field Type added to the schema as part of the &quot;GroupAbstractGallery&quot; Field Group
@@ -11288,6 +11356,9 @@ type MediaItem implements ContentNode & DatabaseIdentifier & HierarchicalContent
"""The globally unique identifier of the attachment object."""
id: ID!
"""Image center point for cropping (e.g., &quot;50% 50%&quot;)"""
imageCenter: String
"""Whether the node is a Comment"""
isComment: Boolean!

View File

@@ -5,8 +5,8 @@ const sections = {
GroupAbstractBuilderSectionsTextBlockLayout: SectionTextBlock,
} as const;
export function useSection({ fieldGroupName, ...attrs }: TheSectionFragment) {
const component = sections[fieldGroupName as keyof typeof sections];
export function useSection({ __typename, ...attrs }: TheSectionFragment) {
const component = sections[__typename as keyof typeof sections];
if (!component) throw createError({ statusCode: 500, statusMessage: "Erreur interne", message: "Type de section invalide." });
return { component, attrs };
}