Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Example working with EF Core #67

Closed
jbliss1234 opened this issue Jul 13, 2017 · 3 comments
Closed

Example working with EF Core #67

jbliss1234 opened this issue Jul 13, 2017 · 3 comments

Comments

@jbliss1234
Copy link

Could you please provide an example of using graphql-dotnetcore working with EF Core, for a query and mutation

@mkmarek
Copy link
Owner

mkmarek commented Jul 13, 2017

Hi, sure I can create an example during the upcoming weekend. I'll post a link here afterwards.

@bancroftway
Copy link

+1 for this. Looking forward to the sample.

@mkmarek
Copy link
Owner

mkmarek commented Jul 15, 2017

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:

  • change the connection string at appsettings.json
  • run the dotnet ef database update to populate your database
  • run it with dotnet run or through visual studio

Then if you go to http://localhost:yourport/public/index.html you should see the GraphiQL interface and there you can play around.

Enjoy!
Marek

@mkmarek mkmarek closed this as completed Jul 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants