Skip to content
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

[Docs]: Missing documentation on relation resolvers in a service #6474

Open
1 task
dac09 opened this issue Sep 30, 2022 · 5 comments · Fixed by #6465
Open
1 task

[Docs]: Missing documentation on relation resolvers in a service #6474

dac09 opened this issue Sep 30, 2022 · 5 comments · Fixed by #6465
Assignees

Comments

@dac09
Copy link
Collaborator

dac09 commented Sep 30, 2022

Summary and description

We don't really talk about how the relation resolvers generated at the bottom of a service file work.

The only mention is here: https://redwoodjs.com/docs/graphql#redwoods-resolver-args - which is useful, but not enough IMO.

What do I mean by relation resolvers?

// services/posts.ts

export const post: QueryResolvers['post'] = /**/
export const createPost: MutationResolvers['createPost'] =  /**/

// 👇 these are your "relation" or field resolvers
- export const Post: PostResolvers = {
+ export const Post: PostRelationResolvers = {
  author: (_obj, gqlArgs) => /**/
}

These resolvers are invoked when a "relation" on the Post model is invoked, in this case if the query requested Post.author.name for example.

Things we should cover:

  • how does a query/mutation map to a service function?
  • what is the order of preference i.e. if you define a relation resolver for a field, it will be invoked first
  • how to optimise queries either:
    a) use prisma includes in the main service function + check if already included in root)
    b) use dataloaders

Are you interested in working on this?

  • I'm interested in working on this
@cannikin
Copy link
Member

I've started on this in the tutorial here: #6465

@jtoar jtoar linked a pull request Oct 4, 2022 that will close this issue
@dac09
Copy link
Collaborator Author

dac09 commented Oct 25, 2022

@cannikin is it worth adding a section the docs/reference (in the services section) and not just the tutorial?

It honestly is one of the most confusing things in services - happy to give it a go if you want to focus on the tutorial piece.

@cannikin
Copy link
Member

Yep, I had planned to add a more in-depth section in the Services docs themselves. Feel free to add something if you need a break from Typescript for a while! :)

@cannikin
Copy link
Member

This probably shouldn't be closed—this was referring to a more in-depth description of relation resolvers, while the intro in the tutorial is pretty minor.

@cannikin cannikin reopened this Oct 31, 2022
@cannikin
Copy link
Member

I assigned this over to you @dac09 but let me know if you change your mind!

@cannikin cannikin assigned dac09 and unassigned cannikin Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants