Can I extend this to support GravityForms?
DesignyourCode opened this issue · comments
Tom Clarke commented
As part of my query, I have the following:
query PageByUri($uri: ID!) {
page(id: $uri, idType: URI) {
id
title
editorBlocks(flat: false) {
... on GravityformsForm {
attributes {
formId
}
}
}
}
}
However, this just returns the formId. What I want to do, is use the gfForm query to actually fetch all the fields (example below):
gfForm(id: $formId, idType: DATABASE_ID) {
databaseId
title
description
submitButton {
text
}
But there doesn't seem to be any support for this. Any ideas? Thank you in advance
Dovid Levine commented
Hey @DesignyourCode
This snippet should work in a cinch:
register_graphql_field(
'GravityformsFormAttributes', // Generated by wp-graphql-content-blocks.
'form',
[
'type' => \WPGraphQL\GF\Type\WPObject\Form\Form::$type,
'description' => __( 'The form object of the node.', 'axewp' ),
'resolve' => static fn ( $source, array $args, AppContext $context ) => ! empty( $source['attrs']['formId'] ) ? \WPGraphQL\GF\Data\Factory::resolve_form( $source['attrs']['formId'], $context ) : null,
]
);
Tom Clarke commented
Amazing ⭐ this worked perfectly. Thank you so much