Use @required directive in an @inline fragment
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
When using an `@inline` fragment, it can be useful to also use the `@required` directive. For example:
```typescript
const query = graphql`
query {
todos {
...todoItem
}
}
`
const todoFragment = graphql`
fragment todoFragment on Todo @inline {
text @required(action: THROW)
}
`;
const doSomethingWithATodo = (todo: todoFragment$key) => {
try {
const todoData = readInlineData(todoFragment, todo);
// ... do stuff (knowing that todoData.text is not null)
} except {
// handle the case of todoData.text being null
}
}
const queryData = await fetchQuery(query).toPromise();
doSomethingWithATodo(queryData.todos[0]);
```
This seems perfectly natural, but currently the Relay compiler fails with the following error: `@required is not supported within @inline fragments.`.
Is this intended? Would it be welcome to implement a change to make the above code work?
Contributor guide
Research direction
Start by reproducing the Relay compiler error for an @required directive inside an @inline fragment using the TypeScript example in the issue. Trace the compiler validation for these directives and identify existing tests for @required or @inline; done means the example compiles and the described null-handling behavior is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, typescript
- Domain
- compilers, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100