상속: implements TypeInterface
예제 #1
0
 /**
  * @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;
 }
예제 #2
0
 public function resolveOfType(AbstractType $value)
 {
     if ($value instanceof CompositeTypeInterface) {
         return $value->getTypeOf();
     }
     return null;
 }
예제 #3
0
 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()));
 }
예제 #4
0
 /**
  * Entry point for the `walkQuery` routine.  Execution bounces between here, where the reducer's ->visit() method
  * is invoked, and `walkQuery` where we send in the scores from the `visit` call.
  *
  * @param Query                $query
  * @param AbstractType         $currentLevelSchema
  * @param AbstractQueryVisitor $reducer
  */
 protected function doVisit(Query $query, $currentLevelSchema, $reducer)
 {
     if (!$currentLevelSchema instanceof AbstractObjectType || !$currentLevelSchema->hasField($query->getName())) {
         return;
     }
     if ($operationField = $currentLevelSchema->getField($query->getName())) {
         $coroutine = $this->walkQuery($query, $operationField);
         if ($results = $coroutine->current()) {
             $queryCost = 0;
             while ($results) {
                 // initial values come from advancing the generator via ->current, subsequent values come from ->send()
                 list($queryField, $astField, $childCost) = $results;
                 /**
                  * @var Query|FieldAst $queryField
                  * @var Field          $astField
                  */
                 $cost = $reducer->visit($queryField->getKeyValueArguments(), $astField->getConfig(), $childCost);
                 $queryCost += $cost;
                 $results = $coroutine->send($cost);
             }
         }
     }
 }
예제 #5
0
 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;
 }