GraphQL::Type(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::Type πŸ’–

okay bestie, welcome to the GraphQL::Type page β€” it's a Perl module (that's the 3pm vibe, iykyk), and it is literally the blueprint era of the GraphQL type world. sit down, grab a strawberry drink πŸ“, and let's get into it.


✨ SYNOPSIS ✨

like, this is the whole move:

extends qw(GraphQL::Type);

that's it. that's the post. πŸ’…


🌸 DESCRIPTION 🌸

so this is the superclass for all the other GraphQL type classes to inherit from. it's giving mother of the family, main character energy, the one everyone else extends. πŸ‘‘


πŸ¦‹ ENCODING πŸ¦‹

okay so every one of these Perl classes implements a GraphQL type, right? and every single item of GraphQL data has a GraphQL type. and plot twist β€” that same piece of data can also exist inside Perl. so objects of that Perl class are the ones holding it down and translating back and forth between the Perl representation and the "GraphQL representation".

and what even is a "GraphQL representation", you ask? it means something that's JSON-encodeable: an "object" (in Perl terms, a hash), an array (Perl: array-reference), a string, a number, a boolean, or null. the whole roster. 🌈

peep "METHODS" down below for the generic methods that do the back-and-forth between these two worlds.

⚠️ real talk though β€” the code you provide for this translation has to return things that can be JSON-encoded, not things that have already been encoded. which means, among other things: do not wrap your strings in "", and for boolean values use the mechanism in JSON::MaybeXS: JSON-"true> etc. don't do the encoding yourself, bestie, that's not your job. 😭

πŸŽ€ SUBCLASSES πŸŽ€

these subclasses implement part of the GraphQL language specification. objects of these classes implement user-defined types, which is what you use to actually build a GraphQL API. iconic behavior. ✨

  • GraphQL::Type::Enum
  • GraphQL::Type::InputObject
  • GraphQL::Type::Interface
  • GraphQL::Type::List
  • GraphQL::Type::NonNull
  • GraphQL::Type::Object
  • GraphQL::Type::Scalar β€” also implements example types such as "String"
  • GraphQL::Type::Union

🧚 ROLES 🧚

and these roles implement part of the GraphQL language specification too. they get applied to objects of GraphQL::Type classes β€” either to facilitate type constraints, or as noted below. slay. 🫢

  • GraphQL::Role::FieldsInput β€” provides fields attribute for an input type
  • GraphQL::Role::FieldsOutput β€” provides fields attribute for an output type
  • GraphQL::Role::Abstract β€” abstract type
  • GraphQL::Role::Composite β€” type has fields
  • GraphQL::Role::Input β€” type can be an input
  • GraphQL::Role::Leaf β€” simple type β€” enum or scalar
  • GraphQL::Role::Listable β€” can be list-wrapped; provides convenience method
  • GraphQL::Role::Named β€” has a name and description, provided by this role
  • GraphQL::Role::Nullable β€” can be null-valued
  • GraphQL::Role::Output β€” type can be an output

🌟 TYPE LIBRARY 🌟

  • GraphQL::Type::Library β€” implements various Type::Tiny type constraints, for use in Moo attributes, and Function::Parameters/Return::Type methods and functions. very demure, very mindful. πŸ’œ

πŸ‘‘ METHODS πŸ‘‘

πŸ’– uplift

turn given Perl entity into a valid Perl value for this type, if possible. no promises if it's not possible, bestie. πŸ™ˆ

πŸ’– graphql_to_perl

turn given GraphQL entity into a Perl entity. the glow-up, but in reverse. πŸ”₯

πŸ’– perl_to_graphql

turn given Perl entity into a GraphQL entity. the glow-up. πŸ”₯

πŸ’– from_ast($name2type, $ast_node)

class method, okay? so $name2type is a hash-ref populated by "from_ast" in GraphQL::Schema. it takes a hash-ref node from an AST made by "parse" in GraphQL::Language::Parser. returns a type object. that's the whole quest. ⭐

πŸ’– to_doc($doc)

returns a Schema Definition Language (SDL) document that describes this object. it's giving author era, it's giving documentation queen. πŸ“βœ¨


and that's the page, bestie!! πŸ¦‹ this whole thing came to you courtesy of perl v5.34.0, dated 2022-03-27, and yeah it's the GraphQL::Type(3pm) page β€” go forth and type responsibly, ily, mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from