NAME

GraphQL::Houtou::Type::Object - GraphQL object type

SYNOPSIS

my $User = GraphQL::Houtou::Type::Object->new(
  name   => 'User',
  fields => {
    id   => { type => $ID },
    name => { type => $String },
    posts => {
      type => $Post->non_null->list,
      args => { first => { type => $Int } },
      resolve => sub {
        my ($user, $args, $context, $info) = @_;
        $context->{posts}->load($user->{id});
      },
    },
  },
  interfaces => [ $Node ],
);

DESCRIPTION

An output object type. Each field takes type, optional args (name => { type => ..., default_value => ... }), an optional resolve callback receiving ($source, $args, $context, $info), and optional description / deprecation_reason. Fields without resolve use the default resolver. A blessed source method named for the field is called with ($args, $context, $info). Otherwise a source hash key is read; when that value is a coderef, it is called with the same arguments. Other hash values are returned directly. Resolvers may return Promise::XS promises; see "Batching resolvers (DataLoader / the on_stall hook)" in GraphQL::Houtou. Method lookup follows normal Perl inheritance, so fields named can, isa, or DOES should use explicit resolvers when the source is blessed.

$type->list and $type->non_null wrap any type in GraphQL::Houtou::Type::List / GraphQL::Houtou::Type::NonNull.

SEE ALSO

GraphQL::Houtou, GraphQL::Houtou::Schema