Closed jbliss1234 closed 7 years ago
Hi, sure I can create an example during the upcoming weekend. I'll post a link here afterwards.
+1 for this. Looking forward to the sample.
Created a repo at https://github.com/mkmarek/graphql-dotnetcore-ef-example for now it contains just one query and one mutation but it should still explain one of the possibilities how to use it. I'll add more stuff and some furter explanation during the weekend hopefully. It went to be a little bit more difficult than I initially expected. But it's quite simmilar to a way how we use this library for real projects.
But basically it uses the CQRS pattern which I think works with GraphQL really well. For DB I used MSSQL but you can surely change that to whatever suits you. For the data access layer I picked unit of work pattern using https://github.com/arch/UnitOfWork library.
It also uses the ASP.NET core DI container quite heavily. You can notice that the graphql schema class doesn't really have anything. The flow is inverse. The types themselves are registering into the schema. The reason for that is here Another workaround would be of course possible if It managed those schema types outside the DI container.
I'm running quite old version of .NET core on my current laptop so you might have to upgrade the project.
To run it you need to:
dotnet ef database update
to populate your databasedotnet run
or through visual studioThen if you go to http://localhost:yourport/public/index.html you should see the GraphiQL interface and there you can play around.
Enjoy! Marek
Could you please provide an example of using graphql-dotnetcore working with EF Core, for a query and mutation