graphql-assert-transformer icon indicating copy to clipboard operation
graphql-assert-transformer copied to clipboard

Assertion on ID only happen when value provided

Open mjza opened this issue 4 years ago • 3 comments

I need to check the value has been provided for a Id, but I cannot define it as mandatory to be able to define auth:

categoryId: ID
    @assert(condition: ".length() > 1 && .matches(\"^\\w+$\")")
    @auth(
      rules: [
        { allow: owner, provider: userPools, operations: [create, update, read] }
        {
          allow: groups
          groups: ["Supers", "Admins", "Employees"]
          provider: userPools
          operations: [create, update, read]
        }
      ]
    )

But the assertion only file when user provides something, it means null is acceptable

mjza avatar Mar 30 '21 11:03 mjza

Also for type String it happen only when value is provided, so length does not check in null

mjza avatar Mar 30 '21 11:03 mjza

How can I check for not null?

categoryId: ID
    @assert(condition: ". != null")
    @auth(
      rules: [
        { allow: owner, provider: userPools, operations: [create, update, read] }
        {
          allow: groups
          groups: ["Supers", "Admins", "Employees"]
          provider: userPools
          operations: [create, update, read]
        }
      ]
    )

Does not work!

mjza avatar Mar 30 '21 11:03 mjza

You just need to require it in GraphQL:

categoryId: ID!
    @auth(
      rules: [
        { allow: owner, provider: userPools, operations: [create, update, read] }
        {
          allow: groups
          groups: ["Supers", "Admins", "Employees"]
          provider: userPools
          operations: [create, update, read]
        }
      ]
    )

using exclamation mark after the field type.

PatrykMilewski avatar Sep 17 '21 09:09 PatrykMilewski