-
Notifications
You must be signed in to change notification settings - Fork 35
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
Is it possible to resolve multiple fields in one function? #29
Comments
I think you can use lazy initialization pattern and store your loaded data inside resolver class once it requested and reuse this data in any resolver method. Since resolvers are services, and services are scoped (scoped to request) this "cached" data inside resolver class will persist during a single user request. |
@pleerock: Thanks, but that doesn't actually solve the problem. Rather than one database query per field, I want to make one database query that will return all fields that the GraphQL query requested. Caching the data doesn't solve this problem, it just means that every field won't be queried more than once. |
by "all fields" do you mean data from multiple tables? |
When I run with ORM logging turned on, and I send this query: query {
people {
name
homeAddress
}
} I get this result:
Notice how the database query for fetching |
Is it possible to write a custom resolver for an entity, like my |
Is it possible to resolve multiple fields at once in a single custom resolver function? I realize this is an unusual request, so let me explain my use-case.
I want to create an application that can track changes over time, and respond to date-based queries. For example, lets say I want to track how people move over time. I want to allow queries that look like this:
Then, I could specify a date in a HTTP header, include that value in the
context
object, and use that date when making queries. The entities look like this:As you can see, the
PersonKVString
entity holds a key-value pairing, along with a time duration that the key-value pairing is valid. I currently have a custom resolver that looks like this:This works, but as you can see, it generates one complex resolver query for every field that the client requests. Ideally, I'd like to generate only one query, which fetches the
PersonKVString
entities for every field requested. I figured that I might be able to do that, if I could write one resolver that handles every requested field at once.Any thoughts? Am I solving this problem the wrong way?
The text was updated successfully, but these errors were encountered: