WooCommerce Code Reference

ObjectType extends Type
in package
implements OutputType, CompositeType, NullableType, HasFieldsType, NamedType, ImplementingType Uses HasFieldsTypeImplementation, NamedTypeImplementation, ImplementingTypeImplementation

Object Type Definition.

Most Automattic\WooCommerce\Vendor\GraphQL types you define will be object types. Object types have a name, but most importantly describe their fields.

Example:

$AddressType = new ObjectType([
    'name' => 'Address',
    'fields' => [
        'street' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type::string(),
        'number' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type::int(),
        'formatted' => [
            'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type::string(),
            'resolve' => fn (AddressModel $address): string => "{$address->number} {$address->street}",
        ],
    ],
]);

When two types need to refer to each other, or a type needs to refer to itself in a field, you can use a function expression (aka a closure or a thunk) to supply the fields lazily.

Example:

$PersonType = null;
$PersonType = new ObjectType([
    'name' => 'Person',
    'fields' => fn (): array => [
        'name' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type::string(),
        'bestFriend' => $PersonType,
    ],
]);
Tags
phpstan-import-type

FieldResolver from Executor

phpstan-import-type

ArgsMapper from Executor

phpstan-type

InterfaceTypeReference InterfaceType|callable(): InterfaceType

phpstan-type

ObjectConfig array{ name?: string|null, description?: string|null, resolveField?: FieldResolver|null, argsMapper?: ArgsMapper|null, fields: (callable(): iterable)|iterable, interfaces?: iterable|callable(): iterable, isTypeOf?: (callable(mixed $objectValue, mixed $context, ResolveInfo $resolveInfo): (bool|Deferred|null))|null, astNode?: ObjectTypeDefinitionNode|null, extensionASTNodes?: array|null }

Interfaces, Classes and Traits

OutputType
CompositeType
NullableType
HasFieldsType
NamedType
export type NamedType = | ScalarType | ObjectType | InterfaceType | UnionType | EnumType | InputObjectType;.
ImplementingType
export type GraphQLImplementingType = GraphQLObjectType | GraphQLInterfaceType;.

Table of Contents

BOOLEAN  = 'Boolean'
BUILT_IN_SCALAR_NAMES  = [self::INT, self::FLOAT, self::STRING, self::BOOLEAN, self::ID]
BUILT_IN_TYPE_NAMES  = [...self::BUILT_IN_SCALAR_NAMES, ...AutomatticWooCommerceVendorGraphQLTypeIntrospection::TYPE_NAMES]
Names of all built-in types: built-in scalars and introspection types.
FLOAT  = 'Float'
ID  = 'ID'
INT  = 'Int'
STANDARD_TYPE_NAMES  = self::BUILT_IN_SCALAR_NAMES
STRING  = 'String'
$argsMapper  : callable|null
$astNode  : ObjectTypeDefinitionNode|null
$config  : array<string|int, mixed>
$description  : string|null
$extensionASTNodes  : array<string|int, mixed>
$name  : string
$resolveFieldFn  : callable|null
$builtInScalars  : array<string|int, mixed>|null
$builtInTypes  : array<string|int, mixed>|null
$fields  : array<string|int, mixed>
Lazily initialized.
$interfaces  : array<string|int, mixed>
Lazily initialized.
__construct()  : mixed
__toString()  : string
assertObjectType()  : self
assertValid()  : void
Validates type config and throws if one of the type options is invalid.
astNode()  : (\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node&\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\TypeDefinitionNode)|null
boolean()  : ScalarType
Returns the built-in Boolean scalar type.
builtInScalars()  : array<string, ScalarType>
Returns all built-in scalar types.
builtInTypes()  : array<string, \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type&\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\NamedType>
Returns all built-in types: built-in scalars and introspection types.
description()  : string|null
extensionASTNodes()  : array<string|int, ObjectTypeExtensionNode>
findField()  : FieldDefinition|null
float()  : ScalarType
Returns the built-in Float scalar type.
getField()  : FieldDefinition
getFieldNames()  : array<string|int, mixed>
getFields()  : array<string, FieldDefinition>
getInterfaces()  : array<int, InterfaceType>
getNamedType()  : (\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type&\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\NamedType)|null
Returns the underlying named type of the given type.
getNullableType()  : Type|NullableType
Unwraps a potentially non-null type to return the underlying nullable type.
getStandardTypes()  : array<string, ScalarType>
Returns all built-in scalar types.
getVisibleFields()  : array<string, FieldDefinition>
hasField()  : bool
id()  : ScalarType
Returns the built-in ID scalar type.
implementsInterface()  : bool
int()  : ScalarType
Returns the built-in Int scalar type.
isAbstractType()  : bool
Determines if the given type is an abstract type.
isBuiltInScalar()  : bool
Determines if the given type is a built-in scalar (Int, Float, String, Boolean, ID).
isBuiltInScalarName()  : bool
Checks if the given name is one of the built-in scalar type names (ID, String, Int, Float, Boolean).
isBuiltInType()  : bool
isCompositeType()  : bool
Determines if the given type is a composite type.
isInputType()  : bool
Determines if the given type is an input type.
isLeafType()  : bool
Determines if the given type is a leaf type.
isOutputType()  : bool
Determines if the given type is an output type.
isTypeOf()  : bool|Deferred|null
jsonSerialize()  : string
listOf()  : ListOfType<string|int, T>
Wraps the given type in a list type.
name()  : string
nonNull()  : NonNull
Wraps the given type in a non-null type.
overrideStandardTypes()  : void
Allows partially or completely overriding the standard types globally.
string()  : ScalarType
Returns the built-in String scalar type.
toString()  : string
assertValidInterfaces()  : void
inferName()  : string
initializeFields()  : void
initializeInterfaces()  : void

Constants

BUILT_IN_TYPE_NAMES

Names of all built-in types: built-in scalars and introspection types.

public array<int, string> BUILT_IN_TYPE_NAMES = [...self::BUILT_IN_SCALAR_NAMES, ...AutomatticWooCommerceVendorGraphQLTypeIntrospection::TYPE_NAMES]
Tags
see
Type::BUILT_IN_SCALAR_NAMES

for just the built-in scalar names.

Properties

Methods

astNode()

public astNode() : (\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node&\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\TypeDefinitionNode)|null
Return values
(\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node&\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\TypeDefinitionNode)|null

builtInTypes()

Returns all built-in types: built-in scalars and introspection types.

public static builtInTypes() : array<string, \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type&\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\NamedType>
Return values
array<string, \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type&\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\NamedType>

getNamedType()

Returns the underlying named type of the given type.

public static getNamedType(Type|null $type) : (\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type&\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\NamedType)|null
Parameters
$type : Type|null
Tags
phpstan-return

($type is null ? null : Type&NamedType)

Return values
(\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type&\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\NamedType)|null

isBuiltInScalar()

Determines if the given type is a built-in scalar (Int, Float, String, Boolean, ID).

public static isBuiltInScalar(mixed $type) : bool

Does not unwrap NonNull/List wrappers — checks the type instance directly. ScalarType is a NamedType, so {@see} is unnecessary.

Parameters
$type : mixed
Tags
phpstan-assert-if-true

ScalarType $type

Return values
bool

isBuiltInScalarName()

Checks if the given name is one of the built-in scalar type names (ID, String, Int, Float, Boolean).

public static isBuiltInScalarName(string $name) : bool
Parameters
$name : string
Return values
bool

nonNull()

Wraps the given type in a non-null type.

public static nonNull(NonNull|(\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\NullableType&\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type)|callable $type) : NonNull
Parameters
$type : NonNull|(\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\NullableType&\Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type)|callable
Return values
NonNull