Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Array type in blocks #1891

Closed
Bowriverstudio opened this issue May 19, 2024 · 4 comments
Closed

Support for Array type in blocks #1891

Bowriverstudio opened this issue May 19, 2024 · 4 comments
Labels
needs: author response Pending information from the author

Comments

@Bowriverstudio
Copy link

This link says
#1522

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

What is the current status of this?

Thanks

@jasonbahl
Copy link
Contributor

@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
Copy link
Author

@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
Copy link
Contributor

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

@theodesp theodesp added the needs: author response Pending information from the author label May 29, 2024
@Bowriverstudio
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: author response Pending information from the author
Projects
None yet
Development

No branches or pull requests

3 participants