diff --git a/Lessons/Lesson-1.md b/Lessons/Lesson-1.md index 6c1230c..888429c 100644 --- a/Lessons/Lesson-1.md +++ b/Lessons/Lesson-1.md @@ -20,7 +20,15 @@ GraphQL represents a new way to work with network transactions. It provides many +## Warm Up (5 mins) +ELI5 (Explain Like I'm 5). Choose one of these to explain + +- How do Web Pages work? +- How do web browsers work? +- What are Web APIs? + + ## What makes the web work? REST 😴 and SOAP 🧼 diff --git a/Lessons/Lesson-2.md b/Lessons/Lesson-2.md index 33b0c32..1ef1bb8 100644 --- a/Lessons/Lesson-2.md +++ b/Lessons/Lesson-2.md @@ -23,6 +23,12 @@ Today we will look at a simple example implementing GraphQL with Express. This i +## Warm Up (5 mins) + +Discuss: +GraphQL and SQL are both Query languages. How do they differ? + + ## Review - **Name three advantages of GraphQL over REST** diff --git a/Lessons/Lesson-3.md b/Lessons/Lesson-3.md index c99aa02..7c9f542 100644 --- a/Lessons/Lesson-3.md +++ b/Lessons/Lesson-3.md @@ -14,6 +14,12 @@ By the end of today's lesson, you should be able to... +## Warm Up (5 mins) + +Discuss: +If GraphQL was a vehicle. What feature of the language do you think will be its engine? + + ## Review **Write a resolver for the following types: ** diff --git a/Lessons/Lesson-4.md b/Lessons/Lesson-4.md index 21069a7..5aaf351 100644 --- a/Lessons/Lesson-4.md +++ b/Lessons/Lesson-4.md @@ -13,6 +13,16 @@ Mutations are queries that make changes or you could say mutate data. +## Warm up - Code Review (10 mins) + +Break out into pairs and choose who will be the reviewer and reviewee for the challenges you were able to finish in lesson 3. + +- Reviewee: Share your screen and explain what your code does from top to bottom. +- Reviewer: Listen, ask questions, and make suggestions for improvement. + +After 5 minutes, switch roles. + + ## Review Write a Query and a Resolver for this schema: diff --git a/Lessons/Lesson-7.md b/Lessons/Lesson-7.md index f8a7a14..ded7e0b 100644 --- a/Lessons/Lesson-7.md +++ b/Lessons/Lesson-7.md @@ -15,15 +15,12 @@ It's efficient and has a great workflow, developer experience and community. 1. We would build a simple React app. 2. Build and use a reusable component 3. Use fundamental features JSX, State and Props -4. Build an app that works with a public API using use fetch to load data -5. Use Hooks +4. Use Hooks ## Review - - Discuss: - What is a subscription in GraphQL? @@ -31,7 +28,6 @@ Discuss: - How are Subscriptions implemented in a JavaScript environment? - Write a GraphQL Subscription operation(schema and resolver) that notifies clients when a new book is created ```js @@ -80,12 +76,11 @@ Components are the foundational building block of React Applications. Most often Components are composable. Components can be nested within other components. Complex components are made from smaller less complex components. -- Components return [JSX](#jsx) and handle user events using event handlers. -- Components can have children(a component shown inside another) or be the child to another component. -- The App (in the App.js) component in a React Project is the base or parent component for all other components. -- Components in React can either be Functional components or Class Components -- When we write React Compnents we shpuld target making them Simple, Stateful(where needed) and easily reusable throughout the application. -- Each **Class based** component has several lifecycle methods that can be used at particular times. Some of the commonly used ones are: +- Components must return [JSX](#jsx) and handle user events using event handlers. +- Components in React can either be Functional components or Class Components i.e. they can be written as a function or a class + + +Class components have several lifecycle methods that can be used at particular times. Some of the commonly used ones are: | LifeCycle Method | When it's called | | ----------- | ----------- | @@ -95,14 +90,6 @@ Components are composable. Components can be nested within other components. Com | [`componentDidUpdate()`](https://reactjs.org/docs/react-component.html#componentdidupdate) | After a component updates| | [`componentWillUnmount()`](https://reactjs.org/docs/react-component.html#componentwillunmount) | Before a component is destroyed. It is a clean up method.| -[Common React Lifecyle methods](https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/) - - - -- A component can be written as a function or a class. -- A component must return JSX -- Components can contain other components. - Example component @@ -148,20 +135,19 @@ function Header(props) { -React uses a virtual DOM to increase effeciency. The virtual DOM is managed through `ReactDOM`. +React uses a virtual DOM to increase efficiency. The virtual DOM is managed through `ReactDOM`. Since the virtual DOM is used to generate the real DOM you should never modify the DOM directly with JS! Instead make changes only via components. Read [here](https://reactjs.org/docs/faq-internals.html) for more on the Virtual DOM +The next block shows a very simple React app with these three features. -Putting these all together, here's a very simple React block of code with these three features. This code will show a simple form with a button that reads 'Click Me'. - -Check out the comments for some more details: + ```js -//Import React and ReactDOM librariea +//Import React and ReactDOM libraries import React from 'react'; import ReactDOM from 'react-dom'; @@ -176,24 +162,10 @@ const App = () => { return (
{this.props.text}
You clicked {count} times
- {/* updating state: call setter function - setCount() - on button click to update state value */} @@ -426,8 +364,9 @@ function Example() { ); } ``` + -#### useEffect + The code snippet below shows a simple implementation of the `useEffect()` method. @@ -471,13 +410,26 @@ Follow these -The challenge today is to build a React App that fetches weather data from your GraphQL Weather server. We would be using the Apollo client for GraphQL. +You will build a React App that fetches weather data from your GraphQL Weather server. It will be use the Apollo client for GraphQL for query. -To get started + + +To get started, your GraphQL server needs to support Cross-Origin Resource Sharing (CORS) + + -- Your GraphQL server needs to support Cross-Origin Resource Sharing (CORS) - - Go to your server directory and run `npm i cors` - - include the following piece of code to your GraphQL server file +What's CORS? + +Cross-Origin Resource Sharing is a mechanism that uses additional HTTP headers. + +It uses these headers to tell a browser to let a web application running at one origin have permission to access selected resources from a server at a different origin. + + +- Go to your GraphQL server directory and run `npm i cors` +- `cors` is a node.js package that can be used to enable CORS. + + +Include the following piece of code to your GraphQL server file ```js // after importing other dependencies @@ -488,6 +440,7 @@ To get started app.use(cors()); ``` + - Start your GraphQL Weather server - Create a new react project - install Apollo `npm install @apollo/client graphql` @@ -495,8 +448,9 @@ To get started ### Create Component - APP.js + We would first create an App component that displays an input field. -In your project folder the `src/App.js` include this piece of code. Take note of the comments for more details +In your project folder the `src/App.js` include this piece of code. ```js // import dependencies @@ -534,15 +488,18 @@ function App() { export default App; ``` + ### Render the Weather Details - Asynchronous operations (async, await) + `Async` and `await` are keywords that are used for Promises in JavaScript. - The `Async` keyword identifies an asyncronous function. An `Async` function always returns a Promise! - The `await` keyword only works within an `Async` function. Use await at the beginning of any expression that would return a Promise. JavaScript will wait at that line until the Promise resolves. + The syntax for using Async/Await looks like so: ```js @@ -554,14 +511,13 @@ The syntax for using Async/Await looks like so: ``` -Update your `App.js` file to include an asynchronous `fetchWeather` function. - - +- Update your `App.js` file to include an asynchronous `fetchWeather` function. - Wrap your App in the ApolloProvider - Make an instance of the Apollo client - Define a GraphQL query + ```js import { useState, useEffect } from 'react' import { gql } from '@apollo/client'; @@ -616,17 +572,21 @@ function App() { export default App; ``` + ### Create a child component - Weather.js + Right now, all the work for fetching and rendering data is handled by one component - `