-
Notifications
You must be signed in to change notification settings - Fork 2k
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
TypeScript GraphQLObjectType and TArgs #2152
Comments
This was also raised in DefinitelyTyped/DefinitelyTyped#21359 |
@williambailey Thanks for the detailed report 👍 |
+1 |
To update this issue, it's my understanding that |
This specific issue was solved in #2488 so this issue can probably be closed. |
Having just gone through the migration to v15 this is still an issue and arguebly worse since #2488. Now we have This then leads to the situation where your typescript failes to build when you try to have infered and typed
interface MyImageRequestArgs {
[argName: string]: any;
height: number;
width: number;
} Our workaround at the moment is to patch the --- a/node_modules/graphql/type/definition.d.ts
+++ b/node_modules/graphql/type/definition.d.ts
@@ -511,7 +511,7 @@
export interface GraphQLFieldConfig<
TSource,
TContext,
- TArgs = { [argName: string]: any }
+ TArgs = any
> {
description?: Maybe<string>;
type: GraphQLOutputType; I will continue to see if there is something else going on that i'm missing but thought i'd give a quick update to the ticket. |
Looks like someone else aready tried to fix it same way, #2518 just linking the PR |
Do we have an update on this? I using version 15.5.0 and still facing the aforementioned issue
|
Bump. Same issue. |
Similar to #2829 |
The TypeScript definitions currently specify a
TArgs
generic type onGraphQLObjectType
which then flows intoGraphQLObjectTypeConfig
,GraphQLFieldConfigMap
andGraphQLFieldMap
.All field resolver arguments on an object therefore have to have the same base type.
This, to me, is unexpected as each resolve function can have it's own differing requirements as to what arguments and it makes it awkward to use types arguments as you need to specify something like
any
when creating theGraphQLObjectType
instance. For example:I suppose you could stick with the default
TArgs
type and then use a typescript user-defined type guard. However this is even more awkward and seems unnecessary given that we are specifying the arguments in theGraphQLFieldConfig
and can be sure that graphql has already validated and asserted that the arguments match what we expect when it comes to calling the resolve function.The text was updated successfully, but these errors were encountered: