facebook / facebook/relay

Relay IDs and scalar types should be opaque types in flow

Open
#2,567 8 comments 2 reactions 0 assignees View on GitHub
wontfix
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Currently the flow types generated by relay use `string` type to represent the ID. The type for the ID field should be a flow opaque type so that users on cannot pass it arbitrary strings as IDs.

This behaviour should be extended for custom scalar types. I.e. Every scalar type should be a unique opaque type.

```
export type RestrictedPartyHitsPanelRestrictedPartyHitScanForCompanyMutationResponse = {|
+RestrictedPartyHitScanForCompany: ?{|
+company: ?{|
+id: string, // CAN THIS BE A an opaque type
....
```

Contributor guide

Open the contributing guide

Research direction

No file or test path is named. Start at Relay's Flow type-generation entry point and trace how the shown ID and custom scalar fields are emitted; done means generated IDs and each scalar use distinct opaque types, with tests confirming arbitrary strings are rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.