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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Why Text2SQL Alone Isn’t Enough: Embracing TAG
  • .NET Aspire: Building Cloud-Native Applications
  • A Comprehensive Guide To Migrating from .NET Framework to .NET Core
  • Instant Integrations With API and Logic Automation

Trending

  • FIPS 140-3: The Security Standard That Protects Our Federal Data
  • Using Python Libraries in Java
  • Measuring the Impact of AI on Software Engineering Productivity
  • Breaking Bottlenecks: Applying the Theory of Constraints to Software Development
  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.

By 
Anshulee Asthana user avatar
Anshulee Asthana
·
Jul. 27, 18 · Presentation
Likes (1)
Comment
Save
Tweet
Share
18.4K 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!


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.

Related

  • Why Text2SQL Alone Isn’t Enough: Embracing TAG
  • .NET Aspire: Building Cloud-Native Applications
  • A Comprehensive Guide To Migrating from .NET Framework to .NET Core
  • Instant Integrations With API and Logic Automation

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!