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

Preparing our GraphQL Layer

Before we start creating components and styling them, we need to create a good communication layer between our backend and frontend. We will write selectors and prepare the client to communicate with the backend in two states – authorized and not authorized.

Writing selectors

We will begin by creating a graphql folder inside our project’s /src folder and adding a selectors.ts file. Inside this file, we will write selectors for our GraphQL queries, and the types that will be used to type the application state.

First, what is a selector? A selector is Zeus’ version of a GraphQL fragment. We discussed fragments in Chapter 1, so go back for a recap.

Second, why do we need selectors? They can be used to create TypeScript types needed by React state and help persist type-safe data there.

The primary selector utilized for the queries on our system’s Home page is based on the QuestionsResponse type derived from the GraphQL...

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 $19.99/month. Cancel anytime