0Pricing
PHP Academy · Lesson

Resolvers, Mutations and Subscriptions

Fetch and change data through resolvers.

Resolvers Are Where Logic Lives

The schema describes what exists; resolvers decide how each field's value is produced. A resolver is just a callable. Mutations are resolvers that change state. Subscriptions stream values over time. This lesson covers all three and the execution model that ties them together.

The Resolver Signature

Every resolver receives four arguments: ($objectValue, $args, $context, ResolveInfo $info).

  • $objectValue — the parent's resolved value (the rootValue at the top).
  • $args — the field's arguments.
  • $context — per-request shared state (DB handle, current user).
  • $info — AST/field metadata (field name, selection set, path).
<?php
use GraphQL\Type\Definition\ResolveInfo;

$resolve = function ($objectValue, array $args, $context, ResolveInfo $info) {
    // $context['db'], $context['user'] set up per request
    return $context['db']->find($args['id']);
};

All lessons in this course

  1. GraphQL vs REST
  2. Building a Schema with graphql-php
  3. Resolvers, Mutations and Subscriptions
  4. Performance: N+1 and DataLoader
← Back to PHP Academy