Noob
Noob

Reputation: 1024

What is a named Apollo Server field within a resolver? How does it work?

In a server I'm working on, I've noticed it has different named resolvers and I'm unsure how they work:

export const resolver = {
 Query: {
  getUsersById(...
 },
 Mutation: {
  updateUserById(...
 },
 User: {
 accounts(...
 },

I understand that the Query field will mean that the resolver getUserById will be a query and the same with resolvers within the Mutation field. I can query those by doing:

query {
  getUsersById(...)
}

I don't understand how this works with named fields since obviously I can't do:

user {
 accounts(...)
}

I can't find any documentation on this either, so any clarification would be appreciated!

Upvotes: 0

Views: 188

Answers (1)

VikR
VikR

Reputation: 5142

Those may be field resolvers. When Apollo finishes a query or mutation resolver and is about to return an object, e.g. in your example, Users or accounts, it runs it through any field resolvers that are present for that object. The field resolver can modify or add fields that are part of the object.

Upvotes: 0

Related Questions