Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GraphQL Best Practices

You're reading from   GraphQL Best Practices Gain hands-on experience with schema design, security, and error handling

Arrow left icon
Product type Paperback
Published in Oct 2024
Publisher Packt
ISBN-13 9781835467145
Length 422 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Artur Czemiel Artur Czemiel
Author Profile Icon Artur Czemiel
Artur Czemiel
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Part 1 - Why GraphQL?
2. Chapter 1: Unveiling the Holy Grail of Communication – GraphQL FREE CHAPTER 3. Chapter 2: Applying an AI-Friendly Approach to GraphQL 4. Part 2 - Schema-First Design Patterns
5. Chapter 3: Crafting Effective GraphQL Schemas 6. Chapter 4: Building Pipes 7. Part 3 - Exploring Possible Ways to Use GraphQL
8. Chapter 5: Transitioning from REST to GraphQL 9. Chapter 6: Defining GraphQL Transformers 10. Chapter 7: Understanding GraphQL Federation 11. Part 4 - Advanced GraphQL
12. Chapter 8: Executing Schema-First Systems 13. Chapter 9: Working on the Frontend with GraphQL 14. Chapter 10: Keeping Data Secure 15. Chapter 11: Describing Errors in GraphQL 16. Chapter 12: Documenting your Schema 17. Chapter 13: Tackling Schemas with Visualization 18. Part 5 - From an Idea to a Working Project
19. Chapter 14: From an Idea to a Working Project – Backend Development with GraphQL and TypeScript 20. Chapter 15: From an Idea to a Working Project – Frontend Integration with GraphQL and TypeScript 21. Index 22. Other Books You May Enjoy

Understanding the query cost calculation

In DoS attacks, we have many different possibilities of feeding the server with too much data, and we can protect ourselves from all of them by using the query cost calculation method. This requires additional middleware and extra work from us, but it should be worth implementing on bigger APIs.

Query cost calculation in GraphQL involves assigning a numerical value to each field in the schema to determine the overall cost of executing a given query. This allows for resource management and optimization, ensuring that queries do not consume excessive server resources.

Let’s explore another example schema to understand how query cost calculation works. In this schema, we will have Product, which can have Reviews, and each Reviews has a corresponding Author. Here, we’ll assign a cost value to each field based on its complexity and the resources it requires. For simplicity, we’ll use a scale from 1 to 10, where 1 represents...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime