You are previewing Learning GraphQL and Relay.
O'Reilly logo
Learning GraphQL and Relay

Book Description

Build data-driven React applications with ease using GraphQL and Relay

About This Book

  • Take your React applications to the next level with GraphQl and Relay

  • Explore the concepts of data fetching, data handling, and more

  • Learn to deploy your applications, which are compliant with GraphQl and Relay

  • Who This Book Is For

    This book is perfect for those who have no prior experience or familiarity with Relay and/or GraphQL. You should be comfortable writing NodeJS applications on a MongoDB database with REST APIs as well as applications on the client-side using React and ES2015.

    What You Will Learn

  • Understand what problem GraphQL solves and how it differs from traditional REST architectures

  • Create a GraphQL server

  • Develop modular and maintainable GraphQL code

  • Grasp how to define GraphQL mutations

  • Comprehend how to define GraphQL queries

  • Modify a GraphQL server to be Relay-compliant

  • Develop a Relay client-side application with ReactJS that consumes a GraphQL endpoint

  • In Detail

    There’s a new choice for implementing APIs – the open source and Facebook-created GraphQL specification. Designed to solve many of the issues of working with REST, GraphQL comes alongside RelayJS, a React library for querying a server that implements the GraphQL specification. This book takes you quickly and simply through the skills you need to be able to build production ready applications with both GraphQL and RelayJS.

    Beginning with a solid foundation in the GraphQl specification, this book swiftly moves to how a data layer can be implemented for your web application using Relay. Get to grips with GraphQL and Relay concepts creating data containers, data masking, and more as your progress towards building a production-ready application.

    Style and approach

    This book serves as the answer to every question related to data-driven app development with React. Using real-world examples, this book will show you how to enhance the functionality of React apps by introducing efficient data handling features within the app.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Learning GraphQL and Relay
      1. Learning GraphQL and Relay
      2. Credits
      3. About the Author
      4. Acknowledgments
      5. About the Reviewers
      6. www.PacktPub.com
        1. Why subscribe?
        2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book 
          3. Errata
          4. Piracy
          5. Questions
      8. 1. An Introduction to GraphQL and Relay
        1. What is GraphQL?
        2. What is Relay?
        3. Why GraphQL?
          1. RESTful APIs versus GraphQL APIs
        4. Why Relay?
          1. Understanding Relay's core principles
            1. Storage and caching
            2. Object identification
            3. The connection model
        5. Setting up a simple GraphQL server
          1. Installing Node.js
          2. Defining the schema
          3. Using the schema
            1. Rolling the dice
            2. Using field arguments
          4. Setting up MongoDB
          5. Setting up an HTTP interface
          6. The GraphiQL editor
        6. Summary
      9. 2. The Query Language
        1. Documents and operations
        2. Fields
        3. Variables
        4. Directives
        5. Aliases
        6. Fragments
        7. Mutations
        8. Summary
      10. 3. The GraphQL Schema
        1. The schema object
        2. Introspection
        3. The type system
          1. Scalars and object types
          2. Interfaces and unions
          3. Type modifiers
          4. Enums
        4. The resolve function
          1. First argument – source
          2. Second argument – args
          3. Third argument – context
          4. Fourth argument – info
          5. Resolving with promises
        5. Validation
        6. Versioning
        7. Summary
      11. 4. Configuring React Applications to Use Relay
        1. The example GraphQL schema
        2. The quotes library
        3. Setting up Webpack
        4. Using GraphQL without Relay in React applications
        5. Relay containers
        6. Summary
      12. 5. Making GraphQL Queries Relay-Compliant
        1. Transforming GraphQL queries for Relay
        2. Root-level field for the quotes library
        3. First query operation with Relay
        4. Relay's connection model
        5. Summary
      13. 6. Relay Variables and Object Identification
        1. Implementing search
          1. Adding a search feature to the GraphQL API
          2. Implementing the search feature in Relay
            1. Adding a search form component
            2. Using Relay variables
        2. Implementing likes
          1. Relay's global ID
          2. The Node interface
        3. Summary
      14. 7. Relay Mutations
        1. Relay-compliant GraphQL mutations
        2. Relay.Mutation
        3. Optimistic updates
        4. Summary
      15. 8. Deploying to the Cloud
        1. Preparing for deployment
          1. Creating a GitHub repository
          2. Deploying locally
        2. Deploying on EC2
          1. Installing MongoDB
          2. Running the Node.js server
        3. Deploying on Heroku
          1. Cloud-hosted MongoDB
        4. Summary