An example of GraphQL, React, communicating via Apollo Client, and using GraphQL Code Generator for type safe react apollo data fetching. We have divided the components into two folders, Cards
and Modules
. Cards are simple UI representations of a specific model (i.e. Character, or Episode). A Module is a horizontal scrolling list, consisting of multiple cards. Each module is responsible for their own data fetching, error handling, and loading state.
- Define a GraphQL Fragment
- Run
yarn generate
, the named fragment above can be used to type the props of your new component. - Define your React component with the types generated above.
- Define a GraphQL Query or Mutation
- Run
yarn generate
- this will result in a hook that will be used to fetch (or mutate) the data - Define your React component with the hook to perform the request.
- install dependencies
yarn
- generate code:
yarn generate
- start server:
yarn start