SlideShare a Scribd company logo
1 of 35
Download to read offline
GraphQL
with .Net Core
Presenting by: Mudassir Qureshi
Demonstration by: Seemab Ashfaque Shaik
Webinar Session | GraphQL
Agenda
1. Intorduction to GraphQL with .Net Core
2. Why is GraphQL?
3. GraphQL Core Concepts
4. GraphQL vs REST
5. Creating a GraphQL Schema
6. Queries and Mutation in GraphQL
7. GraphQL in Microservices Architecture
8. Summary
9. Case study or Demonstration
10. Q&A
GraphQL with .Net Core
1.Introduction to GraphQL with .NET Core
It was created by Facebook back in 2012 for use in their mobile applications, but it was made open
source in 2015 and has grown in popularity ever since.
GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing
data. GraphQL provides a complete and understandable description of the data in your API, gives
clients the power to ask for exactly what they need and nothing more, makes it easier to evolve
APIs over time, and enables powerful developer tools.
illustration
REST API
GraphQL is a query language for APIs, it gives power to the client to control the response on what
they need instead of the server deciding what to respond.
It sits between clients and backend services and fulfills the query for clients. GraphQL can
aggregate multiple resource requests into a single query.
1:1 What is GraphQL
1. Declarative Data fetching.
2. Single Endpoints.
3. Strong Typing Systems.
4. Real-Time Data with Subscriptions.
5. Batching and Efficiency.
6. Evolutionary API.
7. Documentation and Introspection.
8. Wide Adoption.
1:2 Flexibility and efficiency in data retrieval
Why is GraphQL ?
02
1. Precision in Data Retrieval: GraphQLAddresses over-fetching.
2. Elimination of under-fetching: GraphQL tackles under-fetching.
3. Single Request for Multiple Resources:Efficient Network Usage.
4. Reduced Latency: Optimized Data Transfer.
5. Dynamic Responses: Adaptabilityto UI Requirements.
6. Improved Front-End Development: Empowerment of Front-End Developers.
7. Real-time Capabilities: Real-time Data Updates.
8. Schema Evolution: GracefulAPI Evolution.
Why GraphQL ?
In summary, GraphQL addresses the issues of over-fetching and under-fetching present
in REST, offers a streamlined approach with single requests for multiple resources, and
enhances overall efficiency in data transfer, making it a compelling choice for modern
API development.
2.1 Over and Under-fetching issue in REST
▪ Over-fetching is fetching too much data, meaning there is data in the response you don't use
and fetching less variables that are required at this point.
▪ Under-fetching is not having enough data with a call to an endpoint, forcing you to call a second
endpoint,
Example
2.2 Single request for multiple resources in GraphQL
One of the key features of GraphQL that contributes to its efficiency is the ability to request multiple
resources in a single query. This is in contrast to traditional REST APIs, where multiple endpoints
might need to be accessed to retrieve related data. In GraphQL, you can compose a single query to
obtain all the information you need.
Benefits:
1.Reduced Round Trips
2.Minimized Latency
3.Optimized Data Transfer
4.Simplified Client Logic
5.Hierarchical Structure
In summary, the ability to request multiple resources in a single query is a powerful feature of
GraphQL that streamlines data retrieval and contributes to more efficient communication between
clients and servers.
GraphQL Core Concepts
Queries, Mutations and Subscriptions
03
GraphQL has several core concepts that form the foundation of the query language and its
execution.
The Schema Definition Language (SDL): GraphQL has its own type system that’s used to define
the schema of an API. The syntax for writing schemas is called Schema Definition Language (SDL).
Here is an example of how we can use the SDL to define a simple type called Person:
1
3
2
Note that we just created a one-to-
many-relationship between Person
and Post since the posts field on
Person is actually an array of posts.
3.1 Fetching Data with Queries
When working with REST APIs, data is loaded from specific endpoints. Each endpoint has a clearly
defined structure of the information that it returns. This means that the data requirements of a client are
effectively encoded in the URLthat it connects to.
The approach that’s taken in GraphQL is radically different. Instead of having multiple endpoints that
return fixed data structures, GraphQL APIs typically only expose a single endpoint. This works because
the structure of the data that’s returned is not fixed. Instead, it’s completely flexible and lets the client
decide what data is actually needed.
Let’s take a look at an example query that a client could send to a server:
The allPersons field in this query is called the root field of the query. Everything that follows the root field,
is called the payload of the query. The only field that’s specified in this query’s payload is name.
This query would return a list of all persons
currently stored in the database.
3.2 Queries with Arguments
In GraphQL, each field can have zero or more arguments if that’s specified in the schema. For
example, the allPersons field could have a last parameter to only return up to a specific number of
persons. Here’s what a corresponding query would look like:
Ex.1
Ex.2
{
"allPersons" : [
{ "name" : "Sarah" },
{ "name" : "Alice" }
]
}
{
allPersons(id: "123")
{
name
age
}
}
{
"allPersons" : {
"name" : "Johnny",
"age: 29
}
}
output
output
3.3 Writing Data with Mutations
Next to requesting information from a server, the majority of applications also need some way of
making changes to the data that’s currently stored in the backend. With GraphQL, these changes
are made using so-called mutations. There generally are three kinds of mutations:
• creating new data
• updating existing data
• deleting existing data
"createPerson": {
"name": "Bob",
"age": 36,
}
(The server response forthe mutation
would look as follows)
4. GraphQL vs REST API
Here is the important difference between GraphQL and REST API.
GraphQL REST
GraphQL is an application layer server-side technology
which is developed by Facebook for executing queries
with existing data.
REST is a software architectural style that defines a set of
constraints for creating Web services.
It follows client-driven architecture. It follows server-driven architecture.
GraphQL can be organized in terms of a schema. REST can be arranged in terms of endpoints.
GraphQL is a growing community. REST is a large community.
The development speed in GraphQL is fast. The development speed in REST is Slow.
The learning curve in GraphQL is difficult. The learning curve in REST is moderate.
The identity is separated from how you fetch it. The endpoint you call in REST is the identity of an object.
4.1 GraphQL vs REST API
▪ . GraphQL
In GraphQL, the server determines available resources.
Rest
The shape and size of the resource are determined by the
server in REST.
GraphQL provides high consistency across all platforms. It is hard to get consistency across all platforms.
The message format for GraphQL mutations should be a
string.
The message format for REST mutations can be anything.
It is strongly typed. It is weakly typed.
GraphQLAPI endpoints are single. REST API endpoints are multiple.
It uses metadata for
query validation.
It does not have machine-readable metadata cacheable.
Provides consistent and high-quality UX across all
operating systems.
It is difficult to get consistency across all operating
systems.
Partners of GraphQL require API customization.
It offers flexible public API that can easily enable new
applications.
5. Creating a GraphQL Schema
A schema is like a contract between the server and the client. It defines what a GraphQL
API can and can't do, and how clients can request or change data. It's an abstraction
layer that provides flexibility to consumers while hiding backend implementation details.
Type system
{
hero {
name
appearsIn
}
}
{
"data": {
"hero": {
"name": "R2-D2",
"appearsIn": [
"NEWHOPE",
"EMPIRE",
"JEDI"
]
}
}
}
5. 1 Writing a GraphQL Schema
The GraphQL spec defines a language called the Schema Definition Language (SDL) to
write GraphQL schemas.
You use the available types defined by SDL to compose your GraphQL schema. We cover
four of the types in this article:
▪ Object type
▪ Scalar type
▪ Query type
▪ Mutation type
You’ll learn more about these types (and others) in upcoming articles.
It can be challenging to represent types as GraphQL schema, especially with complex
and extensive UIs. However, follow the four steps below to represent your types as a
GraphQL schema like a pro.
5. 2 Writing a GraphQL Schema
Step 1: Represent the nodes as object types:
Step 2: Add the scalar types as fields to the object types:
type BlogPost {
}
typeAuthor {
}
type BlogPost {
title: String!
content: String!}
5. 3 Writing a GraphQL Schema
Similarly, add a property called name of type String to theAuthor object.
Step 3: Represent the relationships
typeAuthor
{ name: String!
type BlogPost {
title: String!
content: String!
// It's required that every blog post has an author
// Hence the exclamation (!) to mark it as required
hasAuthor: Author!}
5. 4 Writing a GraphQL Schema
Similarly, the edge connecting an Author node to its BlogPosts is named hasBlog. Add a
field hasBlog of type BlogPost, inside the Author type to represent this relationship.
The square brackets around [BlogPost] indicates that the hasBlog field is stored as an
array. Because an author can be associated with 0, 1, or more blog posts, so the one-to-
many relationship was indicated by the asterisk (*) in the data graph.
typeAuthor { name: String!
# An author can have more than one blog post
# Hence representing this as an array [BlogPost]
hasBlog: [BlogPost]}
5. 5 Writing a GraphQL Schema
The Last Step: Define queries and mutations:
While object types help you represent the data graph, they don’t help you define the
operations on it. To include the operations on the data graph, you need Query types and
Mutation types. The Query types define the read operations, and the Mutation types
define the write operations on the data graph. They define the type signatures of
operations that are used by your application to read or write data.
type Query {
# Return all blog posts
# Satisfies the data requirement for the first page
getAllBlogs(): [BlogPost] }
type BlogPost { title: String! content: String!
# It's required that every blog post has an author
# Hence the exclamation (!) to mark it as required
hasAuthor: Author! }
type Author { name: String!
# An author can have more than one blog post
# hence representing this as an array [blogpost]
hasBlog: [BlogPost]}
5. 6 Writing a GraphQL Schema
Next, you need an operation to fetch a specific blog post. To enable this operation, you
need to associate a unique ID with every blog post. The ID of a blog post is used to
fetch the blog content for the second application screen.
ID is a scalar type in GraphQL that represents a unique identifier and is added as a field
to the BlogPost and Author object type to uniquely identify eachAuthor and their
BlogPosts.
type BlogPost
{
id: ID!
title: String!
content: String!
hasAuthor: Author!
}
type Author {
id: ID!
name: String!
hasBlog: [BlogPost]
}
5. 7 Writing a GraphQL Schema
Now, you can extend the Query type in the schema by adding a getBlogPost field; this
field can fetch a blog post with its unique ID.
type Query {
# Return all blog posts
# Satisfies the data requirement for the
first page
getAllBlogs(): [BlogPost]
# Returns a single blog post given it's ID.
getBlogPost(id: ID!): BlogPost
}
type Mutation
{
addBlogPost(title: String!, content: String!, authorID: ID!):
BlogPost
}
Similarly, you can add fields to the Mutation type to create
new objects. For example, here is a Mutation field to create
new blog posts:
5. 8 Writing a GraphQL Schema
We have successfully created the GraphQL schema for your simple blog application:
type Query
{
getAllBlogs(): [BlogPost]
getBlogPost(id: ID!): BlogPost
}
type Mutation
{
addBlogPost(title: String!, content: String!,
authorID: ID!): BlogPost!
}
type BlogPost
{ id: ID! title: String! content:
String! hasAuthor: Author!
}
type Author { id: ID! name:
String! hasBlog: [BlogPost]
}
6 Queries and Mutation in GraphQL
Queries: Queries are used to retrieve data from the GraphQL server. They are analogous
to the `GET` method in RESTful APIs.
- Queries define the shape of the data that the client wants to fetch, including the fields
and nested fields.
- Queries are read-only operations and do not modify the data on the server.
- Example query:
query {
users {
id
name
email
}
}
This query requests the `id`, `name`, and `email` fields for all users from the server.
6.1 Queries and Mutation in GraphQL
Mutations: Mutations are used to modify or create data on the GraphQL server. They are
analogous to `POST`, `PUT`, `PATCH`, or `DELETE` methods in RESTful APIs.
- Mutations define operations that modify the data, such as creating, updating, or
deleting objects.
- Mutations can have input parameters to pass data to the server.
- Example mutation:
mutation {
createUser(input: { name: "John Doe", email: "john@example.com" }) {
id
name
email
}
}
This mutation creates a new user with the specified `name` and `email`, and then returns
the `id`, `name`, and `email` of the newly created user.
6.2 Queries and Mutation in GraphQL
Both queries and mutations are executed by sending a GraphQL request to the server
over HTTP or other transport protocols. The server processes the request, executes the
query or mutation, and returns the requested data or confirmation of the mutation.
queries are used for reading data from the server, whilemutations are used
for modifying or creating data on the server in GraphQL.
7. GraphQL in Microservices Architecture
GraphQL in MicroserviceArchitecture:
- Flexible Data Aggregation: In a microservice architecture, different services often
manage distinct subsets of data. GraphQL acts as an efficient data aggregation layer,
allowing clients to retrieve data from multiple services with a single request. This flexibility
reduces chattiness and overhead associated with multiple API calls.
ServiceAutonomy: Each microservice can expose its GraphQL schema, representing
the data it manages. This autonomy enables teams to independently develop, deploy, and
scale their services, while still providing a unified API surface for clients.
Versioning and Evolution: GraphQL's schema-based approach facilitates versioning
and evolution of microservices. Services can evolve their schemas independently, adding
or deprecating fields as needed, without impacting clients consuming their data.
7.1 GraphQL in Microservices Architecture
Efficient Communication: GraphQL's fine-grained control over data fetching enables
clients to request only the data they need, minimizing overfetching and underfetching.
This efficient communication between clients and services improves performance and
reduces network traffic.
Tooling and Ecosystem: GraphQL's growing ecosystem offers tooling and libraries
tailored for microservices, such as schema stitchingfor federated architectures and
performance monitoring tools. These resources simplify development, integration, and
management of GraphQL-based microservices.
GraphQL serves as a powerful middleware layer in microservice architectures, facilitating
efficient data aggregation, service autonomy, versioning, and efficient communication
between clients and services.
8 Summary
In conclusion, GraphQLin .NET Core presents a compelling solution for modern API
development, offering flexibility, efficiency, and a unified approach to data fetching. By
leveraging GraphQL's query language and schema-based approach, developers can
streamline data retrieval, minimize overfetching and underfetching, and empower clients
with precise control over the data they receive. While there may be challenges such as a
learning curve and implementation complexity, the benefits of GraphQL, including
improved performance, reduced network traffic, and enhanced developer productivity,
make it a valuable addition to the .NET Core ecosystem. With its growing popularity and
robust tooling support, GraphQL in .NET Core is poised to shape the future of API
development, enabling teams to build scalable, efficient, and user-centric applications.
Demonstration
Thank you

More Related Content

Similar to GraphQL with .NET Core Microservices.pdf

Similar to GraphQL with .NET Core Microservices.pdf (20)

GraphQL
GraphQLGraphQL
GraphQL
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Boot
 
Modern APIs with GraphQL
Modern APIs with GraphQLModern APIs with GraphQL
Modern APIs with GraphQL
 
GraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database accessGraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database access
 
GraphQL Advanced Concepts A Comprehensive Guide.docx
GraphQL Advanced Concepts A Comprehensive Guide.docxGraphQL Advanced Concepts A Comprehensive Guide.docx
GraphQL Advanced Concepts A Comprehensive Guide.docx
 
What is GraphQL: Best Practices
What is GraphQL: Best PracticesWhat is GraphQL: Best Practices
What is GraphQL: Best Practices
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
codersera_com (1).pdf
codersera_com (1).pdfcodersera_com (1).pdf
codersera_com (1).pdf
 
Graphql for Frontend Developers Simplifying Data Fetching.docx
Graphql for Frontend Developers Simplifying Data Fetching.docxGraphql for Frontend Developers Simplifying Data Fetching.docx
Graphql for Frontend Developers Simplifying Data Fetching.docx
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 
Apollo Server
Apollo ServerApollo Server
Apollo Server
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
CONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQLCONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQL
 
Introduction to Testing GraphQL Presentation
Introduction to Testing GraphQL PresentationIntroduction to Testing GraphQL Presentation
Introduction to Testing GraphQL Presentation
 
Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)
 
GraphQl Introduction
GraphQl IntroductionGraphQl Introduction
GraphQl Introduction
 
REST API Graph API GraphQL GraphiQL Presentation
REST API Graph API  GraphQL GraphiQL Presentation REST API Graph API  GraphQL GraphiQL Presentation
REST API Graph API GraphQL GraphiQL Presentation
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performance
 

More from Knoldus Inc.

More from Knoldus Inc. (20)

Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
 
OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)
 
Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

GraphQL with .NET Core Microservices.pdf

  • 1. GraphQL with .Net Core Presenting by: Mudassir Qureshi Demonstration by: Seemab Ashfaque Shaik Webinar Session | GraphQL
  • 2. Agenda 1. Intorduction to GraphQL with .Net Core 2. Why is GraphQL? 3. GraphQL Core Concepts 4. GraphQL vs REST 5. Creating a GraphQL Schema 6. Queries and Mutation in GraphQL 7. GraphQL in Microservices Architecture 8. Summary 9. Case study or Demonstration 10. Q&A
  • 4. 1.Introduction to GraphQL with .NET Core It was created by Facebook back in 2012 for use in their mobile applications, but it was made open source in 2015 and has grown in popularity ever since. GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. illustration REST API
  • 5. GraphQL is a query language for APIs, it gives power to the client to control the response on what they need instead of the server deciding what to respond. It sits between clients and backend services and fulfills the query for clients. GraphQL can aggregate multiple resource requests into a single query. 1:1 What is GraphQL
  • 6. 1. Declarative Data fetching. 2. Single Endpoints. 3. Strong Typing Systems. 4. Real-Time Data with Subscriptions. 5. Batching and Efficiency. 6. Evolutionary API. 7. Documentation and Introspection. 8. Wide Adoption. 1:2 Flexibility and efficiency in data retrieval
  • 8. 1. Precision in Data Retrieval: GraphQLAddresses over-fetching. 2. Elimination of under-fetching: GraphQL tackles under-fetching. 3. Single Request for Multiple Resources:Efficient Network Usage. 4. Reduced Latency: Optimized Data Transfer. 5. Dynamic Responses: Adaptabilityto UI Requirements. 6. Improved Front-End Development: Empowerment of Front-End Developers. 7. Real-time Capabilities: Real-time Data Updates. 8. Schema Evolution: GracefulAPI Evolution. Why GraphQL ? In summary, GraphQL addresses the issues of over-fetching and under-fetching present in REST, offers a streamlined approach with single requests for multiple resources, and enhances overall efficiency in data transfer, making it a compelling choice for modern API development.
  • 9. 2.1 Over and Under-fetching issue in REST ▪ Over-fetching is fetching too much data, meaning there is data in the response you don't use and fetching less variables that are required at this point. ▪ Under-fetching is not having enough data with a call to an endpoint, forcing you to call a second endpoint,
  • 11. 2.2 Single request for multiple resources in GraphQL One of the key features of GraphQL that contributes to its efficiency is the ability to request multiple resources in a single query. This is in contrast to traditional REST APIs, where multiple endpoints might need to be accessed to retrieve related data. In GraphQL, you can compose a single query to obtain all the information you need. Benefits: 1.Reduced Round Trips 2.Minimized Latency 3.Optimized Data Transfer 4.Simplified Client Logic 5.Hierarchical Structure In summary, the ability to request multiple resources in a single query is a powerful feature of GraphQL that streamlines data retrieval and contributes to more efficient communication between clients and servers.
  • 12. GraphQL Core Concepts Queries, Mutations and Subscriptions 03
  • 13. GraphQL has several core concepts that form the foundation of the query language and its execution. The Schema Definition Language (SDL): GraphQL has its own type system that’s used to define the schema of an API. The syntax for writing schemas is called Schema Definition Language (SDL). Here is an example of how we can use the SDL to define a simple type called Person: 1 3 2 Note that we just created a one-to- many-relationship between Person and Post since the posts field on Person is actually an array of posts.
  • 14. 3.1 Fetching Data with Queries When working with REST APIs, data is loaded from specific endpoints. Each endpoint has a clearly defined structure of the information that it returns. This means that the data requirements of a client are effectively encoded in the URLthat it connects to. The approach that’s taken in GraphQL is radically different. Instead of having multiple endpoints that return fixed data structures, GraphQL APIs typically only expose a single endpoint. This works because the structure of the data that’s returned is not fixed. Instead, it’s completely flexible and lets the client decide what data is actually needed. Let’s take a look at an example query that a client could send to a server: The allPersons field in this query is called the root field of the query. Everything that follows the root field, is called the payload of the query. The only field that’s specified in this query’s payload is name. This query would return a list of all persons currently stored in the database.
  • 15. 3.2 Queries with Arguments In GraphQL, each field can have zero or more arguments if that’s specified in the schema. For example, the allPersons field could have a last parameter to only return up to a specific number of persons. Here’s what a corresponding query would look like: Ex.1 Ex.2 { "allPersons" : [ { "name" : "Sarah" }, { "name" : "Alice" } ] } { allPersons(id: "123") { name age } } { "allPersons" : { "name" : "Johnny", "age: 29 } } output output
  • 16. 3.3 Writing Data with Mutations Next to requesting information from a server, the majority of applications also need some way of making changes to the data that’s currently stored in the backend. With GraphQL, these changes are made using so-called mutations. There generally are three kinds of mutations: • creating new data • updating existing data • deleting existing data "createPerson": { "name": "Bob", "age": 36, } (The server response forthe mutation would look as follows)
  • 17. 4. GraphQL vs REST API Here is the important difference between GraphQL and REST API. GraphQL REST GraphQL is an application layer server-side technology which is developed by Facebook for executing queries with existing data. REST is a software architectural style that defines a set of constraints for creating Web services. It follows client-driven architecture. It follows server-driven architecture. GraphQL can be organized in terms of a schema. REST can be arranged in terms of endpoints. GraphQL is a growing community. REST is a large community. The development speed in GraphQL is fast. The development speed in REST is Slow. The learning curve in GraphQL is difficult. The learning curve in REST is moderate. The identity is separated from how you fetch it. The endpoint you call in REST is the identity of an object.
  • 18. 4.1 GraphQL vs REST API ▪ . GraphQL In GraphQL, the server determines available resources. Rest The shape and size of the resource are determined by the server in REST. GraphQL provides high consistency across all platforms. It is hard to get consistency across all platforms. The message format for GraphQL mutations should be a string. The message format for REST mutations can be anything. It is strongly typed. It is weakly typed. GraphQLAPI endpoints are single. REST API endpoints are multiple. It uses metadata for query validation. It does not have machine-readable metadata cacheable. Provides consistent and high-quality UX across all operating systems. It is difficult to get consistency across all operating systems. Partners of GraphQL require API customization. It offers flexible public API that can easily enable new applications.
  • 19. 5. Creating a GraphQL Schema A schema is like a contract between the server and the client. It defines what a GraphQL API can and can't do, and how clients can request or change data. It's an abstraction layer that provides flexibility to consumers while hiding backend implementation details. Type system { hero { name appearsIn } } { "data": { "hero": { "name": "R2-D2", "appearsIn": [ "NEWHOPE", "EMPIRE", "JEDI" ] } } }
  • 20. 5. 1 Writing a GraphQL Schema The GraphQL spec defines a language called the Schema Definition Language (SDL) to write GraphQL schemas. You use the available types defined by SDL to compose your GraphQL schema. We cover four of the types in this article: ▪ Object type ▪ Scalar type ▪ Query type ▪ Mutation type You’ll learn more about these types (and others) in upcoming articles. It can be challenging to represent types as GraphQL schema, especially with complex and extensive UIs. However, follow the four steps below to represent your types as a GraphQL schema like a pro.
  • 21. 5. 2 Writing a GraphQL Schema Step 1: Represent the nodes as object types: Step 2: Add the scalar types as fields to the object types: type BlogPost { } typeAuthor { } type BlogPost { title: String! content: String!}
  • 22. 5. 3 Writing a GraphQL Schema Similarly, add a property called name of type String to theAuthor object. Step 3: Represent the relationships typeAuthor { name: String! type BlogPost { title: String! content: String! // It's required that every blog post has an author // Hence the exclamation (!) to mark it as required hasAuthor: Author!}
  • 23. 5. 4 Writing a GraphQL Schema Similarly, the edge connecting an Author node to its BlogPosts is named hasBlog. Add a field hasBlog of type BlogPost, inside the Author type to represent this relationship. The square brackets around [BlogPost] indicates that the hasBlog field is stored as an array. Because an author can be associated with 0, 1, or more blog posts, so the one-to- many relationship was indicated by the asterisk (*) in the data graph. typeAuthor { name: String! # An author can have more than one blog post # Hence representing this as an array [BlogPost] hasBlog: [BlogPost]}
  • 24. 5. 5 Writing a GraphQL Schema The Last Step: Define queries and mutations: While object types help you represent the data graph, they don’t help you define the operations on it. To include the operations on the data graph, you need Query types and Mutation types. The Query types define the read operations, and the Mutation types define the write operations on the data graph. They define the type signatures of operations that are used by your application to read or write data. type Query { # Return all blog posts # Satisfies the data requirement for the first page getAllBlogs(): [BlogPost] } type BlogPost { title: String! content: String! # It's required that every blog post has an author # Hence the exclamation (!) to mark it as required hasAuthor: Author! } type Author { name: String! # An author can have more than one blog post # hence representing this as an array [blogpost] hasBlog: [BlogPost]}
  • 25. 5. 6 Writing a GraphQL Schema Next, you need an operation to fetch a specific blog post. To enable this operation, you need to associate a unique ID with every blog post. The ID of a blog post is used to fetch the blog content for the second application screen. ID is a scalar type in GraphQL that represents a unique identifier and is added as a field to the BlogPost and Author object type to uniquely identify eachAuthor and their BlogPosts. type BlogPost { id: ID! title: String! content: String! hasAuthor: Author! } type Author { id: ID! name: String! hasBlog: [BlogPost] }
  • 26. 5. 7 Writing a GraphQL Schema Now, you can extend the Query type in the schema by adding a getBlogPost field; this field can fetch a blog post with its unique ID. type Query { # Return all blog posts # Satisfies the data requirement for the first page getAllBlogs(): [BlogPost] # Returns a single blog post given it's ID. getBlogPost(id: ID!): BlogPost } type Mutation { addBlogPost(title: String!, content: String!, authorID: ID!): BlogPost } Similarly, you can add fields to the Mutation type to create new objects. For example, here is a Mutation field to create new blog posts:
  • 27. 5. 8 Writing a GraphQL Schema We have successfully created the GraphQL schema for your simple blog application: type Query { getAllBlogs(): [BlogPost] getBlogPost(id: ID!): BlogPost } type Mutation { addBlogPost(title: String!, content: String!, authorID: ID!): BlogPost! } type BlogPost { id: ID! title: String! content: String! hasAuthor: Author! } type Author { id: ID! name: String! hasBlog: [BlogPost] }
  • 28. 6 Queries and Mutation in GraphQL Queries: Queries are used to retrieve data from the GraphQL server. They are analogous to the `GET` method in RESTful APIs. - Queries define the shape of the data that the client wants to fetch, including the fields and nested fields. - Queries are read-only operations and do not modify the data on the server. - Example query: query { users { id name email } } This query requests the `id`, `name`, and `email` fields for all users from the server.
  • 29. 6.1 Queries and Mutation in GraphQL Mutations: Mutations are used to modify or create data on the GraphQL server. They are analogous to `POST`, `PUT`, `PATCH`, or `DELETE` methods in RESTful APIs. - Mutations define operations that modify the data, such as creating, updating, or deleting objects. - Mutations can have input parameters to pass data to the server. - Example mutation: mutation { createUser(input: { name: "John Doe", email: "john@example.com" }) { id name email } } This mutation creates a new user with the specified `name` and `email`, and then returns the `id`, `name`, and `email` of the newly created user.
  • 30. 6.2 Queries and Mutation in GraphQL Both queries and mutations are executed by sending a GraphQL request to the server over HTTP or other transport protocols. The server processes the request, executes the query or mutation, and returns the requested data or confirmation of the mutation. queries are used for reading data from the server, whilemutations are used for modifying or creating data on the server in GraphQL.
  • 31. 7. GraphQL in Microservices Architecture GraphQL in MicroserviceArchitecture: - Flexible Data Aggregation: In a microservice architecture, different services often manage distinct subsets of data. GraphQL acts as an efficient data aggregation layer, allowing clients to retrieve data from multiple services with a single request. This flexibility reduces chattiness and overhead associated with multiple API calls. ServiceAutonomy: Each microservice can expose its GraphQL schema, representing the data it manages. This autonomy enables teams to independently develop, deploy, and scale their services, while still providing a unified API surface for clients. Versioning and Evolution: GraphQL's schema-based approach facilitates versioning and evolution of microservices. Services can evolve their schemas independently, adding or deprecating fields as needed, without impacting clients consuming their data.
  • 32. 7.1 GraphQL in Microservices Architecture Efficient Communication: GraphQL's fine-grained control over data fetching enables clients to request only the data they need, minimizing overfetching and underfetching. This efficient communication between clients and services improves performance and reduces network traffic. Tooling and Ecosystem: GraphQL's growing ecosystem offers tooling and libraries tailored for microservices, such as schema stitchingfor federated architectures and performance monitoring tools. These resources simplify development, integration, and management of GraphQL-based microservices. GraphQL serves as a powerful middleware layer in microservice architectures, facilitating efficient data aggregation, service autonomy, versioning, and efficient communication between clients and services.
  • 33. 8 Summary In conclusion, GraphQLin .NET Core presents a compelling solution for modern API development, offering flexibility, efficiency, and a unified approach to data fetching. By leveraging GraphQL's query language and schema-based approach, developers can streamline data retrieval, minimize overfetching and underfetching, and empower clients with precise control over the data they receive. While there may be challenges such as a learning curve and implementation complexity, the benefits of GraphQL, including improved performance, reduced network traffic, and enhanced developer productivity, make it a valuable addition to the .NET Core ecosystem. With its growing popularity and robust tooling support, GraphQL in .NET Core is poised to shape the future of API development, enabling teams to build scalable, efficient, and user-centric applications.