Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

[Relay] Uses latest version and our patches #982

Merged
merged 10 commits into from
Feb 7, 2018
Merged

Conversation

alloy
Copy link
Contributor

@alloy alloy commented Feb 6, 2018

I decided to start checking in the artefacts, because now that we have and use TS typings it will be useful to be able to see those when reviewing PRs.

⚠️ If you already had Emission checked out before, be sure to delete all previous artefacts and reset the transformer cache:

$ find . -name __generated__ | xargs rm -rf
$ yarn relay
$ yarn start-packager --reset-cache

Afterwards you can use the regular script again:

$ yarn start

#skip_new_tests

@alloy
Copy link
Contributor Author

alloy commented Feb 6, 2018

Seems to fail on CI due to ds300/patch-package#36. Will look into that tomorrow; for those interested, you should be able to pull and run this locally.

# i.e. in this case the artist selection is not present in the second fragment.
#
# This can be seen much more clear when adding __typename to the context part in ArtworkRail.tsx.
#
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working around a bug here ^

@alloy alloy mentioned this pull request Feb 7, 2018
@ArtsyOpenSource
Copy link

ArtsyOpenSource commented Feb 7, 2018

Warnings
⚠️

Missing Test Files:

  • src/lib/Components/Artist/Articles/__tests__/index-tests.tsx
  • src/lib/Components/Artist/Artworks/__tests__/index-tests.tsx
  • src/lib/Components/Artist/Shows/__tests__/index-tests.tsx
  • src/lib/Components/ArtworkGrids/__tests__/GenericGrid-tests.tsx
  • src/lib/Components/ArtworkGrids/RelayConnections/__tests__/ArtistForSaleArtworksGrid-tests.tsx
  • src/lib/Components/ArtworkGrids/RelayConnections/__tests__/ArtistNotForSaleArtworksGrid-tests.tsx
  • src/lib/Components/Home/ArtistRails/__tests__/ArtistRail-tests.tsx
  • src/lib/Components/Home/ArtworkRails/__tests__/ArtworkRailHeader-tests.tsx
  • src/lib/Components/Home/__tests__/HeroUnits-tests.tsx
  • src/lib/Components/Inbox/ActiveBids/__tests__/index-tests.tsx
  • src/lib/Components/Inbox/Conversations/Preview/Attachment/__tests__/AttachmentPreview-tests.tsx
  • src/lib/Components/Inbox/Conversations/__tests__/index-tests.tsx
  • src/lib/Components/RelatedArtists/__tests__/RelatedArtist-tests.tsx
  • src/lib/Components/RelatedArtists/__tests__/index-tests.tsx
  • src/lib/Scenes/Favorites/Components/Artists/__tests__/index-tests.tsx
  • src/lib/Scenes/Favorites/Components/Artworks/Relay/__tests__/ArtworksRenderer-tests.tsx
  • src/lib/Scenes/Favorites/Components/Artworks/__tests__/index-tests.tsx
  • src/lib/Scenes/Favorites/Components/Categories/__tests__/index-tests.tsx
  • src/lib/Scenes/Home/Components/ForYou/Components/__tests__/ArtworkCarousel-tests.tsx
  • src/lib/Scenes/Home/Components/ForYou/Components/__tests__/ArtworkCarouselHeader-tests.tsx
  • src/lib/Scenes/Home/Components/ForYou/__tests__/index-tests.tsx
  • src/lib/Scenes/Home/Components/Sales/Relay/__tests__/SalesRenderer-tests.tsx

If these files are supposed to not exist, please update your PR body to include "#skip_new_tests".

Generated by 🚫 dangerJS

@kastermester
Copy link

I hope this works out well for you guys - and I look forward to continue working with @alloy to make sure TS and Relay feels like tools that are made to work together! :)

@alloy
Copy link
Contributor Author

alloy commented Feb 7, 2018

Alright, this is all green now 👍

Copy link
Contributor

@orta orta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep cool, looks 👍

@@ -1 +1,2 @@
CHANGELOG.md merge=union
src/__generated__/*.graphql.ts linguist-generated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, thanks @pchaigno 🥇

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orta - can you explain whats going on here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can - here's the historical context: https://twitter.com/pchaigno/status/961134607113637889

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tyty, makes sense 👍

@@ -0,0 +1,2 @@
src/__generated__/*.ts
node_modules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, a great move 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that the graphql-js patch wasn’t applying because the whole file had changed due to prettier on save :)

@@ -0,0 +1,106 @@
/* tslint:disable */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, shame, guess the gitattributes has to be merged before we get to use it in PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? Is it not working for you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're flattened, yep, but I can't tell if that's because the PR is too long because all of the in app source code changes are also flattened after it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. I’m pretty sure that some of these artefacts were expanded by default yesterday.

import { ConcreteFragment } from "relay-runtime";
export type About_artist = {
readonly has_metadata: boolean | null;
readonly is_display_auction_link: boolean | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our schema this looks like:

type ArtistItem implements Node {
  [...]
  # Only specific Artists should show a link to auction results.
  is_display_auction_link: Boolean
}

It would be nice to bring these comments into the interface in v1.1 of the TS generator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, I have some experience with this in some internal tooling we use where I work. Can you create an issue in https://github.com/relay-tools/relay-compiler-language-typescript ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great, I threw a few minutes at understanding the code to add it- happy to leave that to you 🍡

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless @kastermester has time immediately, I think that somebody else –such as yourself– contributing it would be great. At least you’ll know who to ask questions and perhaps @kastermester knows of some things to keep in mind from the top of his head.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ergh, that alloy, always pushing for more contributors 📟

Will continue my digging

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest concern here comes from interface types and how they interact with the type generation (without remembering exactly how that works in the TS plugin here mind you). If the type ends up being something like:

type MyType = {
  __typename: 'MyType1';
  name: string;
} | {
  __typename: 'MyType2';
  name: string;
} | {
  // Some comment here telling that this is to cover future types being added
  __typename: ' %other';
}

The question now becomes - which comment should be added to the name property - assuming there's one for the interface, and one for each of the types. Previously I have added the comment from the concrete types, such that the interface comment never shows up, but simply the concrete type comments. This has the effect on editors (at least VS Code but AFAIk all editors get their info from the TS language server) that you get the combined comment when simply accessing name.

I would love to find a better way to handle this sort of thing - but disregarding that, it should be pretty straight forward. If you have the time to make a pull request that'd be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case TABS.SHOWS:
return <Shows artist={this.props.artist} />
return <Shows artist={this.props.artist as any} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these additional as any are due to the relay data masking, I think @kastermester covers that here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the only reason that in some cases we didn’t need to specify as any previously was that those components were overriding the constructor without re-typing the props, which meant that the component basically accepted anything by default.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The future plans tie in with the way the artifacts are generated - it means that you cannot pass data to a component, without having actually specified the fragment as part of your fragment text (ie. you need to spread the child component's fragment into your own at the appropriate place to be able to render the child component with the given data).

As mentioned, we're waiting for conditional types coming in TS 2.8 (and conditional infered types as well to be able to type up the componentRef prop).

this.activeBids.refs.component.refreshActiveBids()
this.conversations.refs.component.refreshConversations(() => {
this.activeBids.refreshActiveBids()
this.conversations.refreshConversations(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And using public API.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nitpicking for you guys here: Stuff coming from ref callbacks in React can be set to null (by the ref callback) ie. when the component is unmounting. I'd advice setting the type to T | null and then initialize it to null. Also newer TS versions have definite assignment checks that will complain about this sort of code.

You can then define a method such as this:

function assertNonNull<T>(obj: T | null): T {
  if (obj == null) {
    throw new Error('Object is null');
  }
  return obj;
}

And use that when you assume the object is non null. You may be aware of this and simply having chosen to save the hassle, but I thought I'd let you know :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one 👌 I actually was thinking of using invariant soon, which I assume does this type narrowing too, so that we can use existing babel transforms to strip those assertions out for production code.

Regarding the ref callback also calling for unmounting, that’s just a thing that never happens for these two components.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you can type a function to never return if some condition is not met, sadly. I believe it is baked into flow that the invariant function behaves like that.

Regarding the ref callback also calling for unmounting, that’s just a thing that never happens for these two components.

Yeah I know, I'm just personally a bit obsessed with semantics and there's something in me that itches when I see stuff typed in an incorrect way, as I know the next person editing the code is going to rely on the types and make assumptions based on that. I understand how doing the code properly can be a bit of a hinderance and annoyance though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, good point. Looks like it is being discussed microsoft/TypeScript#10421 & microsoft/TypeScript#8655.

I hear you on worrying about the next person, but I try to strike a balance for my coworkers between untyped and typed code that doesn’t become too tiresome on them :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beauty of TypeScript 😄

initial_message: "Adoro! Por favor envie-me mais informações",
last_message_id: "222",
messages: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the relay runtime warn you about these missing fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, the expanded type definitions did that.

@alloy
Copy link
Contributor Author

alloy commented Feb 7, 2018

Alright, going for the merge 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants