Expose stored object properties
A parent object already contains a scalar field with the same name as the GraphQL field.
GraphQL · Function
defaultFieldResolver is the conventional behavior used by many GraphQL libraries when no field resolver is supplied: read the same-named property from the parent object and return it. It suits simple fields whose values are already present on that object.
GraphQL’s default field behavior resolves a field by reading a property with the same name from the parent object when no custom resolver is supplied. This is useful for simple fields whose response value is already present on the parent object.
The value produced for the field; for a trivial resolver, the same-named property from the parent object.
const user = { name: "Ada" };
const result = user.name;
console.log(result); // AdaA trivial resolver can return a same-named property from the parent object.
A parent object already contains a scalar field with the same name as the GraphQL field.
A type has several straightforward fields that require no computation or data fetching.
A nested selection reads fields directly from an object returned by an earlier resolver.
A resolver is the function backing a GraphQL field. During execution, GraphQL calls the resolver for the field to produce the next value; for a trivial field, many libraries can instead read a same-named property from the parent object.
Follow-up: What happens when the field has a custom resolver? The custom resolver is used to compute the field’s value instead of relying on the same-name property convention.
A trivial resolver is appropriate when the value is already stored on the parent object under the GraphQL field’s name. In that case, no explicit resolver is needed in libraries that support this convention.
Follow-up: When should an explicit resolver be preferred? Use one when the value requires computation, arguments, external data access, or a property name different from the schema field.
Field execution produces values that are placed into a response map under the field name or alias. The resolved value then supplies the next part of the result structure.
Follow-up: What determines the response key? An alias becomes the response key; without an alias, the field name is used.
resolverfield resolvertrivial resolverQueryMutationSubscriptionalias