Making a field in graphql schema required

I have…

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [ ] Bug report
  • [ ] Performance issue
  • [x] Documentation issue or request

Current behavior

When we create a field for any entity and we mark the field as required it is still shown as optional in GraphQL schema

Expected behavior

Once the field is marked as required the schema should reflect it (ie - the exclamation mark in field graphql definition)

Minimal reproduction of the problem

Create an entity, create a simple text field, mark it as required, do an graphql introspection query of the schema - the field is still optional

Environment

  • [ ] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [x] Cloud version

Version: current cloud version

Browser:

  • [ ] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Others:

Hi,

the problem is the graphql server. When a field is required it has to be required in the output as well.

Lets say you execute the following steps:

  1. Create a a schema with a field
  2. Create a few content items where some of the fields are required and others not.
  3. Mark the field as required.
  4. Query the content with GraphQL

Then the GraphQL server (not the Client) would throw an exception.

In relational databases step 3 would fail, but in Squidex and document based databases this constraint is only check when the data is being inserted.

Side note on this particular issue. At first I wanted this to be required as well but I actually think it being optional in GraphQL is helpful.

When you use Apollo later to do code generation of the GraphQL query, by having it be optional, if you change the status in squidex to required/optional at any time it doesn’t impact your current code base.

1 Like