-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
Setting parent
, context
and pageInfo
types for relay plugin
#1305
Comments
There is a lot to unpack in this question, and touches a lot of different components. In general, in Pothos you will almost never define types for your resolver manually. They should always be typed for you based on types provided elsewhere. This is probably very different than your existing set up, but leads to much better type safety, and an easier developer experience once you get things set up, and understand the patterns being used. Some of what you asked about isn't well documented, and currently requires some workarounds (mostly extending the pageInfo type to have a totalCount type) Rather than trying to explain each piece individually, I tried to create a quick interactive demo that adds most of the pieces you asked about: |
Wow, thank you for such a thorough and fast response! It looks like This gives me plenty to work with for a while. Thanks again! |
Context is documented here: https://pothos-graphql.dev/docs/guide/context Root is kind of obscure, it should probably be added to the API docs, but I've never actually seen it used in a real GraphQL API, and I am not entirely sure that it's supported in all the popular graphql server implementations. Extending existing types is probably something that could be covered in the docs. I did remember there was a less hacky solution (but also undocumented) to extend pageInfo:
This could probably be documented, and I think won't pick up the extended types from the builder, so would probably require a type cast in the resolver (which probably could also be fixed pretty easily) PRs for docs are always appreciated if you see something that's missing! |
I'm investigating doing a migration to pothos for a fairly complex existing codebase. We use a custom
PageInfo
type for relay connections as well as customParent
andContext
types for resolver arguments. Here are our types:The relay plugin documentation page lists a large number of options, but doesn't show any examples of using them. I see the following possibly relevant options:
pageInfoTypeOptions
pageInfoFieldOptions
defaultConnectionTypeOptions
defaultConnectionFieldOptions
Here's some follow-up code that tries to define a resolver using the above types:
The resolver does not type-check, failing with this error:
I apologize if this is a very basic question! Any documentation pointers or tips here would be much appreciated.
The text was updated successfully, but these errors were encountered: