Return nested data in queries / mutations



As per @agartha’s comment: Resolver function extend, resolvers are unable to return nested data (relations). But if resolvers are unable to return nested data, how, then, would we be able to do so via custom query/mutations?

For example, upon providing an affiliateLink, I want the clickAffiliateLink mutation to return a tokenString (generated in the AffiliateLinkClick model), as well as its related website title and url (located in the AffiliateLink model).

schema.graphql (incorrect syntax, no doubt):

type Mutation {
	clickAffiliateLink(affiliateLink: String!): AffiliateLinkClickPayload!

type AffiliateLinkClickPayload {
	affiliateLink: AffiliateLinkClickConnectPayload
	tokenString: String!

type AffiliateLinkClickConnectPayload {
	connect: AffiliateLinkPayload

type AffiliateLinkPayload {
	title: String
	url: String

On the client-side, I want this to show, specifically the affiliateLink { title url } part:

mutation($affiliateLink: String!) {
	clickAffiliateLink(affiliateLink: $affiliateLink) {
		affiliateLink {


The forum post you refer to is about Graphcool Framework.
You can absolutely return anything you want in GraphQL resolvers, for example using Prisma binding.

I recommend reading this forum post:

And this blog post:


Thank you, @nilan!

One last question I wasn’t able to find the answer to in your blog post: How should the schema.graphql look like for a nested query resolver?

type Query {
	customQueryName(tokenString: String!): CustomQueryPayload!

type CustomQueryPayload {
	regularField: String! # ← This refers to the same model for which the query is performed.
	nestedField: ? # ← How can I make this refer to the other model? 

I would like to achieve this outcome:

query($tokenString: String!) {
	customQueryName(tokenString: $tokenString) {
		nestedField {

The resolver looks like this:

const resolver = async (parent, args, ctx, info) => {
	const { tokenString } = args
	return await ctx.db.query.customQueryName({ where: { tokenString } }, `{ nestedField { title url } }`)


Made it work! No idea how, thought… this whole thing is a bit over my head :flushed: