-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Language plugin support. #2293
Language plugin support. #2293
Conversation
Badass |
While working on the TypeScript equivalent of the babel plugin I noticed that (at least for ts-loader), the file name that gets passed into the TypeScript transformation context is not actually an absolute path to the file. I need to do some testing to verify whether or not that is the case for babel loader as well. If that is the case then there's some minor changes needed to the babel plugin in order to make it work properly when setting the |
97f9f4a
to
97c58bf
Compare
@kassens @jstejada Alright, regardless of the webpack thing that @kastermester is still going to look into, this should now be in a good state to review. |
@@ -15,11 +15,12 @@ const GraphQLCompilerContext = require('./graphql-compiler/core/GraphQLCompilerC | |||
const RelayCodeGenerator = require('./codegen/RelayCodeGenerator'); | |||
const RelayFileWriter = require('./codegen/RelayFileWriter'); | |||
const RelayIRTransforms = require('./core/RelayIRTransforms'); |
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.
Currently Relay only exports the predefined groups of transforms from https://github.com/facebook/relay/blob/a8af6d7dea1c087bd6c5ba1ca4a2f538d9989cff/packages/relay-compiler/core/RelayIRTransforms.js. However, other language plugins will want to re-use some of these just like the Flow generator does. We are currently doing that in our TS plugin by simply plucking the ones that the Flow generator uses out from the pre-defined groups, but this is fragile and so a more stable solution would be appreciated.
What do you think would be the best way to do this? Export all transformers or is it unlikely that a type generator would need any other builtin transforms than the ones that the Flow generator also uses and so we should just add a predefined group for type generators?
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 currently leaning towards creating a predefined group for type generators.
c19ed6f
to
1a085e7
Compare
Rebased on master again. |
if (!condition) { | ||
throw new Error(util.format(msg, ...args)); | ||
} | ||
} |
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.
Any idea why this needed to be defined in FindGraphQLTags.js
rather than importing 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.
I think it was to allow the compiler to be more restrictive in its dependencies, but I'm not sure
1a085e7
to
d3780a9
Compare
@kastermester Do you have an update re the web pack stuff that still needs to be done? Or otherwise some details about what I should look into? |
@alloy I haven't had time to look into it yet. But I'd say if you're using the option to put all artifacts in a single directory with the babel plugin and it works - then there shouldn't be any issues :) |
@kastermester Re-reading your original comment about the web pack issue, it seems like you’re saying that the issue was around determining the path to the destination directory, is that correct? If so, when using the |
Without using the new artifactDirectory option puts all artifacts in a single directory, where previously it would be put in a directory residing inside the same directory of the file. This meant requiring artifact files were simply With the artifactDirectory we need some way of finding the single directory where the artifacts are stored. My initial attempt (in the TS plugin) I attempted to use the fileName/filePath property in the TypeScript transformation context and resolve a relative require (ie What I have ended up with (so far) in the TypeScript case is to give the responsibility back to the user. Ie: In webpack, define an alias What I haven't had time to test yet - is whether the babel loader is passing absolute file names to the file being generated as opposed to the TS loader, or if it exhibits the same issues. |
Oh I see now what you mean, you’re referring to the runtime requiring of the concrete node, whereas I was referring to the types. We’re using a Babel pipeline in our React Native app and it works well in that case 👍 |
Ah yes, this relates to the PR relay-tools/relay-compiler-language-typescript#21 for the TS transformer and the babel relay plugin in Relay. Might not have made that clear enough. |
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.
This looks pretty awesome.
@kassens, care to take a review?
if (!condition) { | ||
throw new Error(util.format(msg, ...args)); | ||
} | ||
} |
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 think it was to allow the compiler to be more restrictive in its dependencies, but I'm not sure
d3780a9
to
7c36930
Compare
CI is red on master, which is fixed by #2318. |
Alright, everything has been rebased and tested to work well in:
Interesting note about the JS example is that with the addition of the So everybody wins 🎉 |
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.
@jstejada has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@jstejada Better have it land properly and well integrated than a half assed merge :) Thank you so much for looking into this. I think everyone here knows how stuff have a habit of getting in the way. Keep up the good work! :) |
@jstejada What @kastermester said! Thanks for all the effort thus far ❤️ |
Hey guys, any updates on this merge? We've been eagerly (but yet patiently) waiting for 7 months now... |
I left facebook in March 2017, can I re-join for a couple days to merge? |
FYI I’ll be rebasing this one over the weekend and signal @jstejada that we can continue. |
Ok
Other than the example app in the plugin repo I have not yet had the time to verify this in our larger apps. If you do in the meantime, please let me 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.
jstejada has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@@ -33,12 +36,12 @@ const formatGeneratedModule: FormatModule = ({ | |||
'use strict'; | |||
|
|||
/*:: | |||
import type { ${documentType} } from '${relayRuntimeModule}'; | |||
${flowText || ''} | |||
${documentTypeImport} |
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.
this would generate incorrect code if documentTypeImport
is an empty string. In which cases is documentType
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.
As discussed elsewhere, this was basically just following some of the existing code and would indeed generate incorrect code but only if the inputs were already incorrect anyway.
Hey @alloy, I have been using your D. |
Awww yeah! Thanks for all the assistance shepherding this through @jstejada 🙌 🍾 |
Any idea when a release will be cut containing these changes? |
@alloy Will this work for non-ts projects? |
@soneymathew The Note: If you're using flow this should allow flow to typecheck the fragment types akin to how it works if one were to use the haste module system prior to this merge. In short typechecking is applied to the relay properties based on the fragments being spread (Parent component can't render Child component without having done |
@kastermester That matches my understanding but, in this fork(soneymathew/relay-examples@18740d8), I couldn't make it work. |
@soneymathew As far as I can see this is due to the fact that there's still not a release of Relay published yet with the language plugin changes merged. 1.6.2 does not contain this PR. I think @alloy has a version of the relay compiler published with this PR applied somewhere that you can try out? |
Thanks @kastermester 🤦♂️ I was looking forward for this one way too long and skipped to check that fact... |
Heyyy @soneymathew, sorry just getting back online after being away for a bit. I don’t have builds of 1.6.2 with this code applied, the last I had was 1.6.1 just before 1.6.2 was released https://github.com/artsy/relay/releases/tag/v1.6.1-plugin.1 |
In case no one has seen it, this is included in the relay 1.7.0-rc.1 release! 🎉 https://github.com/facebook/relay/releases/tag/v1.7.0-rc.1 Thanks so much to the relay team and @alloy for all the work on this! |
Closes #2073.
Closes #1710.
In preparation for #2073 and as requested by @kassens, this adds language plugin support to relay-compiler.
The whole plugin aspect is really just a matter of consolidating all language specific APIs in the
RelayLanguagePluginInterface.js
file and moving all of the pre-existing JS/Flow related code around to conform to that plugin interface. i.e. nothing should have changed in the existing JS/Flow handling.The one actual additions are:
artifactDirectory
), such that fragment references can easily be imported from other artifacts without the need for the Haste module system. i.e. all imports assume the imported module is a sibling of the requesting module. This should also improve the experience of JS/Flow users.With this plugin infrastructure in place, @kastermester and I have been able to build a TypeScript plugin https://github.com/relay-tools/relay-compiler-language-typescript. (You can find example artifacts here.)
Things that are left to do:
package.json
filesBut these are not critical to being able to start reviewing and providing feedback.
Test plan
Adding the TS plugin to the TODO example app would require the following:
yarn add relay-compiler-language-typescript --dev
.babelrc
: