Automattic\WooCommerce\Vendor\GraphQL\Utils
TypeInfo::extractTypes
Given root type scans through all fields to find nested types.
Returns array where keys are for type name and value contains corresponding type instance.
Example output: [
'String' => $instanceOfStringType, 'MyType' => $instanceOfMyType, ...
]
Method of the class: TypeInfo{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = TypeInfo::extractTypes( $type, $typeMap ): void;
- $type((Type&NamedType)|(Type&WrappingType)) (required)
- .
- $typeMap(array) (required)
- .
TypeInfo::extractTypes() TypeInfo::extractTypes code WC 10.9.1
public static function extractTypes(Type $type, array &$typeMap): void
{
if ($type instanceof WrappingType) {
self::extractTypes($type->getInnermostType(), $typeMap);
return;
}
$name = $type->name;
assert(is_string($name));
if (isset($typeMap[$name])) {
if ($typeMap[$name] !== $type) {
throw new InvariantViolation("Schema must contain unique named types but contains multiple types named \"{$type}\" (see https://webonyx.github.io/graphql-php/type-definitions/#type-registry).");
}
return;
}
$typeMap[$name] = $type;
if ($type instanceof UnionType) {
foreach ($type->getTypes() as $member) {
self::extractTypes($member, $typeMap);
}
return;
}
if ($type instanceof InputObjectType) {
foreach ($type->getFields() as $field) {
$fieldType = $field->getType();
assert($fieldType instanceof NamedType || $fieldType instanceof WrappingType);
self::extractTypes($fieldType, $typeMap);
}
return;
}
if ($type instanceof ImplementingType) {
foreach ($type->getInterfaces() as $interface) {
self::extractTypes($interface, $typeMap);
}
}
if ($type instanceof HasFieldsType) {
foreach ($type->getFields() as $field) {
foreach ($field->args as $arg) {
$argType = $arg->getType();
assert($argType instanceof NamedType || $argType instanceof WrappingType);
self::extractTypes($argType, $typeMap);
}
$fieldType = $field->getType();
assert($fieldType instanceof NamedType || $fieldType instanceof WrappingType);
self::extractTypes($fieldType, $typeMap);
}
}
}