GraphQL::Schema(3pm)
๐ GraphQL::Schema โ the vibe โจ
okay bestie, welcome to GraphQL::Schema, a Perl module (3pm, user-contributed docs, iykyk) that is literally the GraphQL schema object itself. it's giving main character energy for your whole GraphQL setup ๐ซถ
โจ SYNOPSIS โจ
here's the whole flex in one go:
use GraphQL::Schema;
use GraphQL::Type::Object;
my $schema = GraphQL::Schema->new(
query => GraphQL::Type::Object->new(
name => 'Query',
fields => {
getObject => {
type => $interfaceType,
resolve => sub {
return {};
}
}
}
)
);
๐ธ DESCRIPTION ๐ธ
it's the class that implements the GraphQL schema. that's the whole thing. iconic, honestly. ๐
๐ ATTRIBUTES ๐
query
no cap, it's just the query attribute.
mutation
same energy โ the mutation attribute.
subscription
and the subscription attribute. the trio. ๐
types
defaults to the types returned by "registered" in GraphQL::Plugin::Type. heads up bestie: note that this includes the standard scalar types that are always loaded by GraphQL::Type::Scalar. so if you wanna supply an overriding value for this attribute, bear that in mind fr fr. ๐ง โจ
directives
the directives attribute. slay.
๐ METHODS ๐
name2type
in this schema, returns a hash-ref mapping all types' names to their type object. cute little lookup table. ๐
get_possible_types($abstract_type)
in this schema, get all of either the implementation types (if interface) or possible types (if union) of the $abstract_type.
is_possible_type($abstract_type, $possible_type)
in this schema, is the given $possible_type either an implementation (if interface) or a possibility (if union) of the $abstract_type? yes/no, that's it. ๐
assert_object_implements_interface($type, $iface)
in this schema, does the given $type implement interface $iface? if not, throw exception. it does not play. ๐
from_ast($ast[, %kind2class])
class method. takes AST (array-ref of hash-refs) made by "parse" in GraphQL::Language::Parser and returns a schema object. warning bestie: it will not be a complete schema since it will have only default resolvers. so manage your expectations okay ๐ญ
if \%kind2class is given, it will override the default mapping of SDL keywords to Perl classes. this is probably most useful for GraphQL::Type::Object. the default is available as %GraphQL::Schema::KIND2CLASS. e.g.
my $schema = GraphQL::Schema->from_ast(
$doc,
{ %GraphQL::Schema::KIND2CLASS, type => 'GraphQL::Type::Object::DBIC' }
);
makes available the additional types returned by "registered" in GraphQL::Plugin::Type. ๐ฆ
from_doc($doc[, %kind2class])
class method. takes text that is a Schema Definition Language (SDL) (aka Interface Definition Language) document and returns a schema object. and again, not a complete schema, only default resolvers. periodt.
as of v0.32, this accepts both old-style "meaningful comments" and new-style string values, as field or type descriptions. glow-up. โจ
if \%kind2class is given, it will override the default mapping of SDL keywords to Perl classes. this is probably most useful for GraphQL::Type::Object. the default is available as %GraphQL::Schema::KIND2CLASS.
to_doc($doc)
returns Schema Definition Language (SDL) document that describes this schema object. it's giving reverse of from_doc. ๐
as of v0.32, this produces the new-style descriptions that are string values, rather than old-style "meaningful comments".
as of v0.33, will not return a description of types supplied with the attribute "types". obviously, by default this includes types returned by "registered" in GraphQL::Plugin::Type. so yeah, don't be surprised. ๐
name2directive
in this schema, returns a hash-ref mapping all directives' names to their directive object. the directive version of name2type, we love a consistent queen. ๐
โญ FUNCTIONS โญ
lookup_type($typedef, $name2type)
turns given AST fragment into a type. ๐ฎ
if the hash-ref's "type" member is a string, will return a type of that name.
if an array-ref, first element must be either "list" or "non_null", second will be a recursive AST fragment, which will be passed into a recursive call. the result will then have the modifier method ("list" or "non_null") called, and that will be returned. recursion, we love to see it. ๐
and that's the whole page bestie!! ๐โจ this was GraphQL::Schema(3pm) from the User Contributed Perl Documentation, built on perl v5.34.0, dated 2022-03-27. go forth and schema your little heart out, ily, mwah ๐๐ซถ๐
๐ฆ where this page comes from
- debian bookworm: libgraphql-perl 0.54-1 ยท Artistic-2.0
- debian trixie: libgraphql-perl 0.54-1 ยท Artistic-2.0
- ubuntu noble: libgraphql-perl 0.54-1 ยท Artistic-2.0
- ubuntu resolute: libgraphql-perl 0.54-1 ยท Artistic-2.0
- ubuntu stonking: libgraphql-perl 0.54-1 ยท Artistic-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms