Open
Description
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:
const mouseQuery = gql`
query Mouse($mouseId: String!) {
mouse(mouseId: $mouseId) {
name
bio {
full
}
}
}
`
// generated types
type Mouse = {
mouse: ({
name: string;
bio: ({
full: string;
}) | null;
}) | null;
};
type MouseVariables = {
mouseId: string;
};
with
// names may vary
import {
TypeFromQuery,
VariableTypeFromQuery
} from 'ts-graphql-plugin';
const mouseQuery = gql`
query Mouse($mouseId: String!) {
mouse(mouseId: $mouseId) {
name
bio {
full
}
}
}
`
type Mouse = TypeFromQuery<mouseQuery>;
type MouseVariables = VariableTypeFromQuery<mouseQuery>;
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!
Metadata
Metadata
Assignees
Labels
No labels