An example of implementing a GraphQL Server in the standard.NET framework
Most GraphQL solutions showing usage of GraphQL on the client side. The ones on the server side are either using APOLLO servers with javascript frameworks or .NET Core. The project we wanted to use GraphQL in was using standard .NET framework with ADO.NET . We played with various samples and demos and then build out a simple demo app showcasing the use of GraphQL and graphiql with .NET framework. In some senses this is the simplest and most vanilla GraphQL server repo you will see which is what we were looking for.
- GraphQL server with full .NET 4.5 framework
- Code First Entity Framework 6.0
- Graphiql
- Windows Machine
- Visual Studio
- Visual Studio Code
- Parameterized Queries
- Nested Queries
- Parameterized Mutations
- Does NOT use Dependency Injection
- https://fullstackmark.com/post/17/building-a-graphql-api-with-aspnet-core-2-and-entity-framework-core ( This is for .NET Core but good to get started)
- https://github.com/JacekKosciesza/StarWars ( Again this is for .NET Core)
- https://graphql-dotnet.github.io/ (GraphQL for .NET repo)
- https://github.com/graphql-dotnet/examples/tree/master/src/AspNetWebApi (Pretty much the only .NET framework example we got and most useful!)
The api exposes a simple Person-Hobby system with the following relationship
The Schema allows for the following operations
-
Query Person by ID ( allows nested queries to get person’s hobbies)
-
Query Hobby by ID ( Including get count of people interested in that hobby)
The nuget at https://www.nuget.org/packages/graphiql/ is made for .NET Core and does not work with the standard .NET framework. We tried using the Graphiql repo at https://github.com/graphql/graphiql directly but it had some issues building on a windows machine.(graphql/graphiql#318) .
We finally used the fork at https://github.com/mattferrin/graphiql to get this working on a Windows Machine.
- Clone repo from https://github.com/mattferrin/graphiql
- Install Yarn from https://yarnpkg.com/en/docs/install#windows-stable
- Open Command Prompt and Navigate to main project
- Use “Yarn Install” to install all dependencies
- “npm run build” on the parent directory
- Navigate to Example directory
- “npm install”
- Update function graphQLFetcher in example/index.html to hit the HobbyAPIServer
9. “npm start” 10. Navigate to localhost:8080 and explore the schema
What is shown here is simply how to connect the various pieces. However if someone needs specific steps please ping me at anshulee@cennest.com and i'll write up a tutorial