Field.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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\GraphQl\Config\Element;
  8. /**
  9. * Class representing 'field' GraphQL config element.
  10. *
  11. * Fields are used to describe possible values for a type/interface.
  12. */
  13. class Field implements OutputFieldInterface
  14. {
  15. /**
  16. * @var string
  17. */
  18. private $name;
  19. /**
  20. * @var string
  21. */
  22. private $type;
  23. /**
  24. * @var array
  25. */
  26. private $arguments;
  27. /**
  28. * @var bool
  29. */
  30. private $required;
  31. /**
  32. * @var bool
  33. */
  34. private $isList;
  35. /**
  36. * @var string
  37. */
  38. private $resolver;
  39. /**
  40. * @var string
  41. */
  42. private $description;
  43. /**
  44. * @param string $name
  45. * @param string $type
  46. * @param bool $required
  47. * @param bool $isList
  48. * @param string $itemType
  49. * @param string $resolver
  50. * @param string $description
  51. * @param array $arguments
  52. */
  53. public function __construct(
  54. string $name,
  55. string $type,
  56. bool $required,
  57. bool $isList,
  58. string $itemType = '',
  59. string $resolver = '',
  60. string $description = '',
  61. array $arguments = []
  62. ) {
  63. $this->name = $name;
  64. $this->type = $isList ? $itemType : $type;
  65. $this->required = $required;
  66. $this->isList = $isList;
  67. $this->resolver = $resolver;
  68. $this->description = $description;
  69. $this->arguments = $arguments;
  70. }
  71. /**
  72. * Get the field name.
  73. *
  74. * @return string
  75. */
  76. public function getName() : string
  77. {
  78. return $this->name;
  79. }
  80. /**
  81. * Get the type's configured name.
  82. *
  83. * @return string
  84. */
  85. public function getTypeName() : string
  86. {
  87. return $this->type;
  88. }
  89. /**
  90. * Return true if field is a list of items. False otherwise.
  91. *
  92. * @return bool
  93. */
  94. public function isList() : bool
  95. {
  96. return $this->isList;
  97. }
  98. /**
  99. * Return true if the field is required by an input type to be populated. False otherwise.
  100. *
  101. * @return bool
  102. */
  103. public function isRequired() : bool
  104. {
  105. return $this->required;
  106. }
  107. /**
  108. * Get the resolver for a given field. If no resolver is specified, return an empty string.
  109. *
  110. * @return string
  111. */
  112. public function getResolver() : string
  113. {
  114. return $this->resolver;
  115. }
  116. /**
  117. * Get the list of arguments configured for the field. Return an empty array if no arguments are configured.
  118. *
  119. * @return Argument[]
  120. */
  121. public function getArguments() : array
  122. {
  123. return $this->arguments;
  124. }
  125. /**
  126. * Return the human-readable description of the field.
  127. *
  128. * @return string|null
  129. */
  130. public function getDescription() : string
  131. {
  132. return $this->description;
  133. }
  134. }