facebook / facebook/relay

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

Open
#4,949 5 comments 1 reaction 0 assignees View on GitHub
shared with relay team
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Consider the following schema:

```graphql
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:

```graphql
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:

```typescript
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.