GraphQL::Schema(3pm)

๐Ÿ“ฆ
version 0.54 ยท 2 versions
  • 0.54 ยท debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.53 ยท ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– 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