Skip to content

crash on error on non-nullable field #10389

@raphaelfff

Description

@raphaelfff

Is your feature request related to a problem? Please describe.

defer and error on non nullable handling

schema:

type Query {
  """
  Error simulator
  """
  errorSimulator: ErrorSimulatorResult
}

type ErrorSimulatorResult {
  field: String
  resolve(delay: Int, err: Boolean!): ErrorSimulatorResult
    @goField(forceResolver: true)
  resolve2(delay: Int, err: Boolean!): ErrorSimulatorResult!
    @goField(forceResolver: true)
}

query:

errorSimulator {
      resolve2(delay: 500, err: false) {
        field
        ... on ErrorSimulatorResult @defer {
          failed: resolve2(delay: 1000, err: true) {
            field
          }
        }
        ... on ErrorSimulatorResult @defer {
          success: resolve2(delay: 100, err: false) {
            field
          }
        }
      }
    }

this causes

Uncaught TypeError: Cannot read properties of undefined (reading 'field')
code: data?.t2?.resolve2.failed.field

stack:

  • @apollo/client 3 or 4
  • graphql-sse ^2.5.4
  • @graphql-codegen/cli: ^5.0.2

Describe the solution you'd like

mark as optional all fields parent of a @defer on non-nullable field (can be an opt-in config?)

Describe alternatives you've considered

No response

Any additional important details?

I think this is partially due to the specs mess that defer is today, should resolve itself, but in the mean time, this bandaid would allow for safe code to be generated until this is all figured out

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions