GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
532 stars 67 forks source link

How to access the selectionSet from the Resolver ? #104

Open Samsv77 opened 1 year ago

Samsv77 commented 1 year ago

Hi, Is it possible to get the selectionSet in the Resolver ? The selectionSet is a flat list of the fields that the user requested, for example,

family {
   name
   child {
     name
  }
}

Would give the selectionSet ["name", "child/name"]

Thank you

paulofaria commented 1 year ago

As far as I remember, Graphiti doesn’t expose it, but the lower level GraphQL resolver exposes it. It is possible to provide that API, but it would make Graphiti’s API less concise. So back in the day I opted to not export it. Out of curiosity, why do you need it?

Samsv77 commented 1 year ago

I use it to know if I should explicitely pull the child information from the database. Since I have a large volume of data, I need to pull them in batch. I am not sure how to handle it when using Vapor Fluent, to decide whether to pull the relationship or not based on the graphQL query.

ZirgVoice commented 1 year ago

Use DataLoader there is an example