Redwood Flashcards

1
Q

When adding a package to Redwood, what needs to be kept in mind?

A

“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>”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the command to generate a new page in Redwood?

A

“<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>”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What 4 things does the following code do?<div>yarn redwood generate page home /<br></br></div>

A
  1. 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>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s a cool thing Redwood does for you in your routes file?

A

Automatically imports all pages under the Pages directory, so you can avoid a huge stupid import statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens if you don’t include the directory when generating a page?

A

It assumes you want it at /myThing , where myThing is whatever the name of the page it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why don’t you have to worry about creating too many pages in Redwood?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When linking to a named route, what is the function named?

A

The same as the name attribute on the in the routes file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does a Redwood link look like?

A

“<img></img>”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What do you do if you need a table to have a string id (Say UUID or CUID)?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you make changes to the db in Redwood?

A
  1. 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>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the process to add a table in Redwood?

A
  1. 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>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What all do Cells take care of?

A

They handle the query, Loading/Error/Empty/Success states

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When is QUERY called within a cell?

A

Automatically anytime that a component is rendered, you don’t have to worry about it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What life cycle helpers do Cells provide?

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What states can data come back from a query in within Cells?

A

Success, Failure, Empty, Loading

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which exports are required for a cell to work?

A

QUERY and Success

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What happens if you don’t export an Empty component within a cell?

A

those calls get passed to Success instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What happens if you don’t export a Failure component from a cell?

A

It just throws an error in the console.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How can you generate a cell?

A

yarn rw g cell ModelName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does yarn rw g cell ModelName generate?

A

A new file with boilerplate included for data states, and a test file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How do you alias gql data?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the standard life-cycle of adding a new feature within Redwood?

A

<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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do queries work within Redwood?

A

“<img></img>”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What do the *.sdl.js files on the api side define?

A

the GraphQL Object, the query, and the mutations - they ar the whole interface of your API.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Why does Redwood avoid business logic in the resolver map?

A

Because it makes files big and not easily re-used - it puts this logic in the api/src/services

26
Q

Describe an example Javascript SDL.

A

“<img></img>”

27
Q

What does a typical services file look like?

A

“<img></img>”

28
Q

What is the db variable within your services file?

A

An instance of Prisma client.

29
Q

What sweet thing does Apollo do for you with your query results?

A

It waits for the response before sending them back, so you don’t need to mess with async/await or callbacks.

30
Q

Where do Services fit in, in regards to database tables?

A

They are meant to be a layer above them - so you could have a Billing service that hits both a transactions and a subscriptions table.

31
Q

How can you keep a service function un-exposed?

A

Leave it out of the Query and Mutation functions within your sdl.

32
Q

What does dividing your app into well-defined services and then providing an API for them do for you?

A

It enforces the separation of concerns and increases the code’s maintainability.

33
Q

Where does data from a service come back to on the front side?

A

Your Redwood Cell’s success component, and then you can loop through it and/or display it like any other React component.

34
Q

How do you make route params?

A

“<img></img><div>This says ““whatever value is in this position of the path when it comes in, let me reference it by the arbitrary name I’ve given it within the curly bois.</div>”

35
Q

How do you link to a route with a route param?

A

“<div><div> {post.title}</div><div><span></span></div></div>”

36
Q

What is your key that you need a cell?

A

Any time you’re doing data retrieval from the database.

37
Q

“How would you change this query to accept a param?<div><img></img><br></br></div>”

A

“<img></img>”

38
Q

What automagic does Redwood do for you around route params?

A

“Whenever there’s a route param within a route, that variable is automatically available to the page that route renders, you just pull it into your component and use it:<div><br></br></div><div><img></img><br></br></div>”

39
Q

How do you typecast a route param?

A

“It’s as easy as specifying it with a colon:<div><img></img><br></br></div>”

40
Q

What additional benefit does type casting a route param give you?

A

It prevents route matching unless what’s entered matches - so :Int will only match if what’s put into the browser is entirely digits.

41
Q

How do you import React into Redwood?

A

It’s all automatically done for you, so finally, you don’t have to import it over and over again in every file.

42
Q

What do Redwood forms start with?

A

… The tag, as it should be.

43
Q

How do you validate a Redwood Form helper?

A

you pass an object as its validation attribute with whatever you need.

44
Q

How do you display validation errors on a redwood form?

A

You first pass a validation object to the form helper field, and then place a FieldError component with the same name as the form helper field.

45
Q

How do you style a FieldError component?

A

It takes a className prop, which you can pass in easily to style it, since it’s just plain html.

46
Q

How do you style an error input (not display the error, but change the appearance of the input itself)

A

Within your css, just apply a style to an input or textarea or whatever, and then on your FormField, pass it a prop named errorClassName with the name of the class to be applied when an error occurs.

47
Q

How can you style a form label upon error?

A

You have to use Redwood’s custom component, but then you just set it to have the same name as your field, and give it an errorClassName that you’ve set in your css on the label (label.error {})

48
Q

In addition to className or errorClassName, what other fields do React Form components accept for styling?

A

style and errorStyle

49
Q

How do you validate an email form field?

A

“the validation object passed in as a prop on the form field can take a pattern:<div><img></img><br></br></div>”

50
Q

How do you validate as soon as the user leaves a field, not on submit?

A

“Oh god - it’s so simple -<div><img></img><br></br></div>”

51
Q

What are Redwood Forms built on top of?

A

React Hook Form - so you can visit their docs and do everything they mention.

52
Q

What is the first step when adding a new database table to Redwood?

A

Open up api/prisma/schema.prisma and add the model with whatever fields it needs.

53
Q

How do you allow for an optional field within Prisma?

A

Put a question mark next to the type name -<div>name String? will allow name to be either a String or NULL</div>

54
Q

After adding a new model/database table in the schema.prisma, what’s the next (second) step?

A

Create a migration file - yarn rw db save (name of migration)

55
Q

After creating the migration file (2nd step) - what is the third step when adding a new model to a Redwood app?

A

Run the migration to update the database:<div>yarn rw db up</div>

56
Q

After updating the database (step 3) what is the next step wheen adding a model to our Redwood db?

A

Create the GraphQL interface so that we can access the new table:<div>yarn rw g sdl contact</div>

57
Q

What two files does yarn rw g sdl (table) create?

A
  1. graphql/contacts.sdl.js with our interfaces and queries<div>2. services/contacts/contacts.js with our service methods that can be called.</div>
58
Q

Why does Redwood generate create and update Inputs within the graphql sdl?

A

It follows the recommendation to use Input Types in mutations rather than listing out each and every field that can be set.

59
Q

By default, how do requirements work within the generated GraphQL Interfaces?

A

Any required fields are also required on the create input (because you can’t generate a record without them) - but nothing is explicitly required by default in the update input.

60
Q

What does Redwood assume when creating inputs regarding the id or createdAt fields?

A

It assumes you won’t want to update those and that they’re being set on the back end rather than explicitly, so it leaves them out of the inputs.

61
Q

What naming convention does Redwood follow between its sdl and services files/

A

Each field listed in the Query and Mutation types in the sdl file are automatically mapped to a function with the same name in the services file.