Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
richardguerre committed Oct 3, 2021
1 parent 85f0423 commit b0c9caf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,17 @@ With the above you don't have to add any additional options when invoking the `u

You can specify the following `options` in `createRelayMockEnvironmentHook(options)` (global level) or `useRelayMockEnvironment(options)` (component specific level):

| Name | Type | Description |
| :----------------------- | :------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `customResolvers?` | `MockResolvers` | (optional) custom resolvers that are spread after use-relay-mock-environment's `ID` and `String` resolvers. `const resolvers = { ID() {...}, String() {...}, // your custom resolvers go here }` You can of course override the default `ID` and `String` resolvers by specifying your own. Read more about custom resolvers here: https://relay.dev/docs/guides/testing-relay-components/#mock-payload-generator-and-the-relay_test_operation-directive |
| `data?` | [`RelayMockData`](modules.md#relaymockdata) | (optional) an object containing overrides to the types/categories of each field, where each key is the `fieldName` or `parentTypeName` (see below). First specify the `parentTypeName` as the key, and the value is an object containing the `fieldName`(s) as the key(s). Example: `js const mockData = { users: { firstName: { mockType: 'faker.name.firstName' } } }` |
| `extendStringResolver?` | `MockResolver` | (optional) a function to extend use-relay-mock-environment's `String` resolver. **`param`** `context` is the mock resolver context (read more about it here: https://relay.dev/docs/guides/testing-relay-components/#mock-resolver-context) **`param`** `generateId` is a function to generate a globally unique ID number. |
| `forceLoading?` | `boolean` | (optional) Whether to force loading and don't resolve any GraphQL operation. |
| `generatorOptions?` | `MockPayloadGeneratorOptions` | (optional) mock generator options. Please read documentation of type MockPayLoadGeneratorOptions. |
| `instantInitialLoading?` | `boolean` | (optional) Whether to instantly load the GraphQL operation. By default there is a 300ms loading time to mimick real-world network conditions. This only applies to the initial loading. If you would like to change the loading time, set `loadTime` instead. |
| `loadTime?` | `number` | (optional) Loading time in miliseconds for each GraphQL operations. Default is 300ms as to mimick real-world network conditions. |
| `seed?` | `number` \| `string` | If a number is passed in, it directly runs `faker.seed(n)` with `n` being the number that you specify. If a string is passed in, it first converts the string into a hashCode number (like Java's String.hashCode()), and then runs `faker.seed(n)`, where `n` is the hashCode number. Providing `seed` will override property `generatorOptions.randomLengthArray` to false, and will set `geneartorOptions.arrayLength` to 3, unless specified. |
| Name | Type | Description |
| :----------------------- | :------------------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `customResolvers?` | `MockResolvers` | (optional) custom resolvers that are spread after use-relay-mock-environment's `ID` and `String` resolvers. `const resolvers = { ID() {...}, String() {...}, // your custom resolvers go here }` You can of course override the default `ID` and `String` resolvers by specifying your own. Read more about custom resolvers here: https://relay.dev/docs/guides/testing-relay-components/#mock-payload-generator-and-the-relay_test_operation-directive |
| `data?` | [`RelayMockData`](modules.md#relaymockdata) | (optional) an object containing overrides to the types/categories of each field, where each key is the `fieldName` or `parentTypeName` (see below). First specify the `parentTypeName` as the key, and the value is an object containing the `fieldName`(s) as the key(s). Example: `js const mockData = { users: { firstName: { mockType: 'faker.name.firstName' } } }` |
| `extendStringResolver?` | `MockResolver` | (optional) a function to extend use-relay-mock-environment's `String` resolver. If `relay-mock-default` is returned, then it will continue with the default mock resolvers using FakerJS. **`param`** `context` is the mock resolver context (read more about it here: https://relay.dev/docs/guides/testing-relay-components/#mock-resolver-context) **`param`** `generateId` is a function to generate a globally unique ID. |
| `forceLoading?` | `boolean` | (optional) Whether to force loading and don't resolve any GraphQL operation. |
| `generatorOptions?` | `MockPayloadGeneratorOptions` | (optional) mock generator options. Please read documentation of type MockPayLoadGeneratorOptions. |
| `instantInitialLoading?` | `boolean` | (optional) Whether to instantly load the GraphQL operation. By default there is a 300ms loading time to mimick real-world network conditions. This only applies to the initial loading. If you would like to change the loading time, set `loadTime` instead. |
| `loadTime?` | `number` | (optional) Loading time in miliseconds for each GraphQL operations. Default is 300ms as to mimick real-world network conditions. |
| `monitorContext?` | `boolean` | Monitor `context` by console logging it out from the `String` resolver. Useful to get the `parentType` of a field to resolve. |
| `seed?` | `number` \| `string` | (optional) a number or string used to seed the random generators to get consistent fake data. Useful when doing tests like Jest Snapshots or Visual Regression Tests within Chromatic. If a number is passed in, it directly runs `faker.seed(n)` with `n` being the number that you specify. If a string is passed in, it first converts the string into a hashCode number (like Java's String.hashCode()), and then runs `faker.seed(n)`, where `n` is the hashCode number. Providing `seed` will override property `generatorOptions.randomLengthArray` to false, and will set `geneartorOptions.arrayLength` to 3, unless specified. |

You can read more about `options` [here](https://github.com/richardguerre/use-relay-mock-environment/blob/master/docs/modules.md#relaymockoptions).

Expand Down
17 changes: 10 additions & 7 deletions docs/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const mockData = {

#### Defined in

[index.ts:87](https://github.com/richardguerre/use-relay-mock-environment/blob/2b2f109/src/index.ts#L87)
[index.ts:97](https://github.com/richardguerre/use-relay-mock-environment/blob/85f0423/src/index.ts#L97)

___

Expand All @@ -62,13 +62,15 @@ You can specify one or more of the following:
| Name | Type | Description |
| :------ | :------ | :------ |
| `mockDescription?` | `string` | (optional) describe what type/category the field is. This mockDescription goes through the same fuzzy search that the field name goes through. |
| `mockNull?` | `boolean` | (optional) a boolean to specify whether the value should resolve to null. |
| `mockPath?` | `string` | (optional) path taken by the query (not fragment) to get to the field. Example: ``` query { usersConnection { edges { node { firstName } } } } ``` In this case, the path of field `firstName` is `"usersConnection.edges.node.firstName"`. |
| `mockType?` | `FakerPath` | type/category of the field. Only faker types are supported for now. Example: Setting mockType to `faker.random.word` will result in generating a random word. |
| `mockUndefined?` | `boolean` | (optional) a boolean to specify whether the value should resolve to undefined. |
| `mockValues?` | `any`[] | (optional) an array of possible values to randomly select from. Example: Setting mockValues to `['hello', 'world', 3, true, false]`, the generator will randomly select out of those values. If you want to add weight to one value, you can use the `Array(3).fill(yourValue)`. Example: ``` "fieldName": { mockValues: [Array(3).fill('hello'), 'world', 3, true, false] } ``` `'hello'` is 3x more likely to be selected. |

#### Defined in

[index.ts:26](https://github.com/richardguerre/use-relay-mock-environment/blob/2b2f109/src/index.ts#L26)
[index.ts:26](https://github.com/richardguerre/use-relay-mock-environment/blob/85f0423/src/index.ts#L26)

___

Expand All @@ -80,7 +82,7 @@ Same as the `RelayMockOptions` below.

#### Defined in

[index.ts:167](https://github.com/richardguerre/use-relay-mock-environment/blob/2b2f109/src/index.ts#L167)
[index.ts:186](https://github.com/richardguerre/use-relay-mock-environment/blob/85f0423/src/index.ts#L186)

___

Expand All @@ -94,16 +96,17 @@ ___
| :------ | :------ | :------ |
| `customResolvers?` | `MockResolvers` | (optional) custom resolvers that are spread after use-relay-mock-environment's `ID` and `String` resolvers. ``` const resolvers = { ID() {...}, String() {...}, // your custom resolvers go here } ``` You can of course override the default `ID` and `String` resolvers by specifying your own. Read more about custom resolvers here: https://relay.dev/docs/guides/testing-relay-components/#mock-payload-generator-and-the-relay_test_operation-directive |
| `data?` | [`RelayMockData`](modules.md#relaymockdata) | (optional) an object containing overrides to the types/categories of each field, where each key is the `fieldName` or `parentTypeName` (see below). First specify the `parentTypeName` as the key, and the value is an object containing the `fieldName`(s) as the key(s). Example: ```js const mockData = { users: { firstName: { mockType: 'faker.name.firstName' } } } ``` |
| `extendStringResolver?` | `MockResolver` | (optional) a function to extend use-relay-mock-environment's `String` resolver. **`param`** `context` is the mock resolver context (read more about it here: https://relay.dev/docs/guides/testing-relay-components/#mock-resolver-context) **`param`** `generateId` is a function to generate a globally unique ID number. |
| `extendStringResolver?` | `MockResolver` | (optional) a function to extend use-relay-mock-environment's `String` resolver. If `relay-mock-default` is returned, then it will continue with the default mock resolvers using FakerJS. **`param`** `context` is the mock resolver context (read more about it here: https://relay.dev/docs/guides/testing-relay-components/#mock-resolver-context) **`param`** `generateId` is a function to generate a globally unique ID. |
| `forceLoading?` | `boolean` | (optional) Whether to force loading and don't resolve any GraphQL operation. |
| `generatorOptions?` | `MockPayloadGeneratorOptions` | (optional) mock generator options. Please read documentation of type MockPayLoadGeneratorOptions. |
| `instantInitialLoading?` | `boolean` | (optional) Whether to instantly load the GraphQL operation. By default there is a 300ms loading time to mimick real-world network conditions. This only applies to the initial loading. If you would like to change the loading time, set `loadTime` instead. |
| `loadTime?` | `number` | (optional) Loading time in miliseconds for each GraphQL operations. Default is 300ms as to mimick real-world network conditions. |
| `seed?` | `number` \| `string` | If a number is passed in, it directly runs `faker.seed(n)` with `n` being the number that you specify. If a string is passed in, it first converts the string into a hashCode number (like Java's String.hashCode()), and then runs `faker.seed(n)`, where `n` is the hashCode number. Providing `seed` will override property `generatorOptions.randomLengthArray` to false, and will set `geneartorOptions.arrayLength` to 3, unless specified. |
| `monitorContext?` | `boolean` | Monitor `context` by console logging it out from the `String` resolver. Useful to get the `parentType` of a field to resolve. |
| `seed?` | `number` \| `string` | (optional) a number or string used to seed the random generators to get consistent fake data. Useful when doing tests like Jest Snapshots or Visual Regression Tests within Chromatic. If a number is passed in, it directly runs `faker.seed(n)` with `n` being the number that you specify. If a string is passed in, it first converts the string into a hashCode number (like Java's String.hashCode()), and then runs `faker.seed(n)`, where `n` is the hashCode number. Providing `seed` will override property `generatorOptions.randomLengthArray` to false, and will set `geneartorOptions.arrayLength` to 3, unless specified. |

#### Defined in

[index.ts:93](https://github.com/richardguerre/use-relay-mock-environment/blob/2b2f109/src/index.ts#L93)
[index.ts:103](https://github.com/richardguerre/use-relay-mock-environment/blob/85f0423/src/index.ts#L103)

## Functions

Expand Down Expand Up @@ -141,4 +144,4 @@ a function that is the `useRelayMockEnvironment()` React hook. Read more about i

#### Defined in

[index.ts:189](https://github.com/richardguerre/use-relay-mock-environment/blob/2b2f109/src/index.ts#L189)
[index.ts:208](https://github.com/richardguerre/use-relay-mock-environment/blob/85f0423/src/index.ts#L208)

0 comments on commit b0c9caf

Please sign in to comment.