NAME
GraphQL::Houtou::Schema - schema container for GraphQL::Houtou
SYNOPSIS
use GraphQL::Houtou::Schema;
use GraphQL::Houtou::Type::Object;
use GraphQL::Houtou::Type::Scalar qw($String);
my $schema = GraphQL::Houtou::Schema->new(
query => GraphQL::Houtou::Type::Object->new(
name => 'Query',
fields => {
hello => { type => $String, resolve => sub { 'world' } },
},
),
);
# or from SDL
my $schema = GraphQL::Houtou::Schema->from_doc($sdl, resolvers => \%resolvers);
my $runtime = $schema->build_native_runtime(async => 1);
DESCRIPTION
Holds the root operation types, the type registry, and the directive definitions, and is the factory for execution runtimes. Most applications build one schema at startup and one native runtime from it.
CONSTRUCTORS
new(%args)
query is required; mutation, subscription, description, types, and directives are optional. types defaults to the built-in scalars; list types here when they are reachable only through an interface or union (concrete types behind abstract fields).
from_doc($sdl, %opts) / from_ast($ast, %opts)
Build a schema from SDL (or its parsed AST). Resolvers, abstract type dispatch, and custom scalar coercion attach through resolvers => { TypeName => { field => sub {...} } }; see "Building a schema from SDL" in GraphQL::Houtou.
METHODS
build_native_runtime(%opts)
Compiles the schema and returns a GraphQL::Houtou::Runtime::NativeRuntime. Options: async (declare that resolvers return promises; see "Batching resolvers (DataLoader / the on_stall hook)" in GraphQL::Houtou), program_cache_max (per-query program cache size, default 1000), max_depth, max_nodes, max_cost, and default_list_size. With no options the compiled runtime is cached on the schema, so repeated calls are cheap.
assert_valid / validation_errors
validation_errors returns an arrayref of schema-validation messages (interface conformance, input/output type placement, and so on); assert_valid dies with the collected messages and is memoized.
to_doc
Renders the schema back to SDL, matching graphql-js printSchema conventions; also exposed as print_schema() in GraphQL::Houtou.
Accessors
query, mutation, subscription, types, directives, description, name2type, get_possible_types($abstract), is_possible_type($abstract, $object).