[Feature Request]: automatic type resolvers from graphql tags
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
AFAIK Typescript doesn't have the possibilities to `infer` the `TemplateStringsArray` that prevents automatic type resolving.
It seems like an hard issue for TypeScript to solve. The request has been around since 2019:
https://github.com/microsoft/TypeScript/issues/33304
I was thinking if we could create an alternative to:
```ts
type CurrentGraphQLFn = (texts: TemplateStringsArray): GraphQLTaggedNode;
graphql`
query something {
// ....
}
`
```
To something like this:
```ts
type GraphQLQuery = T extends keyof RelayPersistentQueries
? RelayPersistentQueries[T]
: GraphQLTaggedNode;
type FeatureRequestGraphQLFn = (query: T): GraphQLQuery;
// $graphql would be a new function from relay and keep the other one untouched for backward compatibility.
const query = $graphql(`
query something {
// ...
}
`)
```
If the compiler creates a type definition file with all queries like `Record` as the `RelayPersistentQueries` we would be able to automatically type queries.
This is good either way because if they manage to add the inferring feature to Typescript than we already have this functionality and would be easy to add to our `graphql` function as well. Then we only deprecate that `$graphql` function because I can agree that template literals looks better.
Contributor guide
Assessment
This issue has not been assessed yet.