field
/connection
Usually, resolver simply returns a single object or scalar value that comply with defined types.
However, the resolver can bypass type definition with type coercion and can return any arbitrary value regardless of the client's query definition.
undefined
despite the query requiring the field.// example using sql getAuthor(_, args){ return sql.raw('SELECT * FROM authors WHERE id = %s', args.id); } // example calling api endpoint posts(author){ return request(`https://api.blog.io/by_author/${author.id}`); } // returning undefined names(author){ return undefined; }
Meaning, you can create any arbitrary connection between any query/node with another query
/node
.
Query
> User
> Name
connection may have different data than Query
> Group
> User
> Name
User.name
may yield 123-213-4545
even though it's clearly a phone number if the resolver defines it that way.User { Address { City } Age Name }
User
, Address
, Age
, and Name
are all individual nodes connected by resolver field definitions.
null
or undefined
return valueIndicates that the value for the field could not be found.
If your schema indicates that this resolver's field is nullable
, then the operation result has a null
value at the field's position.
If this resolver's field is not nullable
, Apollo Server sets the field's parent to null
.
If necessary, this process continues up the resolver chain until it reaches a field that is nullable
.
This ensures that a response never includes a null
value for a non-nullable
field. When this happens, the response's errors
property will be populated with relevant errors concerning the nullability of that field.