wagtail-grapple
wagtail-grapple copied to clipboard
required attribute on GraphQLStreamField doesn't work
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.
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
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.