-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Use Template Literal Types in TS 4.1 #158
Comments
Seems that it uses the new feature https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types |
This repository should be checked. |
I've figured out prototype! I'll try on this. /*
* TypeScript 4.1
*/
type GetSchema<Schema> =
Schema extends `type Query { ${infer RootQueryName}: String! }`
? { [k in RootQueryName]: string }
: never
type QueryBuilder<Schema, Query> = Query extends `{ ${infer RootQueryName} }`
? RootQueryName extends keyof Schema ? { [k in RootQueryName]: Schema[RootQueryName] } : never
: never
type Schema = GetSchema<`type Query { hello: String! }`>
type ExpectQueryType = QueryBuilder<Schema, '{ hello }'> // => { hello: string }
type ExpectNever = QueryBuilder<Schema, '{ foo }'> // => never As |
basic parser implemented https://github.com/acro5piano/typed-graphqlify/blob/next/src/type-test.ts |
It turns out to be difficult for the current TypeScript type's performance. see: dotansimha/graphql-typed-ast#2 (comment) Instead, how about implement "minimal overhead" syntax?? mutation updateUserMutation($input: UserInput!) {
updateUser(input: $input) {
id
name
bankAccounts {
id
}
}
} Common API: MUTATION.toString() // => print query
MUTATION.dataType() // => returns data type
MUTATION.variableType() // => returns variable type
import { mutation, f } from 'typed-graphqlify'
const MUTATION = mutation('updateUserMutation($input: UserInput!)', {
['updateUser(input: $input)']: f(
'id',
'name',
f('bankAccounts', f({
'id',
})),
`,
})
import { input, mutation, f, types } from 'typed-graphqlify'
const UserInput = input('UserInput', {
name: types.string,
})
const MUTATION = mutation(`updateUserMutation($input: ${UserInput})`, {
['updateUser(input: $input)']: {
id: types.string,
name: types.string,
bankAccounts: {
id: types.string,
}
},
}) |
In the following repository, it parses SQL into TypeScript type. No codegen tool is needed anymore.
https://github.com/codemix/ts-sql
The syntax should be like this:
I think we can do the same thing in GrapQL.
I've started to work on this, will use
next
branch.The text was updated successfully, but these errors were encountered: