Custom Queries / Resolvers that are Nested under User: Is it possible?


#1

This is what I mean:

user {
  getCustomResolver
}

Thanks!


#2

Figured it out:

  const { nodeId: userId } = event.context.auth

#3

@peter technically, that’s not the same. Resolver functions are always top-level fields (so directly under Query or Mutation). In order to really achieve what you want, you need to use a Gateway.


#4

Hey,

Thanks for the reply!

Are gateways supported? Things seem to be working as they should this way. Do you foresee any problems with this method?

Thanks again


#5

Peter, yes Gateways are supported. I have quite a few working examples on my Github, and Graphcool is also working on a boilerplate for a Gateway.

But back to your requirement. The way you implemented it now is absolutely fine, but it only works for ‘current user’. A Gateway would allow you to do something like:

query {
  User(id: "....") {
    customResolver { ... }
}

But it’s very well possible to do it like you’re doing it. But you can only do:

query {
  getCustomResolver
}

not:

query {
   user {
      getCustomResolver
   }
}

like you mentioned in your OP.