-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[relay-compiler] Type-safe updaters for TypeScript #4370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a3b8cd2
58acd91
2e4a627
662684d
d62cfcc
081d565
5b928f4
d111402
982923b
3732a2e
beb8323
fcc1ace
dbcc8bb
5728950
79745a9
582d02b
63ce0a5
e6104c3
84b5dea
105949b
8bcd301
1f3db1f
f60732e
2155d00
768cf93
4a195a2
bf3f5b9
290a803
915e5fb
509f05e
41a37f6
65af68d
565711d
d867283
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| ==================================== INPUT ==================================== | ||
| query Foo { | ||
| viewer { | ||
| ...Assignable_viewer | ||
| } | ||
| } | ||
|
|
||
| fragment Assignable_viewer on Viewer @assignable { | ||
| __typename | ||
| } | ||
| ==================================== OUTPUT =================================== | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type Foo$variables = {}; | ||
| export type Foo$data = { | ||
| readonly viewer: { | ||
| readonly __typename: "Viewer"; | ||
| readonly __id: string; | ||
| readonly " $fragmentSpreads": FragmentRefs<"Assignable_viewer">; | ||
| } | null; | ||
| }; | ||
| export type Foo = { | ||
| response: Foo$data; | ||
| variables: Foo$variables; | ||
| }; | ||
| ------------------------------------------------------------------------------- | ||
| import { FragmentRefs } from "relay-runtime"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| query Foo { | ||
| viewer { | ||
| ...Assignable_viewer | ||
| } | ||
| } | ||
|
|
||
| fragment Assignable_viewer on Viewer @assignable { | ||
| __typename | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| ==================================== INPUT ==================================== | ||
| query updatableFragmentSpreadAndRegularSpreadQuery { | ||
| me { | ||
| ...updatableFragmentSpreadAndRegularSpread_updatable_user | ||
| ...updatableFragmentSpreadAndRegularSpread_user | ||
| } | ||
| } | ||
|
|
||
| fragment updatableFragmentSpreadAndRegularSpread_updatable_user on User @updatable { | ||
| firstName | ||
| } | ||
|
|
||
| fragment updatableFragmentSpreadAndRegularSpread_user on User { | ||
| firstName | ||
| } | ||
| ==================================== OUTPUT =================================== | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type updatableFragmentSpreadAndRegularSpreadQuery$variables = {}; | ||
| export type updatableFragmentSpreadAndRegularSpreadQuery$data = { | ||
| readonly me: { | ||
| readonly $updatableFragmentSpreads: FragmentRefs<"updatableFragmentSpreadAndRegularSpread_updatable_user">; | ||
| readonly " $fragmentSpreads": FragmentRefs<"updatableFragmentSpreadAndRegularSpread_user">; | ||
| } | null; | ||
| }; | ||
| export type updatableFragmentSpreadAndRegularSpreadQuery = { | ||
| response: updatableFragmentSpreadAndRegularSpreadQuery$data; | ||
| variables: updatableFragmentSpreadAndRegularSpreadQuery$variables; | ||
| }; | ||
| ------------------------------------------------------------------------------- | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type updatableFragmentSpreadAndRegularSpread_updatable_user$data = { | ||
| firstName: string | null; | ||
tobias-tengler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| readonly " $fragmentType": "updatableFragmentSpreadAndRegularSpread_updatable_user"; | ||
| }; | ||
| export type updatableFragmentSpreadAndRegularSpread_updatable_user$key = { | ||
| readonly " $data"?: updatableFragmentSpreadAndRegularSpread_updatable_user$data; | ||
| readonly $updatableFragmentSpreads: FragmentRefs<"updatableFragmentSpreadAndRegularSpread_updatable_user">; | ||
| }; | ||
| ------------------------------------------------------------------------------- | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type updatableFragmentSpreadAndRegularSpread_user$data = { | ||
| readonly firstName: string | null; | ||
| readonly " $fragmentType": "updatableFragmentSpreadAndRegularSpread_user"; | ||
| }; | ||
| export type updatableFragmentSpreadAndRegularSpread_user$key = { | ||
| readonly " $data"?: updatableFragmentSpreadAndRegularSpread_user$data; | ||
| readonly " $fragmentSpreads": FragmentRefs<"updatableFragmentSpreadAndRegularSpread_user">; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| query updatableFragmentSpreadAndRegularSpreadQuery { | ||
| me { | ||
| ...updatableFragmentSpreadAndRegularSpread_updatable_user | ||
| ...updatableFragmentSpreadAndRegularSpread_user | ||
| } | ||
| } | ||
|
|
||
| fragment updatableFragmentSpreadAndRegularSpread_updatable_user on User @updatable { | ||
| firstName | ||
| } | ||
|
|
||
| fragment updatableFragmentSpreadAndRegularSpread_user on User { | ||
| firstName | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| ==================================== INPUT ==================================== | ||
| query updatableFragmentSpreadAndRegularSpreadQuery { | ||
| me { | ||
| ...updatableFragmentSpreadAndRegularSpread_updatable_user | ||
| ...updatableFragmentSpreadAndRegularSpread_2_updatable_user | ||
| } | ||
| } | ||
|
|
||
| fragment updatableFragmentSpreadAndRegularSpread_updatable_user on User @updatable { | ||
| firstName | ||
| } | ||
|
|
||
| fragment updatableFragmentSpreadAndRegularSpread_2_updatable_user on User @updatable { | ||
| firstName | ||
| } | ||
| ==================================== OUTPUT =================================== | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type updatableFragmentSpreadAndRegularSpreadQuery$variables = {}; | ||
| export type updatableFragmentSpreadAndRegularSpreadQuery$data = { | ||
| readonly me: { | ||
| readonly $updatableFragmentSpreads: FragmentRefs<"updatableFragmentSpreadAndRegularSpread_2_updatable_user" | "updatableFragmentSpreadAndRegularSpread_updatable_user">; | ||
| } | null; | ||
| }; | ||
| export type updatableFragmentSpreadAndRegularSpreadQuery = { | ||
| response: updatableFragmentSpreadAndRegularSpreadQuery$data; | ||
| variables: updatableFragmentSpreadAndRegularSpreadQuery$variables; | ||
| }; | ||
| ------------------------------------------------------------------------------- | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type updatableFragmentSpreadAndRegularSpread_2_updatable_user$data = { | ||
| firstName: string | null; | ||
| readonly " $fragmentType": "updatableFragmentSpreadAndRegularSpread_2_updatable_user"; | ||
| }; | ||
| export type updatableFragmentSpreadAndRegularSpread_2_updatable_user$key = { | ||
| readonly " $data"?: updatableFragmentSpreadAndRegularSpread_2_updatable_user$data; | ||
| readonly $updatableFragmentSpreads: FragmentRefs<"updatableFragmentSpreadAndRegularSpread_2_updatable_user">; | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Flow this object, and https://flow.org/en/docs/types/objects/#exact-and-inexact-object-types
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would such an inexact type be typed in Typescript, would it just be a union of original_obj & { [k: string]: unknown };Might need more input from some TypeScript wizard before I add this...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can first start with understanding why its inexact in Flow? What breaks if we make it inexact? Is this specific to updatable fragments, or are all fragment keys inexact in Flow? Maybe the semantics of TypeScript are different and we don't actually need them to be inexact in TypeScript.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other places inexact objects are used for fragments, if their MaskStatus is unmasked. I know too little about how fragments work to infer why it would be important to have the same characteristics when updating a fragment... I tried tracing the git log for an explanation of why an InexactObject was being used, but haven't found anything. @rbalicki2 you seem to have added the code, do you perhaps remember why the InexactObject was being used? |
||
| ------------------------------------------------------------------------------- | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type updatableFragmentSpreadAndRegularSpread_updatable_user$data = { | ||
| firstName: string | null; | ||
| readonly " $fragmentType": "updatableFragmentSpreadAndRegularSpread_updatable_user"; | ||
| }; | ||
| export type updatableFragmentSpreadAndRegularSpread_updatable_user$key = { | ||
| readonly " $data"?: updatableFragmentSpreadAndRegularSpread_updatable_user$data; | ||
| readonly $updatableFragmentSpreads: FragmentRefs<"updatableFragmentSpreadAndRegularSpread_updatable_user">; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| query updatableFragmentSpreadAndRegularSpreadQuery { | ||
| me { | ||
| ...updatableFragmentSpreadAndRegularSpread_updatable_user | ||
| ...updatableFragmentSpreadAndRegularSpread_2_updatable_user | ||
| } | ||
| } | ||
|
|
||
| fragment updatableFragmentSpreadAndRegularSpread_updatable_user on User @updatable { | ||
| firstName | ||
| } | ||
|
|
||
| fragment updatableFragmentSpreadAndRegularSpread_2_updatable_user on User @updatable { | ||
| firstName | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ==================================== INPUT ==================================== | ||
| query updatableFragmentSpreadQuery { | ||
| me { | ||
| ...updatableFragmentSpread_updatable_user | ||
| } | ||
| } | ||
|
|
||
| fragment updatableFragmentSpread_updatable_user on User @updatable { | ||
| firstName | ||
| } | ||
| ==================================== OUTPUT =================================== | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type updatableFragmentSpreadQuery$variables = {}; | ||
| export type updatableFragmentSpreadQuery$data = { | ||
| readonly me: { | ||
| readonly $updatableFragmentSpreads: FragmentRefs<"updatableFragmentSpread_updatable_user">; | ||
| } | null; | ||
| }; | ||
| export type updatableFragmentSpreadQuery = { | ||
| response: updatableFragmentSpreadQuery$data; | ||
| variables: updatableFragmentSpreadQuery$variables; | ||
| }; | ||
| ------------------------------------------------------------------------------- | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type updatableFragmentSpread_updatable_user$data = { | ||
| firstName: string | null; | ||
| readonly " $fragmentType": "updatableFragmentSpread_updatable_user"; | ||
| }; | ||
| export type updatableFragmentSpread_updatable_user$key = { | ||
| readonly " $data"?: updatableFragmentSpread_updatable_user$data; | ||
| readonly $updatableFragmentSpreads: FragmentRefs<"updatableFragmentSpread_updatable_user">; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| query updatableFragmentSpreadQuery { | ||
| me { | ||
| ...updatableFragmentSpread_updatable_user | ||
| } | ||
| } | ||
|
|
||
| fragment updatableFragmentSpread_updatable_user on User @updatable { | ||
| firstName | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| ==================================== INPUT ==================================== | ||
| query UpdatableQuery @updatable { | ||
| node(id: 4) { | ||
| ... on User { | ||
| __typename | ||
| parents { | ||
| ...Assignable_user | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fragment Assignable_user on User @assignable { | ||
| __typename | ||
| } | ||
| ==================================== OUTPUT =================================== | ||
| import { FragmentRefs } from "relay-runtime"; | ||
| export type UpdatableQuery$variables = {}; | ||
| export type UpdatableQuery$data = { | ||
| get node(): { | ||
| readonly __typename: "User"; | ||
| get parents(): ReadonlyArray<{}>; | ||
| set parents(value: ReadonlyArray<{ | ||
| readonly __typename: "User"; | ||
| readonly __id: string; | ||
| readonly " $fragmentSpreads": FragmentRefs<"Assignable_user">; | ||
| }>); | ||
| } | { | ||
| // This will never be '%other', but we need some | ||
| // value in case none of the concrete values match. | ||
| readonly __typename: "%other"; | ||
| } | null; | ||
| set node(value: null | undefined); | ||
| }; | ||
| export type UpdatableQuery = { | ||
| response: UpdatableQuery$data; | ||
| variables: UpdatableQuery$variables; | ||
| }; | ||
| ------------------------------------------------------------------------------- | ||
| import { FragmentRefs } from "relay-runtime"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| query UpdatableQuery @updatable { | ||
| node(id: 4) { | ||
| ... on User { | ||
| __typename | ||
| parents { | ||
| ...Assignable_user | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fragment Assignable_user on User @assignable { | ||
| __typename | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.