Nested fields in array/group are nullable in GraphQL-schema when required

default discord avatar
bdalenoord
4 weeks ago
3 1

Hi!

We've got a lot of collection types with arrays/groups in them, allowing our users to create a dynamic set of items within a specific collection item. We've got an issue with the GraphQL schema though, perhaps someone can help us out here...

Fields that are immediately under a CollectionConfig-type and are marked required neatly show up as required in the schema. Fields that are within an array/group are not though. An example, the following config:

const Example: CollectionConfig = {
    slug: "examples",
    fields: [
        {
            name: "direct",
            type: "text",
            required: true,
        },
        {
            type: "group",
            name: "group",
            fields: [
                {
                    name: "inAGroup",
                    type: "text",
                    required: true,
                },
            ],
        },
        {
            name: "array",
            type: "array",
            fields: [
                {
                    name: "nested",
                    type: "text",
                    required: true,
                },
            ],
        },
    ],
};

results in the following schema:

type Example {
  id: String
  direct: String!
  group: Example_Group
  array: [Example_Array!]
  updatedAt: DateTime
  createdAt: DateTime
}

type Example_Group {
  inAGroup: String
}

type Example_Array {
  nested: String
  id: String
}

As you can see, the direct-field is marked as non-nullable, which is expected because the field is marked as required. The nested-field and the inAGroup-field are not though, even though the fields are marked as required as well...

Is there a way to make the nested- and inAGroup-field non-nullable as well?

  • default discord avatar
    bdalenoord
    2 weeks ago

    This turned out to be a bug for which I made a report and a fix (#3259).

    That issue ahs now been merged and included in release 1.15.4

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.