DocReader.php 953 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Framework\GraphQlSchemaStitching\GraphQlReader\MetaReader;
  8. /**
  9. * Reads documentation from the annotation @doc of an AST node
  10. */
  11. class DocReader
  12. {
  13. /**
  14. * Read documentation annotation for a specific node if exists
  15. *
  16. * @param \GraphQL\Language\AST\NodeList $directives
  17. * @return string
  18. */
  19. public function read(\GraphQL\Language\AST\NodeList $directives) : string
  20. {
  21. foreach ($directives as $directive) {
  22. if ($directive->name->value == 'doc') {
  23. foreach ($directive->arguments as $directiveArgument) {
  24. if ($directiveArgument->name->value == 'description') {
  25. return $directiveArgument->value->value;
  26. }
  27. }
  28. }
  29. }
  30. return '';
  31. }
  32. }