Skip to content

Commit 4a5dde4

Browse files
committed
docs: update readme
1 parent c043fdf commit 4a5dde4

File tree

3 files changed

+101
-8
lines changed

3 files changed

+101
-8
lines changed

.circleci/.config.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Javascript Node CircleCI 2.0 configuration file
2+
#
3+
# Check {{ '/2.0/language-javascript/' | docs_url }} for more details
4+
#
5+
version: 2
6+
7+
defaults: &defaults
8+
working_directory: ~/repo
9+
docker:
10+
- image: circleci/node:10
11+
12+
jobs:
13+
test:
14+
<<: *defaults
15+
steps:
16+
- checkout
17+
18+
- restore_cache:
19+
keys:
20+
- v1-dependencies-{{ checksum "package.json" }}
21+
- v1-dependencies-
22+
23+
- run: yarn install
24+
- run:
25+
name: Run tests
26+
command: yarn test
27+
28+
- save_cache:
29+
paths:
30+
- node_modules
31+
key: v1-dependencies-{{ checksum "package.json" }}
32+
33+
- persist_to_workspace:
34+
root: ~/repo
35+
paths: .
36+
37+
workflows:
38+
version: 2
39+
only_test:
40+
jobs:
41+
- test

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,55 @@ generates:
3030
- 'graphql-codegen-typescript-mock-data':
3131
typesFile: '../generated-types.ts'
3232
```
33+
34+
## Example or generated code
35+
36+
Given the following schema:
37+
38+
```graphql
39+
type Avatar {
40+
id: ID!
41+
url: String!
42+
}
43+
44+
type User {
45+
id: ID!
46+
login: String!
47+
avatar: Avatar
48+
}
49+
50+
type Query {
51+
user: User!
52+
}
53+
```
54+
55+
The code generated will look like:
56+
57+
```typescript
58+
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
59+
return {
60+
id: '1550ff93-cd31-49b4-bc38-ef1cb68bdc38',
61+
url: 'aliquid',
62+
...overrides,
63+
};
64+
};
65+
66+
export const aUser = (overrides?: Partial<User>): User => {
67+
return {
68+
id: 'b5756f00-51a6-422a-9a7d-c13ee6a63750',
69+
login: 'libero',
70+
avatar: anAvatar(),
71+
...overrides,
72+
};
73+
};
74+
```
75+
76+
### Usage in tests
77+
78+
Those helper functions can be used in our unit tests:
79+
80+
```typescript
81+
const user = aUser({ login: 'johndoe' });
82+
83+
// will create a user object with `login` property overridden to `johndoe`
84+
```

tests/__snapshots__/typescript-mock-data.spec.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ exports[`should generate mock data functions 1`] = `
44
"
55
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
66
return {
7-
id: '1550ff93-cd31-49b4-bc38-ef1cb68bdc38',
7+
id: '0550ff93-dd31-49b4-8c38-ff1cb68bdc38',
88
url: 'aliquid',
99
...overrides
10-
});
10+
};
1111
};
1212
1313
export const aUser = (overrides?: Partial<User>): User => {
1414
return {
15-
id: 'b5756f00-51a6-422a-9a7d-c13ee6a63750',
15+
id: 'a5756f00-41a6-422a-8a7d-d13ee6a63750',
1616
login: 'libero',
1717
avatar: anAvatar(),
1818
...overrides
19-
});
19+
};
2020
};
2121
"
2222
`;
@@ -27,19 +27,19 @@ import { Avatar, User } from './types/graphql';
2727
2828
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
2929
return {
30-
id: '1550ff93-cd31-49b4-bc38-ef1cb68bdc38',
30+
id: '0550ff93-dd31-49b4-8c38-ff1cb68bdc38',
3131
url: 'aliquid',
3232
...overrides
33-
});
33+
};
3434
};
3535
3636
export const aUser = (overrides?: Partial<User>): User => {
3737
return {
38-
id: 'b5756f00-51a6-422a-9a7d-c13ee6a63750',
38+
id: 'a5756f00-41a6-422a-8a7d-d13ee6a63750',
3939
login: 'libero',
4040
avatar: anAvatar(),
4141
...overrides
42-
});
42+
};
4343
};
4444
"
4545
`;

0 commit comments

Comments
 (0)