This article will cover two graphql options available for dotnet core:
Hotchocolate
Graphql-Dotnet (briefly)
So you're a dotnet developer a...
For further actions, you may consider blocking this person and/or reporting abuse
I would love to use HotChocolate, API looks amazing but API is very changed per 10.3.6. There's no way you can follow the docs even for hello world.. Right now I'm actively reading the source code instead of relying on the docs.. Give this lib a few months to get things in order - this is not ready for production !! If you use this tutorial for example, you will get up and running hotchocolate.io/docs/tutorial-01-g... but if you look at this page you get stuck straight away as the docs aren't updated, hotchocolate.io/docs/introduction . That's not a great look on an intro page
That is not entirely true the API has not changed and you just have to add
using HotChocolate.Execution;
to get the extension methods.I also answered this in your issue.
github.com/ChilliCream/hotchocolat...
Regarding production ready. We are. HotChocolate is the most spec compliant and the fastest GraphQL library for .NET. If you run just the parser kitchen sink tests from Facebook GraphQL-DotNet crashes but Hot Chocolate will run each of them.
Also it is the most feature rich GraphQL Platform for .NET. We have a very active support channel which solves problems of their users very quickly. If you post a question to us we answer within 12 hours most of the times immediately.
Further, apart from that we have a far bigger platform with tools like Banana Cake Pop (GraphQL IDE) or our .NET clients.
We will add to our documentation that you have to add this using. I thought personally that this is not necessary since most Dev IDEs will auto import those. It is basically the same like with Microsofts ServiceCollection many methods are extension methods that have to be imported.
hi Michael. I'm on VS Code.. there is no auto import happening. That's what a lot of devs use if on Mac or Linux. Please add the needed usings for all your examples or add a link to a sample project on GitHub where I can figure this out. I appreciate you taking the time to answer. As I said it looks like a great API, great features but I'm sure you understand how frustrating it is to get stuck
I do get that. We are working hard on out new documentation that we will release alongside the 10.4 release coming next week. I will add the usings to the examples and we will have blog posts going up with the 10.4 release showing how to use it with entity framework in more depth.
Hot Chocolate is developed on macOS and VSCode. That is why I thought that any other IDE would do the same auto import when pressing command + . on the missing method. But I agree that is not actually that obvious. Be assured that we will update the docs over the next week.
Thanks, been trying to figure out how to hook up a database to hotchocolate for a couple days. Looks like instead of hc, it's handled by asp.net and ef core, which I know next to nothing about. Lol, was reading Hotchocolate's - Tutorial Mongo where they say:
...but nothing about actually hooking up to mongodb, as of yet (facepalm). From reading this my next guess would be to combine info from that tut with Create a web API with ASP.NET Core and MongoDB somehow, and then implementing the schema and resolvers and such instead of a rest api. Lots to learn.
Thanks again.
That tutorial for mongo was not supposed to be published on the documentation. It kind of is not finished and stops mid-sentence.
Here is a good example of how you can do mongo with hc:
github.com/ChilliCream/graphql-wor...
Also we have an open slack channel where we help people along:
join.slack.com/t/hotchocolategraph...
However, version 10.4 is soon out and will bring support for projections and with that makes it even easier to bind your database to hc.
Regarding projections:
Given this Query type we generate all the nested types you need. By annotating with attributes you can add additional behavior on top of it.
When you now execute this query
This SQL statement is executed:
Thank you for info and redirect to the repo.
I actually got it working with the BookAPI example on the ms site, and the startwars example repo. I basically just followed the BookAPI tutorial until they started talking about controllers, then looked at the starwars repo and implemented a resolver that used the
BookService
that was connected to mongo, instead of the in-memory repository, and then implemented the types for the book and query and hooked it all up in startup.I'll go through the workshop repo and see how it compares to what I did to see if I was on the right track, and start learning about all the other stuff.
Thank you kindly!
Join the slack channel if you have any questions, you get usually an answer real quickly :)
Thanks mnse. That was a big help. I also had the EXACT same thoughts today as I was researching where to find a graphql library for .net 3.1. 2018? Uh, no thanks. Next!
Seems like Hot Chocolate is the only game in town. Hope it works. Whoever came up w/the name Hot Chocolate for a GraphQL .NET library should see a psychiatrist. Immediately. And take a marketing course.
I am working on version 10.4.3 and I am following this document for Subscriptions but might it out of date because IEventMessage, IEventSender is obsoleted, do you have any new instruction for Subscriptions?
hotchocolate.io/docs/code-first-su...
Hey Michael, I'm new to GraphQL hot chocoloate but this is really a good example and an easy tutorial to follow. Thank you!.
Question #1: In your example, you use "code" as a parameter for the LocationQueries.GetLocation(). If I want to use Id or Active, how do we implement this?
Can we do it like GetLocationByCode or GetLocationByActive. Is this even the right approach? I've done it this way. Is this correct?
dev-to-uploads.s3.amazonaws.com/i/...
Question #2: Do you have an example on how we can query or get the data from a Rest API?
i.e. I want to fetch the data from an http rest api and expose it in the Location Query Type.
Great article! I recommend changing your AddDbContext to make the dbcontext with Transient scpe like this:
services
.AddDbContext(options =>
options.UseSqlServer(MyDbContext.DbConnectionString), ServiceLifetime.Transient);
With GraphQL, many queries could happen simultaneously and you will find that queries in one dbcontext cant be run at the same time.
I'm still looking for some resource on how to approach relationships in entity. Last time I asked they said it was a WIP :(
That is what pascal actually posted up there:
public class Query {
[UsePaging]
[UseSelection] // <--- creates the projections on the database
[UseSorting]
[UseFiltering]
public IQueryable GetJedis([Service]DBContext ctx)
=> ctx.Jedis.AsQueryable()
}
You put our new selections middleware on the resolver and then basically the whole subtree is selectable in one go.
Try out our preview for 10.4
You only need to declare that on the root resolver and hc will allow full selection of the whole tree.