In this post I will walk you through how to build a GraphQL Server using Hot Chocolate and Entity Framework.
Entity Framework is an OR-mapper from...
For further actions, you may consider blocking this person and/or reporting abuse
Awesome post!, solve many of my questions when looking in HotChocolate documentation, as a newbie in the web development i get confused when i studied REST architecture, but when i see graphql, as a .NET enthusiast, i just know that this would be ideal for my database project, thanks a lot!!!
I would like to contribute to HotChocolate project, not like programmer but as a translator in the documentation, i'm a spanish native speaker.
Hi,
the best way to get in touch with us is by heading to our slack channel. You can find the slack invite link on our github repo.
Great tutorial @michaelstaib . The only concern I have is your DB Entities (Domain Models) are being exposed through the graphql schema. Is there any pattern you use to hide them? Maybe you have a GraphQL Gateway? Mobile -> BFF (GraphQL with stitching) -> contoso microservice (graphQL + EFCore as shown above)?
This would mean that in addition to stitching, you would have your "view models" which map from the domain models at this BFF graphql, to not expose any database fields you don't want to?
There are actually easier ways to do that :) This example was only to show how you can couple filtering in hc with your ef context. When planning for a proper project I would not couple my schema to the DB and also think about various other approaches. We have a great slack channel ... so I encourage you to join we have lots of schema design discussions there.
HI Michael, Can we use following attributes in Azure Functions?
[UsePaging]
[UseSelection]
[UseFiltering]
[UseSorting]
Please provide if you have any github sample for that.
Thank you!
There is no technical difference in the GraphQL core between Azure Functions and ASP.NET Core.
So yes :)
Hi Michael,
Just to let you know that selection on the model property does't work anymore. E.g. I followed this exact tutorial and this bit doesn't work anymore: enrollments(where: { courseId: 1 })
query {
students(where: { lastName: "Bar" }) {
firstMidName
lastName
enrollments(where: { courseId: 1 }) {
courseId
course {
title
}
}
}
}
I am using the latest of asp.net core and the latest of Hot Chocolate as of today:
The playground shows error and doesn't allow to execute the enrollment where clause:
"unknown arguments on field enrollments"
TA
That could be because of the paiging. The request which is needed in case of paging enabled (nodes added) -
query {
students(where: { OR: [{ lastName: "Bar" }, { lastName: "Baz" }] }) {
nodes {
firstMidName
lastName
enrollmentDate
enrollments (where: { courseId: 1 }) {
grade
course {
title
}
}
}
}
}
Hi Michael, thank you for the article and especially for the middleware order diagram, that helps a lot with understanding how things work.
Hi Michael @michaelstaib
Look, I don't like this:
[UseFiltering]
public virtual ICollection Enrollments { get; set; }
Because I don't like to apply attributes to my models.
My question is:
There's a way that I can get this behavior but by applying it into ObjectType without losing the IQueriable feature?
You can also use our fluent API.
Hello Michael -
Unable to find the entities Student, Enrollment and Course in Sql server but appication working fine. Please help me to find the tables in sql server.
How could I implement a mutation with a call to context.saveCahngesAsync? 🤔