wpengine / wp-graphql-content-blocks

Plugin that extends WPGraphQL to support querying (Gutenberg) Blocks as data

Home Page:https://faustjs.org/docs/gutenberg/wp-graphql-content-blocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can I extend this to support GravityForms?

DesignyourCode opened this issue · comments

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

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,
	]
);

Amazing ⭐ this worked perfectly. Thank you so much