Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema generation removing non-null rules #260

Open
anderson900 opened this issue Oct 14, 2022 · 1 comment
Open

Schema generation removing non-null rules #260

anderson900 opened this issue Oct 14, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@anderson900
Copy link

We've noticed that the final GQL schema generated by Cruddl seems to be lacking non-null (!) rules that are present in the original model.

For example:

type Group @rootEntity(flexSearch: true, flexSearchLanguage: EN) {
  name: String!
  type: String
}

generates:

type Group {
  """
  An auto-generated string that identifies this root entity uniquely among others of the same type
  """
  id: ID!

  """The instant this object has been created"""
  createdAt: DateTime!

  """
  The instant this object has been updated the last time (not including relation updates)
  """
  updatedAt: DateTime!
  name: String
  type: String

  """
  Provides a value that can be supplied to the `after` argument for pagination. Depends on the value of the `orderBy` argument.
  """
  _cursor: String

  """
  An identifier that is updated automatically on each update of this root entity (but not on relation changes)
  """
  _revision: ID!
}

The same issue applies to the mutation input types, e.g. CreateGroupInput as well.

@Yogu
Copy link
Member

Yogu commented Oct 15, 2022

Yes, cruddl currently does not support non-null types. The fact that it does not warn about using them in the input schema files is a bug currently.

About non-null types we have been tracking this missing feature for a few years. Just passing through ! could work, but it feels like this would not address the issue fully.

  • There are no checks that the existing data conforms to this non-null type, or that data stays conforming when edited outside of cruddl (yes, that's already the case for regular types)
  • GraphQL errors on fields bubble up to the first field that is nullable. In the case of cruddl, these errors are type mismatch errors and permission errors. Marking output types as non-nullable would result in errors bubbling up all the way to the top, so you could no longer receive partial data.
  • In input types, fields can be either omitted or specified to null, which leads to different behavior in cruddl's update mutations (omitting a field leaves it alone, specifying null sets the field to null). Non-null input fields affect both cases - you can't mark a field as optional, but non-nullable. So for update input types, we would need to allow null even on non-nullable fields, and we would either need to throw a custom error if null is specified or treat null like non-specified in this case. Both behaviors can be confusing.

These issues, combined with limited resources, sadly result in cruddl not having required fields currently. In case you have ideas or opinion about these issues, feel free to share them.

@Yogu Yogu added the enhancement New feature or request label Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants