Redwood Flashcards
When adding a package to Redwood, what needs to be kept in mind?
“Unlike with plain React, you need to specify which workspace they go in. It needs to look like this:<div><img></img><br></br></div>”
What is the command to generate a new page in Redwood?
“<img></img><div>or yarn rw g page home /</div><div><br></br></div><div>Where ‘home’ will be replaced by whatever page you want to create and ‘/’ is replaced by whatever url you want to map the route to.</div>”
What 4 things does the following code do?<div>yarn redwood generate page home /<br></br></div>
- Creates the page, like:<div>web/src/pages/HomePage/HomePage.js</div><div><br></br></div><div>2. Creates a test file web/src/pages/HomePage/HomePage.test.js with a single, passing test.</div><div><br></br></div><div>3.Creates a StoryBook at web/src/pages/HomePage/HomePage.stories.js,</div><div><br></br></div><div>4.Adds a Route in web/src/Routes.js that maps to the / path that we passed in</div>
What’s a cool thing Redwood does for you in your routes file?
Automatically imports all pages under the Pages directory, so you can avoid a huge stupid import statement.
What happens if you don’t include the directory when generating a page?
It assumes you want it at /myThing , where myThing is whatever the name of the page it.
Why don’t you have to worry about creating too many pages in Redwood?
It will automatically code-split on each page, so the initial page loads will still blind you with their speed. The number of pages will not impact the webpack bundle size.
When linking to a named route, what is the function named?
The same as the name attribute on the in the routes file.
What does a Redwood link look like?
“<img></img>”
What do you do if you need a table to have a string id (Say UUID or CUID)?
You just set the id to a String in the schema, and then you can use the built in uuid() or cuid() functions instead of autoincrement()
How do you make changes to the db in Redwood?
- Add the new data-type definition to api/prisma/schema.prisma<div><br></br></div><div>2. run ‘yarn rw db save create posts’</div><div><br></br></div><div>3. Apply the migration by running ‘yarn rw db up’</div><div><br></br></div><div>4. Then you can create CRUD action pages, Cells, GraphQL mutations and types, and a services file for business logic with scaffolding by running:</div><div>‘yarn rw g scaffold post’</div>
What is the process to add a table in Redwood?
- Add data definition to api/prisma/schema.prisma<div><br></br></div><div>2. Save the change - yarn rw db save create posts</div><div><br></br></div><div>3. Apply the migration with yarn rw db up</div><div><br></br></div>
What all do Cells take care of?
They handle the query, Loading/Error/Empty/Success states
When is QUERY called within a cell?
Automatically anytime that a component is rendered, you don’t have to worry about it.
What life cycle helpers do Cells provide?
beforeQuery handles the case where you need to massage some props before passing them to the query.<div><br></br></div><div>afterQuery handles the case where you need to do some stuff with the data that returns from the query before passing it off to your Success component.</div>
What states can data come back from a query in within Cells?
Success, Failure, Empty, Loading
Which exports are required for a cell to work?
QUERY and Success
What happens if you don’t export an Empty component within a cell?
those calls get passed to Success instead.
What happens if you don’t export a Failure component from a cell?
It just throws an error in the console.
How can you generate a cell?
yarn rw g cell ModelName
What does yarn rw g cell ModelName generate?
A new file with boilerplate included for data states, and a test file.
How do you alias gql data?
You can just change the name (not the query) in the gql, then that will change the name of the prop being passed into your Success component.
What is the standard life-cycle of adding a new feature within Redwood?
<ol> <li>Generate the homepage/landing page for the feature</li> <li>Generate the layout for those pages.</li> <li>Define the database schema</li> <li>Run migrations to update database and add the new table.</li> <li>Scaffold a CRUD interface to the database table.</li> <li>Create a cell to load the data and take care of loading/empty/fail/success states.</li> <li>Add the cell to the page.</li></ol>
How do queries work within Redwood?
“<img></img>”
What do the *.sdl.js files on the api side define?
the GraphQL Object, the query, and the mutations - they ar the whole interface of your API.