-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[1.0] Fix graphql compiler on typescript #949
[1.0] Fix graphql compiler on typescript #949
Conversation
It's usefull to parse any graphql queries
adc55d0
to
9f60674
Compare
Deploy preview failed. Built with commit adc55d074820650df7ec1dbd46976860beeb5c4b https://app.netlify.com/sites/using-drupal/deploys/591345b4cf321c336be384d3 |
Deploy preview failed. Built with commit adc55d074820650df7ec1dbd46976860beeb5c4b https://app.netlify.com/sites/gatsbyjs/deploys/591345b4cf321c336be384cd |
Deploy preview failed. Built with commit adc55d074820650df7ec1dbd46976860beeb5c4b https://app.netlify.com/sites/gatsbygram/deploys/591345b4cf321c336be384d0 |
Deploy preview ready! Built with commit 7cc009e |
Deploy preview ready! Built with commit 7cc009e |
Deploy preview ready! Built with commit 7cc009e |
@@ -19,7 +19,10 @@ module.exports.modifyWebpackConfig = ({ config }, { compilerOptions }) => { | |||
const opts = { compilerOptions: copts, transpileOnly: true } | |||
config.loader(`typescript`, { | |||
test, | |||
loader: `ts-loader?` + JSON.stringify(opts), | |||
loaders: [ | |||
`babel?${JSON.stringify(config._loaders.js.config.query)}`, |
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 may do more than you want here. You really only want to run the babel query extractor plugin. This will run the file through all the babel transforms (admittedly most won't matter after tsc runs).
Honestly you probably better to just leave this off entirely, the plugin isn't important to running anything, it's really more of a minification step, as the queries aren't used a runtime it's better to just remove the code.
another option is to move the babel plugin to a proper package that can be consumed by plugins directly
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 know it's a bit overkill, I just want to avoid any futur missed babel transformer (we never think to typescript module ^^).
I'm not a big fan with another package for babel, we have already manyyyyy packages (and it introduce some tricky part for anyone want use gatsby without starter)
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 for information:
// During a `yarn build` on my starter
config._loaders.js.config.query = {
"plugins": [
"D:\\Projets\\gatsby-starter\\node_modules\\gatsby\\dist\\utils\\babel-plugin-extract-graphql.js",
"D:\\Projets\\gatsby-starter\\node_modules\\babel-plugin-add-module-exports\\lib\\index.js",
"D:\\Projets\\gatsby-starter\\node_modules\\babel-plugin-add-module-exports\\lib\\index.js",
"D:\\Projets\\gatsby-starter\\node_modules\\babel-plugin-transform-object-assign\\lib\\index.js"
],
"presets": [
"D:\\Projets\\gatsby-starter\\node_modules\\babel-preset-es2015\\lib\\index.js",
"D:\\Projets\\gatsby-starter\\node_modules\\babel-preset-stage-0\\lib\\index.js",
"D:\\Projets\\gatsby-starter\\node_modules\\babel-preset-react\\lib\\index.js"
],
"cacheDirectory": true
}
I will try to only take graphql-extract plugin ;) (but tomorow, it's late ^^)
@@ -50,7 +50,8 @@ class Runner { | |||
} | |||
|
|||
async parseEverything() { | |||
let files = await globp(`${this.baseDir}/**/*.js`) | |||
let files = await globp(`${this.baseDir}/**/*.+(t|j)s?(x)`) | |||
files = files.filter(d => !d.match(/(\.stories\.|\.test\.|\.d\.)/)) |
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 (I think) is too prescriptive. you'll undoubtably catch actual source files. perhaps it makes sense to make a a config option for "ignore paths" or something that is specifiable in the gatsby-config
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.
It's based on classic patterns of jest/storybook/typescript declaration files 😉 ignorePath
can be a cool options but I don't want to provide useless option as it's commun patterns.
@KyleAMathews What do you thing on this issue?
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 understand why you chose it :) my point is only that conventions only meet some peoples needs. for instance in my own projects this wouldn't catch any of my test files or stories. More importantly tho it will likely silently filter real source files which is a different version of the problem of this problem
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 line is only to avoid a warning on .d.ts file in my current project, I've just add stories and tests to optimize a little bit more ;) (so it's not really important for now if any test file are not filtered)
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 agree with @jquense that by default we shouldn't ignore anything.
Shouldn't this just be globbing the src
directory 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.
All this files are in src (one folder for one module, with tests beside component)
My only issue is with d.ts (needed for js module and global var as graphql) I can remove test and stories if you want ;) It was just to avoid useless processing
BTW I don't try to have a project with coffeescript, but I think it will have the same issues |
@fabien0102 what's the status on Gatsby + Typescript? |
Sorry, I was very busy these last weeks, I will update this PR during next week ;) |
No worries! Get to it when you can!
…On Thu, Jun 1, 2017, 1:13 PM Fabien BERNARD ***@***.***> wrote:
Sorry, I was very busy these last weeks, I will update this PR during next
week ;)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#949 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AYdmDeJpnHaLgDtahPx9UHcDp-tbeXiXks5r_xt3gaJpZM4NW8dY>
.
|
This is to avoid conflit with `@types/{packageName}` pattern into packages.json
@@ -1,3 +1,3 @@ | |||
const regex = new RegExp(`[^a-zA-Z0-9_]`, `g`) | |||
|
|||
module.exports = key => key.replace(regex, `___`) | |||
module.exports = key => key.replace(`@`, ``).replace(regex, `___`) |
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 don't think removing this is the best option, you can get namespace conflcits on fields without the @
that aren't resolvable.
I did fix this in two ways tho in #1136
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 will cherry-pick your commit 😄 For instant I just try to have a functionnal gatsby env, I will clean this PR before remove [WIP]
tag 😉
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.
@jquense I've cherry-pick your two commits in my branch and…
It's not working for me…
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.
looks like you didn't change the queries to adjust to the commits? or maybe i didn't update the examples. it replaces characters with a single _
instead of 3 so frontmatter_updateRole
etc
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.
Indeed! My bad
After many pains, this PR is fully working on my starter integration (fabien0102/gatsby-starter#24) |
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.
Looking good! Sorry for all the API changes but glad you were able to get it working again.
I'm not in love with adding stuff to globs, etc. to support additional languages but this is the cheapest way to get this working right now for sure. This is what we did in 0.x and it worked out alright. When we add support for more compile-to-js languages we can debate a better API then and update this plugin accordingly.
@@ -15,14 +14,6 @@ import type { DocumentNode, DefinitionNode } from "graphql" | |||
|
|||
const readFileAsync = Bluebird.promisify(fs.readFile) | |||
|
|||
function getAssignedIdenifier(path) { |
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.
was this not being used?
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.
My VSCode tell me that is not used, but you can recheck ;) (I try to remove unused code when I see 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.
@jquense you know what this was used for?
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.
well if no code is calling it whatevers. We can recover it later if it's needed for something.
Thanks again @fabien0102 for holding the line on Typescript :-D |
@KyleAMathews When do you plan a new release? I need a "real" version for my starter 😉 |
As soon as I finish #1174 going to do a beta release! |
Perfect! |
Bug description
Actually graphql queries are compiled with a complexe ast parser and a babel plugin. Due to typescript files don't use any babel loader and not finished by
.js
they are totally ignored in this process.What I did
Just add a
babel
into typescript loader (and hijack query from js loader), and deal with.ts|.tsx|.jsx
files for queries parsingIntegration test on my starter