-
Notifications
You must be signed in to change notification settings - Fork 1k
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
(1.3.0) Generated resolver type is not callable (and related issues) #5370
Labels
Comments
As 1.3.0 has now been released, this issue applies to 1.3.0 as well. Updated repro without needing to upgrade to yarn create redwood-app redwood-resolvers-not-callable --typescript
cd redwood-resolvers-not-callable
yarn rw g sdl UserExample
yarn rw type-check |
Cool, this all makes sense - I wonder if Redwood should provide a function for in testing that's like a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this pertains to 1.3.0-rc.0.
#5216 improved the GraphQL codegen resolver types (and is a good change!), but it seems to create some problems with calling resolver functions from tests in TypeScript (including in generated service tests).
To reproduce a simple case:
yarn create redwood-app redwood-resolvers-not-callable --typescript cd redwood-resolvers-not-callable yarn rw upgrade --tag rc yarn rw g sdl UserExample yarn rw type-check
Several errors will appear, such as:
A direct solution to this error could be to include
makeResolverTypeCallable: true
(part of https://www.graphql-code-generator.com/plugins/typescript-resolvers) in the defaultgraphql-code-generator
config.With that said, the above change will reveal further type errors, as the resolver typings require 2 arguments, e.g.:
It would be good to both improve the generated tests so they type-check and to demonstrate proper arguments for the new typings. It’s simple enough to add
{}
forargs
where necessary, but I think it’s non-obvious what should be passed as the second (obj
) argument.Possible solutions here might involve some sort of test helper(s) to either
obj
) parameterAddendum: strict null checks
I will note that with
strictNullChecks
disabled, one can simply passnull
orundefined
as the second argument (or for any ofroot
,context
, orinfo
). However, withstrict: true
(or even juststrictNullChecks: true
) in tsconfig.json, things get a bit more complicated with errors like:and
I haven't quite figured out why the
'await' operand
error occurs, but I have been able to work around it by overridingcustomResolverFn
to returnPromise<TResult> | TResult
instead ofPromise<Partial<TResult>> | Partial<TResult>
-- though there may be drawbacks to this, so I'm not necessarily proposing it as a solution.For the second error I've been using a helper that accepts a
Partial
of the second (obj
) argument and basicallyundefined
resolver functionobj
argument to the correct non-Partial type (basically a hack).The text was updated successfully, but these errors were encountered: