-
-
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
How to get params type? #52
Comments
Hi @zwh1666258377, thank you for your interest in this project! Do you mean operation params by const params = { $input: 'UserInput!' }
// `typeof params` is just { $input: string } Unlike We possibly create params builder like this: import { graphqlify, ParamsBuilder, types } from 'typed-graphqlify'
const builder = new ParamsBuilder('$input', 'UserInput!', {
name: types.string,
})
builder.toString() // => { $input: 'UserInput!' }
typeof builder.type // => { name: string }
// now, type-check is enabled
graphqlify.mutation('UpdateUser', params(builder), {
updateUser: builder.render({ name: 'Tom' }, {
name: types.string
})
})
// This must throw type error
builder.render({ name: 123 }, { ... }) And the interface will look this: class ParamsBuilder<T> {
constructor<T> (paramName: string, typeName: string, type: T)
toString(): string
render(params: T): T
} Also note #51 might affect it. Thanks |
Or, simply import { graphqlify, types } from 'typed-graphqlify'
interface UpdateUserParams {
name: string
}
graphqlify.mutation<UpdateUserParams>('UpdateUser', params({ name: 'Tom' }, {
updateUser: {
name: types.string,
},
}) |
However, people query variables like fetch('/graphql', {
body: JSON.stringify({
query: ...,
variables: {
name: 'Tom',
},
}),
}) |
👍 |
This is what I'm trying to do with typed-graphqlify right now, however in the output after conversion to string, the quotation marks around 'Tom' are gone, making the GraphQL syntax illegal. Any way to circumvent/fix this? |
This issue might help you. Which version do you use? |
Got it. https://github.com/acro5piano/typed-graphqlify/blob/master/src/__test__/index.test.ts#L254 Currently we expect query-level vars, so in your case you have to use Thanks! |
I created a helper function that recursively runs |
like title...
The text was updated successfully, but these errors were encountered: