Skip to content

gastby-source-wordpress, ACF Flexible content, schemaCustomization issue #16809

Closed
@tol-is

Description

@tol-is

Hi, I'm trying to hook into the createSchemaCustomization and create some custom types for an some acf flexible content data. The reason is some node types will not exist at any given time. So i can't rely on the data to infer the types.

Something is not working for me and I'm not sure if I'm missing something or if this is a bug.

The query i'm trying to run
  fragment typeOne on WordPressAcf_typeOne {
  flexText
}

fragment typeTwo on WordPressAcf_typeTwo {
  flexInt
}

fragment typeThree on WordPressAcf_typeThree {
  flexUrl
}

query MyQuery {
  wordpressWpHelp(wordpress_id: {eq: 659}) {
    id
    acf {
      flexContent_help {
        ...typeOne
        ...typeTwo
        ...typeThree
      }
    }
  }
}

Half of it seems to be working well, meaning I can declare a node field and a type that don't exist in the cms, using the @dontInfer directive, and in graphiql I can successfully see both

const typeDefs = `

    type WordPressAcf_typeOne implements Node @dontInfer {
      id: ID!
      flexText: String
    }

    type WordPressAcf_typeTwo implements Node @dontInfer {
      id: ID!
      flexInt: String
      # flexPotato is a made up key, doesn't come from anywhere
      flexPotato: Int
    }
    # typeThree doesn't exist in the cms
    type WordPressAcf_typeThree implements Node @dontInfer {
      id: ID!
      flexUrl: String
      flexTomato: String
    }
  `
  createTypes(typeDefs)
}

The problem

As soon as I'm trying to customize the schema for the node containing the flexible content union I get an error Error: Schema must contain uniquely named types but contains multiple types named "wordpress__wp_helpAcf".

  const typeDefs = `
    union AcfFlexContentUnion =
      WordPressAcf_typeOne
    | WordPressAcf_typeTwo
    | WordPressAcf_typeThree
   
    # customize union type of acf flexible content node
    type wordpress__wp_helpAcf implements Node @dontInfer {
      flexContent_help : [AcfFlexContentUnion]
    }

    type WordPressAcf_typeOne implements Node @dontInfer {
      id: ID!
    }

    type WordPressAcf_typeTwo implements Node @dontInfer {
      id: ID!
    }
    # typeThree doesn't exist in wordpress data (layout not applied in cms)
    type WordPressAcf_typeThree implements Node @dontInfer {
      id: ID!
    }

Another attempt

I also tried to customize the schema from one level up, and its not complaining anymore but now the flexContent_help value returns null.

const typeDefs = `

    union AcfFlexContentUnion =
      WordPressAcf_typeOne
    | WordPressAcf_typeTwo
    | WordPressAcf_typeThree

    type wordpress__wp_help implements Node  {
      id: ID!
      acf: wordpress__wp_helpAcf
    }

    type wordpress__wp_helpAcf implements Node @dontInfer  {
      flexContent_help : [AcfFlexContentUnion]
    }

Reproduction

I prepared a repository to reproduce the issue with all three attempts in gastby-node.js
https://github.com/tol-is/gastby-wordpress-help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions