-
Notifications
You must be signed in to change notification settings - Fork 78
[Relay] Uses latest version and our patches #982
Conversation
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. | ||
# |
There was a problem hiding this comment.
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 ^
Generated by 🚫 dangerJS |
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! :) |
Alright, this is all green now 👍 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff, thanks @pchaigno 🥇
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, a great move 👍
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea!
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 🍡
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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} /> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye 👍
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, simpler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And using public API.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Alright, going for the merge 🚀 |
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.
Afterwards you can use the regular script again:
#skip_new_tests