Add relation resolver using ExtendObjectType #3178
-
Hey there 👋 I am just wondering if the documentation at https://chillicream.com/docs/hotchocolate/api-reference/object-type/ is correct. I have a Query class that returns a list of Employees: // Removed The Employee class has a one-to-many relationship to the Absence, which should be exposed via GraphQL as well. I was wondering what’s the easiest possible way to do that. The way I’ve understood it, would be to introduce an object type extension using “Pure Code-First” as mentioned in the link above, so that’s what I’ve came up with: // Removed My first guess was that I should be able to introduce that GetAbsences function in the Query class as well, and the Parent Attribute would automatically recognize when to use that function, but that does not seem to work, so I switched to the approach with the ExtendObjectType attribute. I also registered that class in the Startup.cs file of ASP.NET: // Removed But when I try to query absences from the employees now, I always get an empty list, and there are no logs indicating that a database request to that table was done. A RTFM with a link would be totally fine, but I couldn’t find any V11 documentation covering this in more detail than the one above 😕 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
@danrot Can you create a project that reproduces the issue? I tried running the code you provided but it's working fine. See working sample project here: https://github.com/gojanpaolo/hotchocolate-3178 Runnning the following query: query {
employee(id: 1) {
absences {
id
}
}
} ... returns the following response {
"data": {
"employee": {
"absences": [
{
"id": 1
}
]
}
}
} |
Beta Was this translation helpful? Give feedback.
@danrot Can you create a project that reproduces the issue?
I tried running the code you provided but it's working fine.
See working sample project here: https://github.com/gojanpaolo/hotchocolate-3178
Runnning the following query:
... returns the following response