-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make __typename selections within concrete linked fields have a strin…
…g literal flowtype Summary: # What and why * Currently, a selection like `foo { __typename }` will generate a type of `__typename: string`. We have never had a need to generate a more accurate type, hence we generate `string` instead of a string literal for the value of `__typename`. * However, this is problematic for typesafe updaters! This requires assignments of `foo` to be validated, **even though we known statically that the validation can never fail**. * With this change, assigning an array of linked fields is modified as follows: ``` const data = useFragment(graphql`fragment SourceFragment on User { best_friends(count: 5) required(action: THROW) { ...Assignable_user } }`, userRef); const env = useRelayEnvironment(); const onClick = () => { env.commitUpdate(store => { const {updatableData} = store.readUpdatableQuery(graphql` query Updatable_best_friends updatable { best_friends { ...Assignable_user } } `, {}); // WE CAN REPLACE THIS const validateUser = require('SourceFragment').validate; const validBestFriends = data.best_friends.flatMap(bestFriend => { const validBestFriend = validateUser(bestFriend); if (validBestFriend !== false) { return [validBestFriend]; } else { // this case never occurs! return []; } }); updatableData.best_friends = validBestFriends; // WITH THIS updatableData.best_friends = data.best_friends }); } ``` # How Pass around a `enclosing_concrete_linked_field_type: Option<Type>` through the codegen. Whenever we visit a linked field, we potentially pass `Some(linked_field_type)`. When we process a scalar field, if that parameter is Some, then we generate an AST with the StringLiteral of tha type. # Rollout This needs to rollout with a rollout. Once this diff is approved, I'll put a rollout in. Reviewed By: alunyov Differential Revision: D36357062 fbshipit-source-id: e06d076e6395183eb7872e47962c81e6cd4db475
- Loading branch information
1 parent
90b4226
commit 20626f2
Showing
24 changed files
with
183 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.