You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to make an issue here to request an example using nested field resolvers. One of the benefits of GraphQL is that only what you call is resolved.
Say we have a posts query that also has comments. We don't want to fetch the comments unless they are specifically requested in the GraphQL query. This would make a great example using the JSONPlaceholder API.
I found an example of nested types in the dgraph-101 project:
However, this always fetches the category data even if it's not requested in the GraphQL query. I'm not sure if nested resolvers are currently supported, but it would be valuable to demonstrate this pattern.
Proposed Implementation using JSONPlaceholder:
import{http}from"@hypermode/modus-sdk-as"
@jsonexportclassComment{postId!: numberid!: numbername!: stringemail!: stringbody!: string}
@jsonexportclassPost{id!: numberuserId!: numbertitle!: stringbody!: stringcomments: Comment[]=[]}/** * Get a list of posts. Comments will only be fetched when the comments field is requested. */exportfunctiongetPosts(): Post[]{constrequest=newhttp.Request("https://jsonplaceholder.typicode.com/posts")constresponse=http.fetch(request)returnresponse.json<Post[]>()}/** * Field resolver for Post.comments - only called when comments are requested */exportfunctionresolvePostComments(post: Post): Comment[]{constrequest=newhttp.Request(`https://jsonplaceholder.typicode.com/posts/${post.id}/comments`)constresponse=http.fetch(request)returnresponse.json<Comment[]>()}
This would allow queries like:
# Just posts - comments not fetchedquery {
posts {
idtitle
}
}
# Posts with comments - comments fetched via resolverquery {
posts {
idtitlecomments {
idbody
}
}
}
Can someone confirm if field resolvers are supported? If so, this would make a great example here.
The text was updated successfully, but these errors were encountered:
Hi team,
I wanted to make an issue here to request an example using nested field resolvers. One of the benefits of GraphQL is that only what you call is resolved.
Say we have a posts query that also has comments. We don't want to fetch the comments unless they are specifically requested in the GraphQL query. This would make a great example using the JSONPlaceholder API.
I found an example of nested types in the dgraph-101 project:
modus-recipes/dgraph-101/api-as/assembly/index.ts
Line 34 in f119281
However, this always fetches the category data even if it's not requested in the GraphQL query. I'm not sure if nested resolvers are currently supported, but it would be valuable to demonstrate this pattern.
Proposed Implementation using JSONPlaceholder:
This would allow queries like:
Can someone confirm if field resolvers are supported? If so, this would make a great example here.
The text was updated successfully, but these errors were encountered: