DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Using Render Log Streams to Log to Papertrail
  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • Chaining API Requests With API Gateway
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally

Trending

  • Using Render Log Streams to Log to Papertrail
  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • Chaining API Requests With API Gateway
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  1. DZone
  2. Data Engineering
  3. Databases
  4. GraphQL Server With .NET Framework (Not .NET Core)

GraphQL Server With .NET Framework (Not .NET Core)

Wondering whether you can set up a GraphQL server implementation using the regular ole .NET Framework? Then read on.

Anshulee Asthana user avatar by
Anshulee Asthana
·
Jul. 27, 18 · Presentation
Like (1)
Save
Tweet
Share
17.31K Views

Join the DZone community and get the full member experience.

Join For Free

in a recent post, we had listed out analyses done and conclusions made when asked by a customer to convert their existing api to graphql. while exploring graphql with .net framework, we realized there is a large gap in examples and demos on using graphql with full scale .net framework and entityframework. we took some time out to create a sample repo and put it out there so that other programmers don’t have to wonder whether its even possible.

the repo is available at https://github.com/anshulee/graphqlhobbyapi

why another graphql repo?

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 used various samples and demos to 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 demo you will see which is what we were looking for.

technology stack

  • graphql server with full .net 4.5 framework
  • code first entity framework 6.0
  • graphiql

development platform

  • windows machine
  • visual studio
  • visual studio code

this example showcases

  1. parameterized queries
  2. nested queries
  3. parameterized mutations
  4. does not use dependency injection

references

  • 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!)

functioning

the api exposes a simple person-hobby system with the following relationship

clip_image002

the schema allows for the following operations:

  1. query person by id (allows nested queries to get person’s hobbies)

queryperson

  1. query hobby by id (including get count of people interested in that hobby)

queryhobby

  1. create new hobby (mutation)

createhobby

using graphiql

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.( https://github.com/graphql/graphiql/issues/318 ) . we finally used the fork at https://github.com/mattferrin/graphiql to get this working on a windows machine.

steps were as under

  1. clone repo from https://github.com/mattferrin/graphiql
  2. install yarn from https://yarnpkg.com/en/docs/install#windows-stable
  3. open command prompt and navigate to main project
  4. use “yarn install” to install all dependencies
  5. “npm run build” on the parent directory
  6. navigate to example directory
  7. “ npm install”
  8. update function graphqlfetcher in example/index.html to hit the hobbyapiserver

clip_image010

9. “ npm start”

10. navigate to localhost:8080

what is shown here is simply how to connect the various pieces. however if someone needs specific steps, please ping us at anshulee@cennest.com and we will write up a tutorial

happy coding!



if you enjoyed this article and want to learn more about graphql, check out this collection of tutorials and articles on all things graphql.

GraphQL Framework Database .NET

Published at DZone with permission of Anshulee Asthana, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Using Render Log Streams to Log to Papertrail
  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • Chaining API Requests With API Gateway
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: