hirochachacha / graphql-assert-transformer

MIT No Attribution
17 stars 4 forks source link

Assertion on ID only happen when value provided #4

Open mjza opened 3 years ago

mjza commented 3 years ago

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 commented 3 years ago

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

mjza commented 3 years ago

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!

PatrykMilewski commented 3 years ago

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.