Skip to content

Allows nullable variables in non-null locations #3227

@darylsze

Description

@darylsze

Currently I am migrating AppSync sdk (although it embedded an internal Apollo sdk, it is way too outdated) to Apollo sdk v2.
However, I found that below query will be compile error:

query myQueryABCD(
    $page: Int = 1,
    $first: Int = 20
) {
      myQueryABCD(first: $first, page: $page) {
          ...MyFragmentABCD
      }
}

because in query definition, the field first is optional with default value, but in schema query first is required.
So i change the query to below:

query myQueryABCD(
    $page: Int = 1,
    $first: Int! = 20 // adding '!' as required
) {
      myQueryABCD(first: $first, page: $page) {
          ...MyFragmentABCD
      }
}

Then apollo client can generate query class successfully, and project got compile. Yeah!!
However, the problem is apollo client respond error because of Variable "$first" of type "Int!" is required and will not use the default value. Perhaps you meant to use type "Int".

I would suggest

  1. allowing required field to have default value, or
  2. do not return error. Just warn me in project

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions