GraphQL
main principle - code on the browser forms a query describing the data wanted and sends it to the API with a HTTP POST request -- all queries are sent to same address.
GraphQL schema
- contract between the server and client
- abstraction layer that provides flexibily to consumers and hide back-end implementation
- defines what API can and can't do; how clients can request or change data
- collection of object types containing fields
- schema describes two types:
- object type containing scalar types - leaves of the graph (concrete data)
- query type - tells what kind of queries can be made to API - direct link between query and returned JSON object
- [GraphQL Benefits]
- [GraphQL Fragment]
- [3 Types of GraphQL Operations]
- [GraphQL Server Approaches]
- [Example of Using Fetch API for GraphQL request]
- [Use GraphQL Variables to Do Queries]
Apollo server
[Using DataLoader with Apollo Server] to solve n + 1 problem
context returns object and give to all resolvers as third parameter
context is the right place to do things which are shared by multiple resolvers i.e. user identification
Apollo Client
Apollo client is a state management library to use GraphQL to interact with remote server. Client enables you to manage local state alongside remotely fetched state. A single API to interact with all of the application's state. 1
- [Apollo Client Working with Cache]
- [Use Update Callback in useMutation to Manage Cache]
- [Subscriptions on Apollo Client]
[React] hooks: