Esempio n. 1
0
 /**
  * Given a variable definition, and any value of input, return a value which
  * adheres to the variable definition, or throw an error.
  *
  * @param Schema $schema
  * @param VariableDefinition $definition
  * @param $input
  *
  * @return array|mixed|null|string
  *
  * @throws \Exception
  */
 protected static function getVariableValue(Schema $schema, VariableDefinition $definition, $input)
 {
     $type = TypeInfo::typeFromAST($schema, $definition->get('type'));
     if (!$type) {
         return NULL;
     }
     if (self::isValidValue($type, $input)) {
         if (!isset($input)) {
             $default = $definition->get('defaultValue');
             if ($default) {
                 return self::coerceValueAST($type, $default);
             }
         }
         return self::coerceValue($type, $input);
     }
     // @todo Fix exception message once printer is ported.
     throw new \Exception(sprintf('Variable $%s expected value of different type.', $definition->get('variable')->get('name')->get('value')));
 }
Esempio n. 2
0
 /**
  * Determines if a fragment is applicable to the given type.
  *
  * @param ExecutionContext $context
  * @param $fragment
  * @param ObjectType $type
  *
  * @return bool
  */
 protected static function doesFragmentConditionMatch(ExecutionContext $context, $fragment, ObjectType $type)
 {
     $typeCondition = $fragment->get('typeCondition');
     if (!$typeCondition) {
         return TRUE;
     }
     $conditionalType = TypeInfo::typeFromAST($context->schema, $typeCondition);
     if ($conditionalType->getName() === $type->getName()) {
         return TRUE;
     }
     if ($conditionalType instanceof InterfaceType || $conditionalType instanceof UnionType) {
         return $conditionalType->isPossibleType($type);
     }
     return FALSE;
 }