/** * @param AbstractType $type * @param null|string $name * @param array $config * @option string connectionFields * * @return ObjectType */ public static function connectionDefinition(AbstractType $type, $name = null, $config = []) { $name = $name ?: $type->getName(); $connectionFields = !empty($config['connectionFields']) ? $config['connectionFields'] : []; $connectionType = new ObjectType(['name' => $name . 'Connection', 'description' => 'A connection to a list of items.', 'fields' => array_merge(['pageInfo' => ['type' => new NonNullType(self::getPageInfoType()), 'description' => 'Information to aid in pagination.', 'resolve' => [__CLASS__, 'getPageInfo']], 'edges' => ['type' => new ListType(self::edgeDefinition($type, $name, $config)), 'description' => 'A list of edges.', 'resolve' => [__CLASS__, 'getEdges']]], $connectionFields)]); return $connectionType; }
public function assertTypeInUnionTypes(AbstractType $type, AbstractUnionType $unionType) { foreach ($unionType->getTypes() as $unionTypeItem) { if ($unionTypeItem->getName() == $type->getName()) { return; } } throw new ResolveException(sprintf('Type "%s" not exist in types of "%s"', $type->getName(), $unionType->getName())); }
private function getVariableReferenceArgumentValue(VariableReference $variableReference, AbstractType $argumentType, Request $request) { $variable = $variableReference->getVariable(); if ($argumentType->getKind() == TypeMap::KIND_LIST) { if ($variable->getTypeName() != $argumentType->getNamedType()->getName() || !$variable->isArray()) { throw new ResolveException(sprintf('Invalid variable "%s" type, allowed type is "%s"', $variable->getName(), $argumentType->getName()), $variable->getLocation()); } } else { if ($variable->getTypeName() != $argumentType->getName()) { throw new ResolveException(sprintf('Invalid variable "%s" type, allowed type is "%s"', $variable->getName(), $argumentType->getName()), $variable->getLocation()); } } $requestValue = $request->getVariable($variable->getName()); if (!$request->hasVariable($variable->getName()) || null === $requestValue && $variable->isNullable()) { throw new ResolveException(sprintf('Variable "%s" does not exist in request', $variable->getName()), $variable->getLocation()); } return $requestValue; }