facebook / facebook/relay

Why can a fragment tagged with `@alias` be nullable?

Open
#4,720 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

# Creating issues for Relay

## Questions regarding how to use Relay and/or GraphQL

We are experimenting with the new @alias directive. Given the following example:
```
graphql`
query aliasDirectiveConditionalFragmentTestQuery($skip: Boolean!) {
viewer {
...aliasDirectiveTestFragment @skip(if: $skip) @alias
}
}
`,
```
the type generated would be
```
readonly viewer: {
readonly aliasDirectiveTestFragment?: {
readonly " $fragmentSpreads": FragmentRefs<"aliasDirectiveTestFragment">;
} | null;
};
```
while being undefined make sense but wondering why `aliasDirectiveTestFragment` can be null? what would be the possible scenarios where it will be null? Thank you

## Reporting issues with Relay

We will be using GitHub Issues for our public bugs. We will keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new issue, make sure an issue for your problem doesn't already exist.

The best way to get your bug fixed is to provide a reduced test case. To make reproduction simple for you, and set-up simple for Relay's maintainers, you can use Glitch:
https://glitch.com/edit/#!/remix/relay-starter-kit

You can also provide a public repository with a runnable example.

## Security bugs

Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe disclosure of security bugs. With that in mind, please do not file public issues; go through the process outlined on that page.

Contributor guide

Open the contributing guide

Research direction

Start with the GraphQL query using @alias and @skip and the generated type shown in the issue. Trace Relay's handling of aliased conditional fragments and nullable fields, then document the scenarios that produce undefined versus null. Done means the generated type behavior and its possible runtime cases are clearly explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, javascript
Domain
api, frontend
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.