SlideShare uma empresa Scribd logo
1 de 12
GraphQL- Best
practices
wednesday.is
Presented by:Anurag Rathod
2
Content
What we’ll be covering
What is GraphQL
Why we need to adhere to best practices
Importance of Schema design
Security and Versioning
Documentation
3
What is GraphQL
The what and the why?
GraphQLis a query language and runtime forAPIs (Application Programming Interfaces)
that was developed by Facebook in 2012 and later open-sourced in 2015. It provides a
more efficient, flexible, and powerful way to interact withAPIs compared to traditional
REST(Representational StateTransfer)APIs.
Instead of having multiple endpoints for different types of data, a GraphQLAPI exposes a
single endpoint where clients can send queries that specify the shape and structure of the
response they expect.This query is essentially a JSON object describing the data
requirements.
4
REST vs GraphQL
In traditional RESTAPIs, the client typically has to make multiple requests to different
endpoints to gather all the required data.
GraphQLaddresses these issues by allowing the client to specify exactly what data it
needs and in what format.
5
Issues with RESTAPIs
Addressing bottlenecks
In REST, endpoints often return fixed data structures, which can result in clients receiving
more data than needed (over-fetching) or making multiple requests to different endpoints
to gather required data (under-fetching).This leads to increased latency and inefficient use
of network resources.
In RESTAPIs, when changes are made to the data structure or behaviour of an endpoint,
it often requires creating a new version of theAPI to avoid breaking existing clients.This
can lead to maintenance challenges and confusion for bothAPI providers and consumers.
GraphQLsolves this by allowing clients to request only the specific fields they need,
eliminating over-fetching and under-fetching. Clients define their data requirements in
the query, ensuring that they receive precisely the data they expect, without
unnecessary additional information. GraphQLreduces versioning challenges by
introducing a strongly-typed schema.The schema serves as a contract between the
client and the server, defining the types of data that can be queried and the relationships
between them.
6
How to make the most out of GraphQL
What are the different practices that can give you superpowers
Following best practices when working with GraphQLis crucial to ensure the efficiency,
maintainability, and scalability of yourAPI and the applications that interact with it. Here are
some reasons why adhering to best practices is important
• Efficiency
• Data Security
• Scalability
• Developer Collaboration
• Future-proofing
7
Importance of Schema Design
How you should design your schema and why doing it right matters
The schema acts as a contract between the client and the server, defining the types of
data that can be queried, the relationships between them, and the operations that can
be performed. It matters because a well-designed schema ensures clarity, efficiency,
and flexibility in yourAPI.
• Use clear and meaningful type names
• Hierarchical Structure
• Use Interfaces and Union for Polymorphic types
• Use @deprecated directive
• Add support for pagination and filtering
8
Importance of meaningful errors
Why you should care about the error messages as much as the returned data
Meaningful error messages provide clear insights into what went wrong, making it
easier for developers to identify and fix issues in their queries or mutations.
• PromotesAdoption
• Encourages Proper Usage
• Supports Client-Side Development
• Saves NetworkTraffic
9
Some other best practices
What can help you make the most of your GraphQLAPIs
Caching and Performance
Utilize caching mechanisms likeApollo Client's cache or Dataloader caching.These
mechanisms store frequently accessed data in memory, reducing the need for repeated
database queries. Implement server-side caching with tools like Redis for queries that
are common and resource-intensive. Minimize the data returned in each request to
reduce payload size and improve performance, especially for mobile clients.
Security
Protect sensitive data with authentication and authorization mechanisms. Ensure that
only authorized users can access certain queries and mutations. Implement field-level
permissions to restrict access to specific fields based on the user's role or permissions.
Be cautious with the introspection query, which can expose your schema structure;
disable it in production to mitigate potential security risks.
10
Some other best practices
What can help you make the most of your GraphQLAPIs
Versioning
Plan for schema changes and versioning to prevent breaking changes for clients.
GraphQLschemas can evolve over time, and it's important to provide backward
compatibility for existing clients. Use features like unions and interfaces to maintain
compatibility even as you introduce new types. Provide clear deprecation notices for
fields or types that will be removed in the future.
Tooling
Leverage tools likeApollo Server, GraphQLYoga, or Express GraphQLfor setting up
your GraphQLserver.These tools simplify server creation and provide useful features
out of the box. Use GraphQLtools like GraphiQLor GraphQLPlayground for query
exploration and debugging. Incorporate linting and code generators to maintain code
quality, consistency, and to automate repetitive tasks.
11
Key Takeaways
What we learned
What is GraphQL
Bottlenecks with RESTAPIs
Best practices when using GraphQL
Thank you
for your time
wednesday.is

Mais conteúdo relacionado

Semelhante a What is GraphQL: Best Practices

Introduction to Testing GraphQL Presentation
Introduction to Testing GraphQL PresentationIntroduction to Testing GraphQL Presentation
Introduction to Testing GraphQL PresentationKnoldus Inc.
 
Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)Knoldus Inc.
 
Introduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxIntroduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxKnoldus Inc.
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservicesMohammed Shaban
 
Thiruvananthapuram Anypoint DataGraph 2 Sept.pdf
Thiruvananthapuram Anypoint DataGraph 2 Sept.pdfThiruvananthapuram Anypoint DataGraph 2 Sept.pdf
Thiruvananthapuram Anypoint DataGraph 2 Sept.pdfVikalp Bhalia
 
Whither the Hadoop Developer Experience, June Hadoop Meetup, Nitin Motgi
Whither the Hadoop Developer Experience, June Hadoop Meetup, Nitin MotgiWhither the Hadoop Developer Experience, June Hadoop Meetup, Nitin Motgi
Whither the Hadoop Developer Experience, June Hadoop Meetup, Nitin MotgiFelicia Haggarty
 
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 togetherSashko Stubailo
 
Neo4j GraphDay Seattle- Sept19- in the enterprise
Neo4j GraphDay Seattle- Sept19-  in the enterpriseNeo4j GraphDay Seattle- Sept19-  in the enterprise
Neo4j GraphDay Seattle- Sept19- in the enterpriseNeo4j
 
Democratization of Data @Indix
Democratization of Data @IndixDemocratization of Data @Indix
Democratization of Data @IndixManoj Mahalingam
 
apidays LIVE Paris - GraphQL meshes by Jens Neuse
apidays LIVE Paris - GraphQL meshes by Jens Neuseapidays LIVE Paris - GraphQL meshes by Jens Neuse
apidays LIVE Paris - GraphQL meshes by Jens Neuseapidays
 
OOW 2012: Integrate Cloud Applications with Oracle SOA Suite
OOW 2012: Integrate Cloud Applications with Oracle SOA SuiteOOW 2012: Integrate Cloud Applications with Oracle SOA Suite
OOW 2012: Integrate Cloud Applications with Oracle SOA SuiteRajesh Raheja
 
Data Services and the Modern Data Ecosystem (ASEAN)
Data Services and the Modern Data Ecosystem (ASEAN)Data Services and the Modern Data Ecosystem (ASEAN)
Data Services and the Modern Data Ecosystem (ASEAN)Denodo
 
The 15 ITIL Steps to DBaaS in the Cloud
The 15 ITIL Steps to DBaaS in the CloudThe 15 ITIL Steps to DBaaS in the Cloud
The 15 ITIL Steps to DBaaS in the CloudJoaquin Marques
 
Confluent Partner Tech Talk with Reply
Confluent Partner Tech Talk with ReplyConfluent Partner Tech Talk with Reply
Confluent Partner Tech Talk with Replyconfluent
 
Building an Android app with GraphQL Unleashing the Power of Modern Mobile De...
Building an Android app with GraphQL Unleashing the Power of Modern Mobile De...Building an Android app with GraphQL Unleashing the Power of Modern Mobile De...
Building an Android app with GraphQL Unleashing the Power of Modern Mobile De...ssuser5583681
 
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 performanceRed Hat
 
Roadmap for Enterprise Graph Strategy
Roadmap for Enterprise Graph StrategyRoadmap for Enterprise Graph Strategy
Roadmap for Enterprise Graph StrategyNeo4j
 
Your Roadmap for An Enterprise Graph Strategy
Your Roadmap for An Enterprise Graph StrategyYour Roadmap for An Enterprise Graph Strategy
Your Roadmap for An Enterprise Graph StrategyNeo4j
 

Semelhante a What is GraphQL: Best Practices (20)

codersera_com (1).pdf
codersera_com (1).pdfcodersera_com (1).pdf
codersera_com (1).pdf
 
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)
 
Introduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxIntroduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptx
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
 
Thiruvananthapuram Anypoint DataGraph 2 Sept.pdf
Thiruvananthapuram Anypoint DataGraph 2 Sept.pdfThiruvananthapuram Anypoint DataGraph 2 Sept.pdf
Thiruvananthapuram Anypoint DataGraph 2 Sept.pdf
 
Whither the Hadoop Developer Experience, June Hadoop Meetup, Nitin Motgi
Whither the Hadoop Developer Experience, June Hadoop Meetup, Nitin MotgiWhither the Hadoop Developer Experience, June Hadoop Meetup, Nitin Motgi
Whither the Hadoop Developer Experience, June Hadoop Meetup, Nitin Motgi
 
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
 
Neo4j GraphDay Seattle- Sept19- in the enterprise
Neo4j GraphDay Seattle- Sept19-  in the enterpriseNeo4j GraphDay Seattle- Sept19-  in the enterprise
Neo4j GraphDay Seattle- Sept19- in the enterprise
 
Democratization of Data @Indix
Democratization of Data @IndixDemocratization of Data @Indix
Democratization of Data @Indix
 
apidays LIVE Paris - GraphQL meshes by Jens Neuse
apidays LIVE Paris - GraphQL meshes by Jens Neuseapidays LIVE Paris - GraphQL meshes by Jens Neuse
apidays LIVE Paris - GraphQL meshes by Jens Neuse
 
OOW 2012: Integrate Cloud Applications with Oracle SOA Suite
OOW 2012: Integrate Cloud Applications with Oracle SOA SuiteOOW 2012: Integrate Cloud Applications with Oracle SOA Suite
OOW 2012: Integrate Cloud Applications with Oracle SOA Suite
 
Data Services and the Modern Data Ecosystem (ASEAN)
Data Services and the Modern Data Ecosystem (ASEAN)Data Services and the Modern Data Ecosystem (ASEAN)
Data Services and the Modern Data Ecosystem (ASEAN)
 
About CDAP
About CDAPAbout CDAP
About CDAP
 
The 15 ITIL Steps to DBaaS in the Cloud
The 15 ITIL Steps to DBaaS in the CloudThe 15 ITIL Steps to DBaaS in the Cloud
The 15 ITIL Steps to DBaaS in the Cloud
 
Confluent Partner Tech Talk with Reply
Confluent Partner Tech Talk with ReplyConfluent Partner Tech Talk with Reply
Confluent Partner Tech Talk with Reply
 
Building an Android app with GraphQL Unleashing the Power of Modern Mobile De...
Building an Android app with GraphQL Unleashing the Power of Modern Mobile De...Building an Android app with GraphQL Unleashing the Power of Modern Mobile De...
Building an Android app with GraphQL Unleashing the Power of Modern Mobile De...
 
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
 
Roadmap for Enterprise Graph Strategy
Roadmap for Enterprise Graph StrategyRoadmap for Enterprise Graph Strategy
Roadmap for Enterprise Graph Strategy
 
Your Roadmap for An Enterprise Graph Strategy
Your Roadmap for An Enterprise Graph StrategyYour Roadmap for An Enterprise Graph Strategy
Your Roadmap for An Enterprise Graph Strategy
 

Mais de Wednesday Solutions

Master iOS Performance Optimization with Instruments
Master iOS Performance Optimization with InstrumentsMaster iOS Performance Optimization with Instruments
Master iOS Performance Optimization with InstrumentsWednesday Solutions
 
What is React Concurrent Mode: A Walkthrough
What is React Concurrent Mode: A WalkthroughWhat is React Concurrent Mode: A Walkthrough
What is React Concurrent Mode: A WalkthroughWednesday Solutions
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorWednesday Solutions
 
Create Basic 3D Scenes Using Three.js
Create Basic 3D Scenes Using Three.jsCreate Basic 3D Scenes Using Three.js
Create Basic 3D Scenes Using Three.jsWednesday Solutions
 
What is Temporal: Workflow & Cluster
What is Temporal: Workflow & ClusterWhat is Temporal: Workflow & Cluster
What is Temporal: Workflow & ClusterWednesday Solutions
 

Mais de Wednesday Solutions (8)

Error Handling in Express
Error Handling in ExpressError Handling in Express
Error Handling in Express
 
Master iOS Performance Optimization with Instruments
Master iOS Performance Optimization with InstrumentsMaster iOS Performance Optimization with Instruments
Master iOS Performance Optimization with Instruments
 
What is React Concurrent Mode: A Walkthrough
What is React Concurrent Mode: A WalkthroughWhat is React Concurrent Mode: A Walkthrough
What is React Concurrent Mode: A Walkthrough
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage Collector
 
Create Basic 3D Scenes Using Three.js
Create Basic 3D Scenes Using Three.jsCreate Basic 3D Scenes Using Three.js
Create Basic 3D Scenes Using Three.js
 
A Guide to Figma for Developers
A Guide to Figma for DevelopersA Guide to Figma for Developers
A Guide to Figma for Developers
 
What is Temporal: Workflow & Cluster
What is Temporal: Workflow & ClusterWhat is Temporal: Workflow & Cluster
What is Temporal: Workflow & Cluster
 
Vector Embedding using AI
Vector Embedding using AIVector Embedding using AI
Vector Embedding using AI
 

Último

Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfAshrafRagab14
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfJNTUA
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualBalamuruganV28
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxMustafa Ahmed
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesRashidFaridChishti
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxCHAIRMAN M
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfssuser5c9d4b1
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2T.D. Shashikala
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Nitin Sonavane
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docxrahulmanepalli02
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfJNTUA
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1T.D. Shashikala
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...IJECEIAES
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdfAlexander Litvinenko
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksIJECEIAES
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalSwarnaSLcse
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxRashidFaridChishti
 

Último (20)

Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdf
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdf
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docx
 

What is GraphQL: Best Practices

  • 2. 2 Content What we’ll be covering What is GraphQL Why we need to adhere to best practices Importance of Schema design Security and Versioning Documentation
  • 3. 3 What is GraphQL The what and the why? GraphQLis a query language and runtime forAPIs (Application Programming Interfaces) that was developed by Facebook in 2012 and later open-sourced in 2015. It provides a more efficient, flexible, and powerful way to interact withAPIs compared to traditional REST(Representational StateTransfer)APIs. Instead of having multiple endpoints for different types of data, a GraphQLAPI exposes a single endpoint where clients can send queries that specify the shape and structure of the response they expect.This query is essentially a JSON object describing the data requirements.
  • 4. 4 REST vs GraphQL In traditional RESTAPIs, the client typically has to make multiple requests to different endpoints to gather all the required data. GraphQLaddresses these issues by allowing the client to specify exactly what data it needs and in what format.
  • 5. 5 Issues with RESTAPIs Addressing bottlenecks In REST, endpoints often return fixed data structures, which can result in clients receiving more data than needed (over-fetching) or making multiple requests to different endpoints to gather required data (under-fetching).This leads to increased latency and inefficient use of network resources. In RESTAPIs, when changes are made to the data structure or behaviour of an endpoint, it often requires creating a new version of theAPI to avoid breaking existing clients.This can lead to maintenance challenges and confusion for bothAPI providers and consumers. GraphQLsolves this by allowing clients to request only the specific fields they need, eliminating over-fetching and under-fetching. Clients define their data requirements in the query, ensuring that they receive precisely the data they expect, without unnecessary additional information. GraphQLreduces versioning challenges by introducing a strongly-typed schema.The schema serves as a contract between the client and the server, defining the types of data that can be queried and the relationships between them.
  • 6. 6 How to make the most out of GraphQL What are the different practices that can give you superpowers Following best practices when working with GraphQLis crucial to ensure the efficiency, maintainability, and scalability of yourAPI and the applications that interact with it. Here are some reasons why adhering to best practices is important • Efficiency • Data Security • Scalability • Developer Collaboration • Future-proofing
  • 7. 7 Importance of Schema Design How you should design your schema and why doing it right matters The schema acts as a contract between the client and the server, defining the types of data that can be queried, the relationships between them, and the operations that can be performed. It matters because a well-designed schema ensures clarity, efficiency, and flexibility in yourAPI. • Use clear and meaningful type names • Hierarchical Structure • Use Interfaces and Union for Polymorphic types • Use @deprecated directive • Add support for pagination and filtering
  • 8. 8 Importance of meaningful errors Why you should care about the error messages as much as the returned data Meaningful error messages provide clear insights into what went wrong, making it easier for developers to identify and fix issues in their queries or mutations. • PromotesAdoption • Encourages Proper Usage • Supports Client-Side Development • Saves NetworkTraffic
  • 9. 9 Some other best practices What can help you make the most of your GraphQLAPIs Caching and Performance Utilize caching mechanisms likeApollo Client's cache or Dataloader caching.These mechanisms store frequently accessed data in memory, reducing the need for repeated database queries. Implement server-side caching with tools like Redis for queries that are common and resource-intensive. Minimize the data returned in each request to reduce payload size and improve performance, especially for mobile clients. Security Protect sensitive data with authentication and authorization mechanisms. Ensure that only authorized users can access certain queries and mutations. Implement field-level permissions to restrict access to specific fields based on the user's role or permissions. Be cautious with the introspection query, which can expose your schema structure; disable it in production to mitigate potential security risks.
  • 10. 10 Some other best practices What can help you make the most of your GraphQLAPIs Versioning Plan for schema changes and versioning to prevent breaking changes for clients. GraphQLschemas can evolve over time, and it's important to provide backward compatibility for existing clients. Use features like unions and interfaces to maintain compatibility even as you introduce new types. Provide clear deprecation notices for fields or types that will be removed in the future. Tooling Leverage tools likeApollo Server, GraphQLYoga, or Express GraphQLfor setting up your GraphQLserver.These tools simplify server creation and provide useful features out of the box. Use GraphQLtools like GraphiQLor GraphQLPlayground for query exploration and debugging. Incorporate linting and code generators to maintain code quality, consistency, and to automate repetitive tasks.
  • 11. 11 Key Takeaways What we learned What is GraphQL Bottlenecks with RESTAPIs Best practices when using GraphQL
  • 12. Thank you for your time wednesday.is