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

Question: GraphQL fragments on WordPress ACF Flexible Content fields #4064

Closed
RobertBolender opened this issue Feb 15, 2018 · 3 comments · Fixed by #4074
Closed

Question: GraphQL fragments on WordPress ACF Flexible Content fields #4064

RobertBolender opened this issue Feb 15, 2018 · 3 comments · Fixed by #4074
Assignees

Comments

@RobertBolender
Copy link
Contributor

I'm having some difficulty querying for my Flexible Content data with GraphQL.

I've been using the recommended inline fragments and everything has been working fine until just yesterday.
Now Gatsby is generating GraphQL Union nodes that differ from one build to the next.

My Flexible Field has the ACF key content_block, and it currently has four layouts: quote, link, image_and_text, image_and_content. The resulting GraphQL Unions look like this:

Union_blocks_page___NODE_WordPressAcf_quote__WordPressAcf_link__WordPressAcf_image_and_content__WordPressAcf_image_and_text
Union_blocks_page___NODE_WordPressAcf_quote__WordPressAcf_link__WordPressAcf_image_and_text__WordPressAcf_image_and_content
Union_blocks_page___NODE_WordPressAcf_image_and_text__WordPressAcf_quote__WordPressAcf_link__WordPressAcf_image_and_content

The order changes on each build, even though I haven't added, changed, or removed any of the layouts.

I'm trying to create a reusable fragment like this:

export const contentBlockQuery = graphql`
  fragment content_block on [Union_blocks_page...] {
    __typename
    ... on WordPressAcf_quote {
      text
      source
    }
    ... on WordPressAcf_link {
      text
      link
    }
    (etc)
  }
`

This fragment fails to compile because that Union node keeps changing.

  1. Is there something I can do to make sure that the Union node stays consistent?
  2. Is there something more generic that I can use in the GraphQL fragment for the "on" target?
@pieh
Copy link
Contributor

pieh commented Feb 15, 2018

Hmm, we probably could make it to stay somewhat consistent by sorting types before joining them but this still would not be bullet proof (i.e. if you would never use one of your layouts name would change again). This is definitely problematic, I will prepare PR with bandaid solution, but long term solution is so either user or source plugin could declare schema types.

@pieh
Copy link
Contributor

pieh commented Feb 16, 2018

Just letting You know PR with fix is opened if You want to track it - #4074

@ghost ghost removed the review label Feb 16, 2018
@RobertBolender
Copy link
Contributor Author

I can confirm that this resolved the issue for me. Thanks @pieh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants