DEV Community

loading...

Discussion on: Entity Framework DotNet Core with GraphQL and SQL Server (using HotChocolate)

Collapse
michaelstaib profile image
Michael Staib

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.

Collapse
pascalsenn profile image
PascalSenn

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.

public class Query {
     [UsePaging]
     [UseSelection] // <--- creates the projections on the database
     [UseSorting]
     [UseFiltering]
     public IQueryable<Jedi> GetJedis([Service]DBContext ctx) 
       => ctx.Jedis.AsQueryable()

}

When you now execute this query

{
  jedis(where: {name: "Han"}, order_by:{side:DESC}) { name side }
}

This SQL statement is executed:

SELECT [p].[Name],[p].[Side]
FROM [Jedis] AS [p]
WHERE [p].[Name] ="Han"
ORDER BY [p].[Side] DESC
Thread Thread
toddfulton profile image
Todd-Fulton

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!

Thread Thread
pascalsenn profile image
PascalSenn

Join the slack channel if you have any questions, you get usually an answer real quickly :)

Forem Open with the Forem app