-
Notifications
You must be signed in to change notification settings - Fork 26
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
Examine the possibility to use type from queries without generation #117
Comments
hi, thanks for reporting issue. It’s not possible. The And with |
Hi, that was not really an issue 😄 And there is no shenanigans a typescript plugin can do about this? PS: Yeah, used wrong syntax sorry, was wavering between a generic and a function and mixed both --' |
Hey @Quramy, Seems like it will be soon doable: https://github.com/dotansimha/graphql-typed-ast (using an alpha TS version) How do you feel about it, is that functionality something you would like for this plugin? Cheers |
Template literal types is very interesting feature. But I will not use this in my plugin because I think lexing / parsing queries should be responsible for graphql-js . And recursive descent parser with string type literal can exceed TypeScript's recursive type limitation. |
Is it possible for the plugin to override the type of a tagged template expression? Or to insert a type assertion? import { DocumentNode } from 'graphql';
export interface TypedDocumentNode<Result = {
[key: string]: any;
}, Variables = {
[key: string]: any;
}> extends DocumentNode {
__resultType?: Result;
__variablesType?: Variables;
} It would be super helpful if the plugin could replace the inferred type of import { TypedDocumentNode } from "@graphql-typed-document-node/core"
const mouseQuery = gql`
query Mouse($mouseId: String!) {
mouse(mouseId: $mouseId) {
name
bio {
full
}
}
}
` as TypedDocumentNode<
{
mouse: {
name: string
bio: {
full: string
} | null
} | null
},
{
mouseId: string
}
> Passing a value with that type to, for example, Edit: I realized an By the way, this plugin makes me very happy! I love it! |
So I've learned that, no, TypeScript plugins cannot produce the effect of adding a type assertion to an expression. So instead, inspired by @ts-gql I made an ESLint plugin with an autofix that automatically appends type assertions to The plugin: @hallettj/eslint-plugin-ts-graphql The autofix avoids the step of importing generated types myself. The |
name: Feature request
about: Examine the possibility to use type from queries without generation
title: 'Create a function/generic to return the expected result of a query'
labels: 'question, feature request'
assignees: ''
---Describe the feature
Since typescript knows, thanks to this plugin, what are the expected key name and type of any query, could it be possible to have some sort of function or generic that would return the data from a query, without having to generate them?
It would replace:
with
Since we can have auto-completion for queries and query type generation, what would we need to make this happen?
--
Thanks a lot for this plugin, love it!
The text was updated successfully, but these errors were encountered: