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

Federating schemas in a to-do list service

In this section, we will create a to-do list using GraphQL Federation. We will use the axolotl library, together with its micro-federation starter. To bootstrap the federated project, use the following command:

npx @aexol/axolotl@latest create-federation-yoga federated-backend

This will create the federated-backend folder and install the required dependencies inside it. It also contains a schema for a to-do list with simple user authentication and authorization.

Now, we will examine the content of the repository. We will start with the to-do list, and then move on to the users schema. In the end, we will see how the schemas merge into a supergraph and one gateway for the resolvers.

To-do list

In the to-do list schema – located inside src/todos/schema.graphql – we have the to-do list logic. Let’s take a look at the code:

type Todo {
  _id: String!
  content: String!
  done...
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 AU $24.99/month. Cancel anytime