Skip to content

Raw response type of @semanticNonNull field is different when selected in a type refinement with @throwOnFieldError #4949

Open
@tobias-tengler

Description

@tobias-tengler

Consider the following schema:

type Query {
  blogPageBySlug(slug: String!): BlogPage
  node(id: ID!): Node
}

type BlogPage implements Node {
  id: ID!
  title: String @semanticNonNull
}

interface Node {
  id: ID!
}

And the following query:

query somethingSomethingQuery
  @throwOnFieldError
  @raw_response_type {
  node(id: "test-id") {
    ... on BlogPage {
      title
    }
  }
  blogPageBySlug(slug: "test-slug") {
    title
  }
}

Those would currently generate this raw response type:

export type somethingSomethingQuery$rawResponse = {
  readonly blogPageBySlug: {
    readonly id: string;
    readonly title: string;
  } | null | undefined;
  readonly node: {
    readonly __typename: "BlogPage";
    readonly id: string;
    readonly title: string | null | undefined;
  } | {
    readonly __typename: string;
    readonly id: string;
  } | null | undefined;
};

It seems like the @throwOnFieldError isn't properly considered in the case of a type refinement on a field returning an abstract type, since the title is typed as nullable below the node field and non-null on the field directly returning the object type.

We use @raw_response_type a lot to write typed mocked data for component demos and tests, so this makes it a lot harder to write accurate mock data for our developers.

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