Comments (11)
It should be possible to use the TypeScript parser / emitter to inject the needed type annotations - although if you haven't used this API before it might be a bit tricky. I don't think it will be that costly using the TS API for this, it should be kinda fast - but obviously this would need to be verified.
from relay-compiler-language-typescript.
@alloy sounds good! I'm travelling this week but will get started on the PR after
from relay-compiler-language-typescript.
This makes sense, yeah, send a PR 👍
from relay-compiler-language-typescript.
I tried and I don't understand it quiet yet.. any hints to help me out?
from relay-compiler-language-typescript.
Hmm, yeah, this isn’t that easy right now. The plugin currently only operates on the types for the resulting GraphQL selections, not the artefact AST. The artefact AST comes in as just a large string from relay-compiler here, so the only way I could currently see this work is if we were to parse that text and regenerate it with the any
typings, but that seems a little costly. Maybe we can determine if the noImplicitAny
compiler flag is enabled and only then do the parsing/regeneration?
In any case, that’s where you should start with this.
from relay-compiler-language-typescript.
I hacked it together today.
function addAsAnyToObjectLiterals(oldSource){
const ts = require("typescript");
function transformer(context){
return function transform(node){
function visit(node){
if(node.kind === ts.SyntaxKind.ObjectLiteralExpression){
return ts.createAsExpression(node, ts.createTypeReferenceNode('any', []));
}
return ts.visitEachChild(node, visit, context);
}
return ts.visitNode(node, visit);
}
}
const source = ts.createSourceFile('', oldSource);
const result = ts.transform(source, [transformer]);
const printer = ts.createPrinter();
const newSource = printer.printFile(result.transformed[0]);
return newSource;
}
from relay-compiler-language-typescript.
Nice and simple 👌 And where are you adding this into your pipeline?
from relay-compiler-language-typescript.
should this be an option for relay compiler?
from relay-compiler-language-typescript.
@alloy I manually added it here in my project and it worked. If you want I can look into integrating it into this library.
from relay-compiler-language-typescript.
@sibelius I don’t think so, it’s a project wide TS setting, so my opinion is that we should fetch it from the project’s tsconfig (or perhaps there’s a runtime test for tsc options.)
@timjacobi Yeah that would be much appreciated! (And only do so when the option is enabled, as per above.)
from relay-compiler-language-typescript.
Closed by #83
from relay-compiler-language-typescript.
Related Issues (20)
- Generated refetch definition with variables can not pass the validation of backend, such as github.com/vektah/gqlparser/v2
- Generate GraphQL fragment files for VSCode GraphQL Extension fragment autocompletion HOT 2
- Cannot read property 'createKeywordTypeNode' of undefined HOT 8
- Support for [email protected] HOT 8
- Migrate travis CI release process to GitHub actions HOT 3
- Unknown directive 'appendNode' HOT 1
- module esnext HOT 2
- Why is it not releasing HOT 7
- `require` substitution is not working HOT 6
- doc: explain why configuration with a single artifact directory is suggested
- Update to TS 4.4 and update types to support exactOptionalPropertyTypes HOT 1
- @stream argument naming by schema spec is: `initialCount` not `initial_count` HOT 1
- Invalid AST Node error with graphql@16 HOT 2
- Typescript 4.5 type generation is broken HOT 6
- Relay Compiler generates Typescript Synthax error HOT 3
- Error: Cannot find module 'relay-compiler-language-typescript' on 15.0
- Fragment Typematching
- Input Types generated as readonly HOT 1
- deprecate this package HOT 1
- Issue with import of the __generated__
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from relay-compiler-language-typescript.