Skip to content

How to handle required arguments: NonNull (!) vs @rules(apply: ["required"]) #345

@robsontenorio

Description

@robsontenorio

Country ID is mandatory.

input UpdatePersonInput {
     country_id: Int!
     name: String
}

This is pretty clear, by graphql spec itself, and guide users about this API usage. API auto-docs will say it.

The above stuff is a pure schema definition. if user try to send a empty country_id an GraphQL Error is thrown (useless when handling errors on frontend, because there is no definition about fields keys; a big message is thrown).

When using @rules directive errors are friendly, because there are properly field keys. So i can handle it on frontend.

input UpdatePersonInput {
     country_id: Int @rules(apply: ["required"])
     name: String
}

However, it "breaks" the schema definition, because "officially" that field is not mandatory anymore. So API auto-docs get inconsistent (Eg, graphql-playground).

So... what is the best practice in this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionRequires input from multiple people

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions