Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handful of doc fixes - typos and light highlights #6077

Merged
merged 12 commits into from
Aug 7, 2022
4 changes: 2 additions & 2 deletions docs/docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: How to use environment variables on the api and web sides

You can provide environment variables to each side of your Redwood app in different ways, depending on each Side's target, and whether you're in development or production.

> Right now, Redwood apps have two fixed Sides, API and Web, that have each have a single target, nodejs and browser respectively.
> Right now, Redwood apps have two fixed Sides, API and Web, that each have a single target, nodejs and browser respectively.

## Generally

Expand Down Expand Up @@ -46,7 +46,7 @@ By adding environment variables to this array, they'll be available to Web in pr

Note: if someone inspects your site's source, _they could see your `REDWOOD_ENV_SECRET_API_KEY` in plain text._ This is a limitation of delivering static JS and HTML to the browser.

#### Option 2: Prefixing with REDWOOD*ENV*
#### Option 2: Prefixing with REDWOOD\_ENV\_

In `.env`, if you prefix your environment variables with `REDWOOD_ENV_`, they'll be available via `process.env.REDWOOD_ENV_MY_VAR_NAME`, and will be dynamically replaced at built-time.

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ export const schema = gql`

2. Import the scalar's definition and resolver and pass them to your GraphQLHandler via the `schemaOptions` property:

```tsx {11-14} title="api/src/functions/graphql.ts"
```tsx {10-13} title="api/src/functions/graphql.ts"
import { CurrencyDefinition, CurrencyResolver } from 'graphql-scalars'

// ...
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/serverless-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ export const handler = useRequireAuth({

Now anywhere `context` is used, such as in services or when using `hasRole()` or `isAuthenticated()` from your `auth` lib, `currentUser` will be set and `requireAuth`-related functions will be able to verify the authentication state or if the user has the required roles.

In short, you can now use the any of your auth functions like `isAuthenticated()`, `hasRole()`, or `requireAuth()` in your serverless function.
In short, you can now use any of your auth functions like `isAuthenticated()`, `hasRole()`, or `requireAuth()` in your serverless function.

:::note

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Remember: Service are just functions. That means they can be used not only as Gr
>
> The short answer is no because our build process doesn't support it yet.
>
> Generally, in a full-stack application, Services will concern themselves with getting data in and out of a database. The libraries we use for this, like Prisma, do not run in the browser. However, even if it did, it would happily pass on whatever SQL-equivalent commands you give it, like `db.user.deleteMany()`, which would remove all user records! That kind of power in the hands of the client would wreck havoc the likes of which you have never seen.
> Generally, in a full-stack application, Services will concern themselves with getting data in and out of a database. The libraries we use for this, like Prisma, do not run in the browser. However, even if it did, it would happily pass on whatever SQL-equivalent commands you give it, like `db.user.deleteMany()`, which would remove all user records! That kind of power in the hands of the client would wreak havoc the likes of which you have never seen.

Service functions can also call each other. For example, that theoretical Service function that handles transferring money between two accounts: it certainly comes in handy when a user initiates a transfer through a GraphQL call, but our business logic for what constitutes a transfer lives in that function. That function should be the only one responsible for moving money between two accounts, so we should make use of it anywhere we need to do a transfer—imagine an async task that moves $100 between a checking and savings account every 1st of the month.

Expand Down
10 changes: 5 additions & 5 deletions docs/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export default Article

If we're only displaying the summary of an article then we'll only show the first 100 characters with an ellipsis on the end ("...") and include a link to "Read more" to see the full article. A reasonable test for this component would be that when the `summary` prop is `true` then the "Read more" text should be present. If `summary` is `false` then it should *not* be present. That's where `queryByText()` comes in (relevant test lines are highlighted):

```jsx {18,24} title="web/src/components/Article/Article.test.js"
```jsx {22} title="web/src/components/Article/Article.test.js"
import { render, screen } from '@redwoodjs/testing/web'
import Article from 'src/components/Article'

Expand Down Expand Up @@ -478,7 +478,7 @@ it('renders a link with a name', () => {

But what if we wanted to check the `href` of the link itself to be sure it's correct? In that case we can capture the `screen.getByRole()` return and run expectations on that as well (the `forEach()` loop has been removed here for simplicity):

```jsx {2,6-8}
```jsx {1,6-8}
import { routes } from '@redwoodjs/router'

it('renders a link with a name', () => {
Expand Down Expand Up @@ -597,7 +597,7 @@ export default Article

Redwood provides the test function `mockGraphQLQuery()` for providing the result of a given named GraphQL. In this case our query is named `getArticle` and we can mock that in our test as follows:

```jsx {8-16,20} title="web/src/components/Article/Article.test.js"
```jsx {6-14,18} title="web/src/components/Article/Article.test.js"
import { render, screen } from '@redwoodjs/testing/web'
import Article from 'src/components/Article'

Expand Down Expand Up @@ -646,7 +646,7 @@ mockGraphQLQuery('getArticle', (variables, { ctx }) => {

You could then test that you show a proper error message in your component:

```jsx {4,8-10,21,27} title="web/src/components/Article/Article.js"
```jsx {2,6-8,18-20,24} title="web/src/components/Article/Article.js"
const Article = ({ id }) => {
const { data, error } = useQuery(GET_ARTICLE, {
variables: { id },
Expand Down Expand Up @@ -1433,7 +1433,7 @@ scenario('incomplete', 'retrieves only incomplete users', async (scenario) => {
})
```

The name of the scenario you want to use is passed as the *first* argument to `scenario()` and now those will be the only records present in the database at the time the test to run. Assume that the `users()` function contains some logic to determine whether a user record is "complete" or not. If you pass `{ complete: false }` then it should return only those that it determines are not complete, which in this case includes users who have not entered their name yet. We seed the database with the scenario where one user is complete and one is not, then check that the return of `users()` only contains the user without the name.
The name of the scenario you want to use is passed as the *first* argument to `scenario()` and now those will be the only records present in the database at the time the test is run. Assume that the `users()` function contains some logic to determine whether a user record is "complete" or not. If you pass `{ complete: false }` then it should return only those that it determines are not complete, which in this case includes users who have not entered their name yet. We seed the database with the scenario where one user is complete and one is not, then check that the return of `users()` only contains the user without the name.

#### Multiple Models

Expand Down