Summary
In this chapter, we started by learning the GraphQL syntax for queries and mutations. A great feature of GraphQL is the ability to request and receive only the required objects and fields. This can really help the performance of our apps.
We used React Query and fetch
to interact with a GraphQL API. This is very similar to interacting with a REST API, but the HTTP method needs to be POST
, and the query or mutation needs to be placed in the request body. A new feature we learned about in React Query is the ability to trigger queries when the user interacts with the app using the enabled
option.
We refactored the app to use Apollo Client, which is a specialized GraphQL client. It is very similar to React Query in that it has useQuery
and useMutation
hooks and a provider component. One advantage over React Query is that Apollo Client interacts directly with the GraphQL API, which means we write less code.
In the next chapter, we will cover patterns that help us build...