Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ADDC 2018 - Nicola Zaghini: Introduction to Rea...

ADDC 2018 - Nicola Zaghini: Introduction to React Native and GraphQL for App Development

The objective of the workshop is to provide base understanding of the React Native framework and the React designs principles by building a Native App for iOS and Android platform.

Additionally, the GraphQL query language will be presented and used during the workshop as a strategic companion for frontend development and perfect match for React design.

By the end of the workshop you will be capable of understanding the technologies involved and proactively progress in your learning journey.

More about the talk, authors & slides: https://addconf.com/2018/schedule/introduction-to-react-native-and-graphql-for-app-development/
Read about the conference: https://addconf.com

More Decks by ADDC - App Design & Development Conference

Other Decks in Technology

Transcript

  1. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    React Native 
 & GraphQL - ADDC 2018 Workshop - An introduction to
  2. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Solution Architect & Lead iOS Engineer • Leader of a team of 5 aimed at researching on React Native and GraphQL in early 2018 @ Travelport Digital • Twitter —> @nzaghini • Email —> [email protected] About Me
  3. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Introduction to the Workshop • Warm Up with some code! • Introduction to React • The Movies App • Introduction to GraphQL • Play with Queries • Integrate Apollo Client • Write a Jest test! Agenda
  4. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini A bit on you. bit.ly/ADDC-RN bit.ly/ADDC-GQ The Repos!
  5. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Enable Live Reload • Let’s have a look at the project structure • Install ESlint and Configuration for better experience • Consider using TypeScript for production codebase! Warm Up!
  6. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    Introduction to React The Basics
  7. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • A Library to create Graphical User Interfaces • Renders UI and responds to events mostly • Rendering logic is coupled with other UI logic
 ( handling of events, state changes, data prep for display ) • React separates concerns via the use of Components vs technologies • Components are easily unit testable, as they are unit after all • Immutable by default, re-renders the whole app on every update! What is it ?
  8. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • A React app is a tree of components. React takes the tree, walks through it, and creates a virtual model of the end result. • The virtual model is then translated into a platform dependent representation for actual display. • As the app updates, the process of creating the virtual result happens over and over again. Each time the previous virtual tree is compared (diff-ed) to the next one. • React will find what’s changed, and update as little as it can on the actual display. How does it work ?
  9. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Defines how a Component works and behaves • Handles the tree of Components and make them work together React React Native • Takes the Component’s output and knows how to place it on the screen • Provides many out of the box default components such as images, text … • Runs on Javascript Engine, in a custom Thread, not the Main Thread.
  10. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini Native Code + React Native SDK Javascript Engine (custom thread) Test Device IDE Bundler Scaffold RN App ./ios ./android Bridge
  11. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Elements are the smallest building blocks of a React App • const helloElement = <h1>Hello World!</h1> • const helloElement = <Text>Hello World!</Text> • Elements are immutable! • JSX: a syntax extension to JavaScript (it is a pre- processor only, no runtime or fancy). Elements.
  12. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • A Javascript function. • Accepts arbitrary input parameters called Props • Returns Elements describing what should appear on the Screen. • A React Application is the result of a collection of Components. Components
  13. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Component must act as pure functions with respect to their Props • Not suitable for data fetching or data that might change Functional Components
  14. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Lifecycle methods available! • http://bit.ly/ADDC-LIFE • State is similar to props, but it is private and fully controlled by the component. • Do Not Modify State Directly • State Updates are Merged • (State Updates May Be Asynchronous) • One Way Data Flow (data flows down) • Any state is always owned by some specific component, and any data or UI derived from that state can only affect components “below” them in the tree. Class Components
  15. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Render Function • It should examine this.props and this.state and return React Elements • It should be pure, meaning that it does not modify component state Class Components
  16. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Step 1 —> Break The UI Into A Component Hierarchy!
 Single responsibility principle, that is, a component should ideally only do one thing. • Step 2 —> Build A Static Version in React!
 Static version of your app that renders your data model via components that reuse other components • Step 3 —> Identify The Minimal Representation Of UI State!
 Don’t Repeat Yourself. Compute when possible. Thinking in React!
  17. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Step 4 —> Identify Where Your State Should Live!
 Find a common owner component when needed. • Step 5 —> Add Inverse Data Flow!
 Components should only update their own state, pass callback function as param down the hierarchy Thinking in React!
  18. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Project Structure • Imports / Javascript • Functional Components • Styles Baby Steps
  19. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini The App • List Component • Item Component
  20. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini The App Little hint const MovieItem = ( ??? ) => {
 …
 <???>
 <???/>
 <???/>
 </???>
 …
 };
  21. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    Introduction to GraphQL The Basics
  22. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini What is it ? https://graphql.org A query language for your API
  23. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • A Data Query Language for your API and a Runtime for fulfilling queries with existing data • Powerful type system to describe what is possible • Get Many and Different Resources on a single request • Network optimised requests & responses • No over or under fetching • Single Evolving Version vs API versioning • Integrated documentation & introspection What is it ?
  24. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini What is it ? GET /movies/1 { “id”: 1, “version”: 1, “title”: “Interstellar” … } Database App REST API
  25. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini What is it ? Database App GraphQL GET /graphql { “data”: { “allMovies” { “title”: “Interstellar” … “director”: { “name”: … … } } } GET /graphql allMovies{ title year director{ firstName lastName } }
  26. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini Schema is where you define the types and the relationship between types. How it works ?
  27. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini Resolvers is where the runtime fulfils Queries and Mutations by running actual code against data sources. How it works ? Every field is a function.
  28. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini Entities Prop Name Type ID Id Title String! Year Int DirectorID Id Movie Prop Name Type ID Id First Name String! Last Name Int Director 1 n
  29. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini REST Prop Name Type ID Id Title String! Year Int Director Id Movie Prop Name Type ID Id First Name String! Last Name Int Movies [Id] Director
  30. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini Graph Movie Director Id, Title, Year Id, First Name, Last Name 1..1 1..n
  31. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini How to use it ? 1. Invoke operation (Query or Mutation) 2. Get exactly what you asked for! Demo bit.ly/ADDC-GQi
  32. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini What is it ? 1. Popular & quick to setup GraphQL client 2. Supports caching, subscriptions, pre-fetching and more 3. Designed with React echo-system in mind 4. Production ready (KLM, The New York Times, OpenTable, Ticketmaster, Coursera, Khan Academy … ) 5. OSS & community focused: over 700 contributors and counting
  33. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini Apollo Provider How it works ? React App Apollo Client GraphQL Server Apollo Client: Makes actual calls to a GraphQL server Apollo Provider: Connects the Apollo Client to React by wrapping the App.
  34. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Project setup and ESLint • Introduction to React • The Movies App • A simple component • List and Items • Introduction to GraphQL • Play with Queries • Integrate Apollo Client • Write a Jest test! What did we see today
  35. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    Q&A Fire ahead! bit.ly/ADDC-W-Survey Let’s hear your voice ✍
  36. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    Thank you! @nzaghini [email protected] bit.ly/ADDC-W-Survey Let’s hear your voice ✍
  37. React Native & GraphQL - ADDC 2018 - Nicola Zaghini

    - @nzaghini • Styling Cheat Sheet - https://github.com/vhpoet/react- native-styling-cheat-sheet • Awesome React Native - https://github.com/jondot/ awesome-react-native • Flex Box Froggy - https://flexboxfroggy.com/ Links