wagtail-grapple icon indicating copy to clipboard operation
wagtail-grapple copied to clipboard

required attribute on GraphQLStreamField doesn't work

Open sks444 opened this issue 4 years ago • 2 comments
trafficstars

Suppose that you have a StreamField and you're using GraphQLStreamField to generate the schema. Now to make the field as required we should use the the required parameter as True. But that doesn't produce any affect to the schema.

    graphql_fields = [
        GraphQLStreamfield("main_menu", required=True),
    ]
type MainMenu {
  id: ID
  mainMenu: [StreamFieldInterface]
}

Why is it happening

In GraphQLField we have the support of making field as required. But then if the field is list we are updating the field_type without checking the required parameter.

sks444 avatar Mar 10 '21 04:03 sks444

Thank you @sks444, as per https://docs.graphene-python.org/en/latest/types/list-and-nonnull/#nonnull-lists this is a valid use case that we are missing

edit: further reading https://graphql.org/learn/schema/#lists-and-non-null, https://graphql.org/learn/schema/#lists-and-non-null

zerolab avatar Mar 10 '21 09:03 zerolab

Thanks @zerolab,

Looks like this line could be replaced with self.field_type = graphene.List(self.field_type) which results in following schema:

type MainMenu {
  id: ID
  mainMenu: [StreamFieldInterface!]
}

But in case we want something like:

type MainMenu {
  id: ID
  mainMenu: [StreamFieldInterface!]!
}

Even doing self.field_type = graphene.List(self.field_type, required=True), doesn't seem to produce that.

sks444 avatar Mar 10 '21 09:03 sks444