wpengine / faustjs

Faust.js™ - The Headless WordPress Framework
https://faustjs.org
Other
1.44k stars 134 forks source link

Support for Array type in blocks #1891

Closed Bowriverstudio closed 5 months ago

Bowriverstudio commented 6 months ago

This link says https://github.com/wpengine/faustjs/issues/1522

Note: The array type won't be supported initially.

What is the current status of this?

Thanks

jasonbahl commented 6 months ago

@Bowriverstudio In order for GraphQL to support array types, the GraphQL Schema needs to know what Type of Scalar (string, int, etc) or Type(s) can be returned by the array.

In order to support this, attribute fields of the array type would need to specify the GraphQL List of Type manually since blocks can simply register attributes as "array" without further definition.

I believe you might be able to accomplish what you're after by using existing filters within WPGraphQL to support this on a case-by-case basis.

Bowriverstudio commented 6 months ago

@jasonbahl

Thank you. I'll explain the issue I'm having in more detail.

The Block I'm Trying to Make

image

Typical ACF Fields:

  1. Image Field: Background Image

    • Label: Background Image
    • Field Name: background_image
  2. Repeater Field: Team Members

    • Label: Team Members
    • Field Name: team_members
    • Subfields:
      • Image Field: Profile Image
      • Label: Profile Image
      • Field Name: profile_image
      • Text Field: Name
      • Label: Name
      • Field Name: name
      • Text Field: Position
      • Label: Position
      • Field Name: position
      • Textarea Field: Quote
      • Label: Quote
      • Field Name: quote
  3. Number Field: Total Projects

    • Label: Total Projects
    • Field Name: total_projects
  4. Number Field: Total Clients

    • Label: Total Clients
    • Field Name: total_clients
  5. Number Field: Total Tech

    • Label: Total Tech
    • Field Name: total_tech

Options I'm Considering:

  1. Use ACF with renderTemplate:

    • This approach is straightforward, but it limits the use of libraries like Framer Motion for animations.
  2. Use ACF with a Custom Parser:

    • Example:
      <?php if ($is_preview): ?>
      Render the block like option one.
      <?php else: ?>
      Render out a custom tag with the data I need;
      Then use a Parser to Convert Some Blocks to Components
      https://wpengine.com/builders/gutenberg-in-headless-wordpress-render-blocks-as-html
      <?php endif; ?>
    • The downside is that rendering a custom tag can be fragile and requires more code. However, it provides the best experience for the client and editor.
  3. Ask for Best Practices:

jasonbahl commented 6 months ago

@Bowriverstudio if you're using ACF Blocks have you tried WPGraphQL for ACF?

Bowriverstudio commented 5 months ago

@jasonbahl - Thank you I just did and it is works well thank you.