Skip to content

Commit 3c6c25a

Browse files
author
Lucas Bento
authored
Check if id is valid on Loader.load (#45)
2 parents 1f67b8f + d234cc8 commit 3c6c25a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

packages/generator/src/loader/__tests__/__snapshots__/LoaderGenerator.spec.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default class Example {
3838
}
3939
4040
static async load(viewer, id) {
41+
if (!id) {
42+
return null;
43+
}
44+
4145
const data = await Example.ExampleLoader.load(id.toString());
4246
4347
return Example.viewerCanSee(viewer, data) ? new Example(data) : null;
@@ -112,6 +116,10 @@ export default class Post {
112116
}
113117
114118
static async load(viewer, id) {
119+
if (!id) {
120+
return null;
121+
}
122+
115123
const data = await Post.PostLoader.load(id.toString());
116124
117125
return Post.viewerCanSee(viewer, data) ? new Post(data) : null;
@@ -183,6 +191,10 @@ export default class User {
183191
}
184192
185193
static async load(viewer, id) {
194+
if (!id) {
195+
return null;
196+
}
197+
186198
const data = await User.UserLoader.load(id.toString());
187199
188200
return User.viewerCanSee(viewer, data) ? new User(data) : null;

packages/generator/src/loader/templates/Loader.js.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export default class <%= name %> {
3636
}
3737

3838
static async load(viewer, id) {
39+
if (!id) {
40+
return null;
41+
}
42+
3943
const data = await <%= name %>.<%= rawName %>Loader.load(id.toString());
4044

4145
return <%= name %>.viewerCanSee(viewer, data) ? new <%= name %>(data) : null;

packages/generator/src/loader/templates/LoaderWithSchema.js.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export default class <%= name %> {
4242
}
4343

4444
static async load(viewer, id) {
45+
if (!id) {
46+
return null;
47+
}
48+
4549
const data = await <%= name %>.<%= rawName %>Loader.load(id.toString());
4650

4751
return <%= name %>.viewerCanSee(viewer, data) ? new <%= name %>(data) : null;

0 commit comments

Comments
 (0)