Exemplo n.º 1
0
 /**
  * @return array<Directive>
  */
 public function getDirectives()
 {
     if (!$this->_directives) {
         $this->_directives = [Directive::ifDirective(), Directive::unlessDirective()];
     }
     return $this->_directives;
 }
Exemplo n.º 2
0
 /**
  * Determines if a field should be included based on the @include and @skip
  * directives, where @skip has higher precedence than @include.
  *
  * @param ExecutionContext $exeContext
  * @param $directives
  * @return bool
  */
 private static function shouldIncludeNode(ExecutionContext $exeContext, $directives)
 {
     $skipDirective = Directive::skipDirective();
     $includeDirective = Directive::includeDirective();
     /** @var \GraphQL\Language\AST\DirectiveNode $skipNode */
     $skipNode = $directives ? Utils::find($directives, function (\GraphQL\Language\AST\DirectiveNode $directive) use($skipDirective) {
         return $directive->name->value === $skipDirective->name;
     }) : null;
     if ($skipNode) {
         $argValues = Values::getArgumentValues($skipDirective, $skipNode, $exeContext->variableValues);
         if (isset($argValues['if']) && $argValues['if'] === true) {
             return false;
         }
     }
     /** @var \GraphQL\Language\AST\DirectiveNode $includeNode */
     $includeNode = $directives ? Utils::find($directives, function (\GraphQL\Language\AST\DirectiveNode $directive) use($includeDirective) {
         return $directive->name->value === $includeDirective->name;
     }) : null;
     if ($includeNode) {
         $argValues = Values::getArgumentValues($includeDirective, $includeNode, $exeContext->variableValues);
         if (isset($argValues['if']) && $argValues['if'] === false) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * @return array
  */
 public static function getInternalDirectives()
 {
     return array_values(Directive::getInternalDirectives());
 }
Exemplo n.º 4
0
 /**
  * Determines if a field should be included based on the @include and @skip
  * directives, where @skip has higher precedence than @include.
  */
 private static function shouldIncludeNode(ExecutionContext $exeContext, $directives)
 {
     $skipDirective = Directive::skipDirective();
     $includeDirective = Directive::includeDirective();
     /** @var \GraphQL\Language\AST\Directive $skipAST */
     $skipAST = $directives ? Utils::find($directives, function (\GraphQL\Language\AST\Directive $directive) use($skipDirective) {
         return $directive->name->value === $skipDirective->name;
     }) : null;
     if ($skipAST) {
         $argValues = Values::getArgumentValues($skipDirective->args, $skipAST->arguments, $exeContext->variableValues);
         return empty($argValues['if']);
     }
     /** @var \GraphQL\Language\AST\Directive $includeAST */
     $includeAST = $directives ? Utils::find($directives, function (\GraphQL\Language\AST\Directive $directive) use($includeDirective) {
         return $directive->name->value === $includeDirective->name;
     }) : null;
     if ($includeAST) {
         $argValues = Values::getArgumentValues($includeDirective->args, $includeAST->arguments, $exeContext->variableValues);
         return !empty($argValues['if']);
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * @return array<Directive>
  */
 public function getDirectives()
 {
     if (!$this->_directives) {
         $this->_directives = [Directive::includeDirective(), Directive::skipDirective()];
     }
     return $this->_directives;
 }
Exemplo n.º 6
0
 /**
  * Determines if a field should be included based on @if and @unless directives.
  */
 private static function shouldIncludeNode(ExecutionContext $exeContext, $directives)
 {
     $ifDirective = Values::getDirectiveValue(Directive::ifDirective(), $directives, $exeContext->variables);
     if ($ifDirective !== null) {
         return $ifDirective;
     }
     $unlessDirective = Values::getDirectiveValue(Directive::unlessDirective(), $directives, $exeContext->variables);
     if ($unlessDirective !== null) {
         return !$unlessDirective;
     }
     return true;
 }