@@ -84,7 +84,7 @@ |
||
| 84 | 84 | new GraphQLField( |
| 85 | 85 | 'currencySign', |
| 86 | 86 | 'String', |
| 87 | - 'currency_sign',__('Currency Sign', 'event_espresso') |
|
| 87 | + 'currency_sign', __('Currency Sign', 'event_espresso') |
|
| 88 | 88 | ), |
| 89 | 89 | new GraphQLField( |
| 90 | 90 | 'currencySignBeforeNumber', |
@@ -18,99 +18,99 @@ |
||
| 18 | 18 | class Country extends TypeBase |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Country constructor. |
|
| 23 | - * |
|
| 24 | - * @param EEM_Country $country_model |
|
| 25 | - */ |
|
| 26 | - public function __construct(EEM_Country $country_model) |
|
| 27 | - { |
|
| 28 | - $this->model = $country_model; |
|
| 29 | - $this->setName('Country'); |
|
| 30 | - $this->setDescription(__('A country', 'event_espresso')); |
|
| 31 | - $this->setIsCustomPostType(false); |
|
| 32 | - parent::__construct(); |
|
| 33 | - } |
|
| 21 | + /** |
|
| 22 | + * Country constructor. |
|
| 23 | + * |
|
| 24 | + * @param EEM_Country $country_model |
|
| 25 | + */ |
|
| 26 | + public function __construct(EEM_Country $country_model) |
|
| 27 | + { |
|
| 28 | + $this->model = $country_model; |
|
| 29 | + $this->setName('Country'); |
|
| 30 | + $this->setDescription(__('A country', 'event_espresso')); |
|
| 31 | + $this->setIsCustomPostType(false); |
|
| 32 | + parent::__construct(); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return GraphQLFieldInterface[] |
|
| 38 | - * @since $VID:$ |
|
| 39 | - */ |
|
| 40 | - public function getFields() |
|
| 41 | - { |
|
| 42 | - return [ |
|
| 43 | - new GraphQLField( |
|
| 44 | - 'isActive', |
|
| 45 | - 'Boolean', |
|
| 46 | - null, // 'active', |
|
| 47 | - esc_html__('Flag that indicates if the country should appear in dropdown select lists', 'event_espresso') |
|
| 48 | - ), |
|
| 49 | - new GraphQLField( |
|
| 50 | - 'ISO', |
|
| 51 | - 'String', |
|
| 52 | - null, //'ISO', |
|
| 53 | - esc_html__('Country ISO Code', 'event_espresso') |
|
| 54 | - ), |
|
| 55 | - new GraphQLField( |
|
| 56 | - 'ISO3', |
|
| 57 | - 'String', |
|
| 58 | - null, //'ISO3', |
|
| 59 | - esc_html__('Country ISO3 Code', 'event_espresso') |
|
| 60 | - ), |
|
| 61 | - new GraphQLField( |
|
| 62 | - 'name', |
|
| 63 | - 'String', |
|
| 64 | - 'name', |
|
| 65 | - esc_html__('Country Name', 'event_espresso') |
|
| 66 | - ), |
|
| 67 | - new GraphQLField( |
|
| 68 | - 'currencyCode', |
|
| 69 | - 'String', |
|
| 70 | - 'currency_code', |
|
| 71 | - esc_html__('Country Currency Code', 'event_espresso') |
|
| 72 | - ), |
|
| 73 | - new GraphQLField( |
|
| 74 | - 'currencySingular', |
|
| 75 | - 'String', |
|
| 76 | - 'currency_name_single', |
|
| 77 | - esc_html__('Currency Name Singular', 'event_espresso') |
|
| 78 | - ), |
|
| 79 | - new GraphQLField( |
|
| 80 | - 'currencyPlural', |
|
| 81 | - 'String', |
|
| 82 | - 'currency_name_plural', |
|
| 83 | - esc_html__('Currency Name Plural', 'event_espresso') |
|
| 84 | - ), |
|
| 85 | - new GraphQLField( |
|
| 86 | - 'currencySign', |
|
| 87 | - 'String', |
|
| 88 | - 'currency_sign',__('Currency Sign', 'event_espresso') |
|
| 89 | - ), |
|
| 90 | - new GraphQLField( |
|
| 91 | - 'currencySignBeforeNumber', |
|
| 92 | - 'String', |
|
| 93 | - 'currency_sign_before', |
|
| 94 | - esc_html__('Currency Sign Before Number', 'event_espresso') |
|
| 95 | - ), |
|
| 96 | - new GraphQLField( |
|
| 97 | - 'currencyDecimalPlaces', |
|
| 98 | - 'String', |
|
| 99 | - 'currency_decimal_places', |
|
| 100 | - esc_html__('Currency Decimal Places', 'event_espresso') |
|
| 101 | - ), |
|
| 102 | - new GraphQLField( |
|
| 103 | - 'currencyDecimalMark', |
|
| 104 | - 'String', |
|
| 105 | - 'currency_decimal_mark', |
|
| 106 | - esc_html__('Currency Decimal Mark', 'event_espresso') |
|
| 107 | - ), |
|
| 108 | - new GraphQLField( |
|
| 109 | - 'currencyThousandsSeparator', |
|
| 110 | - 'String', |
|
| 111 | - 'currency_thousands_separator', |
|
| 112 | - esc_html__('Currency Thousands Separator', 'event_espresso') |
|
| 113 | - ), |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 36 | + /** |
|
| 37 | + * @return GraphQLFieldInterface[] |
|
| 38 | + * @since $VID:$ |
|
| 39 | + */ |
|
| 40 | + public function getFields() |
|
| 41 | + { |
|
| 42 | + return [ |
|
| 43 | + new GraphQLField( |
|
| 44 | + 'isActive', |
|
| 45 | + 'Boolean', |
|
| 46 | + null, // 'active', |
|
| 47 | + esc_html__('Flag that indicates if the country should appear in dropdown select lists', 'event_espresso') |
|
| 48 | + ), |
|
| 49 | + new GraphQLField( |
|
| 50 | + 'ISO', |
|
| 51 | + 'String', |
|
| 52 | + null, //'ISO', |
|
| 53 | + esc_html__('Country ISO Code', 'event_espresso') |
|
| 54 | + ), |
|
| 55 | + new GraphQLField( |
|
| 56 | + 'ISO3', |
|
| 57 | + 'String', |
|
| 58 | + null, //'ISO3', |
|
| 59 | + esc_html__('Country ISO3 Code', 'event_espresso') |
|
| 60 | + ), |
|
| 61 | + new GraphQLField( |
|
| 62 | + 'name', |
|
| 63 | + 'String', |
|
| 64 | + 'name', |
|
| 65 | + esc_html__('Country Name', 'event_espresso') |
|
| 66 | + ), |
|
| 67 | + new GraphQLField( |
|
| 68 | + 'currencyCode', |
|
| 69 | + 'String', |
|
| 70 | + 'currency_code', |
|
| 71 | + esc_html__('Country Currency Code', 'event_espresso') |
|
| 72 | + ), |
|
| 73 | + new GraphQLField( |
|
| 74 | + 'currencySingular', |
|
| 75 | + 'String', |
|
| 76 | + 'currency_name_single', |
|
| 77 | + esc_html__('Currency Name Singular', 'event_espresso') |
|
| 78 | + ), |
|
| 79 | + new GraphQLField( |
|
| 80 | + 'currencyPlural', |
|
| 81 | + 'String', |
|
| 82 | + 'currency_name_plural', |
|
| 83 | + esc_html__('Currency Name Plural', 'event_espresso') |
|
| 84 | + ), |
|
| 85 | + new GraphQLField( |
|
| 86 | + 'currencySign', |
|
| 87 | + 'String', |
|
| 88 | + 'currency_sign',__('Currency Sign', 'event_espresso') |
|
| 89 | + ), |
|
| 90 | + new GraphQLField( |
|
| 91 | + 'currencySignBeforeNumber', |
|
| 92 | + 'String', |
|
| 93 | + 'currency_sign_before', |
|
| 94 | + esc_html__('Currency Sign Before Number', 'event_espresso') |
|
| 95 | + ), |
|
| 96 | + new GraphQLField( |
|
| 97 | + 'currencyDecimalPlaces', |
|
| 98 | + 'String', |
|
| 99 | + 'currency_decimal_places', |
|
| 100 | + esc_html__('Currency Decimal Places', 'event_espresso') |
|
| 101 | + ), |
|
| 102 | + new GraphQLField( |
|
| 103 | + 'currencyDecimalMark', |
|
| 104 | + 'String', |
|
| 105 | + 'currency_decimal_mark', |
|
| 106 | + esc_html__('Currency Decimal Mark', 'event_espresso') |
|
| 107 | + ), |
|
| 108 | + new GraphQLField( |
|
| 109 | + 'currencyThousandsSeparator', |
|
| 110 | + 'String', |
|
| 111 | + 'currency_thousands_separator', |
|
| 112 | + esc_html__('Currency Thousands Separator', 'event_espresso') |
|
| 113 | + ), |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @param EEM_Datetime $model |
| 16 | 16 | * @param Datetime $type |
| 17 | - * @return callable |
|
| 17 | + * @return \Closure |
|
| 18 | 18 | */ |
| 19 | 19 | public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
| 20 | 20 | { |
@@ -12,8 +12,8 @@ |
||
| 12 | 12 | /** |
| 13 | 13 | * Defines the mutation data modification closure. |
| 14 | 14 | * |
| 15 | - * @param EEM_Datetime $model |
|
| 16 | - * @param Datetime $type |
|
| 15 | + * @param EEM_Datetime $model |
|
| 16 | + * @param Datetime $type |
|
| 17 | 17 | * @return callable |
| 18 | 18 | */ |
| 19 | 19 | public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
@@ -5,13 +5,11 @@ |
||
| 5 | 5 | use EE_Datetime; |
| 6 | 6 | use EventEspresso\core\domain\services\graphql\types\Datetime; |
| 7 | 7 | use EventEspresso\core\domain\services\graphql\data\mutations\DatetimeMutation; |
| 8 | - |
|
| 9 | 8 | use EE_Error; |
| 10 | 9 | use InvalidArgumentException; |
| 11 | 10 | use ReflectionException; |
| 12 | 11 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 13 | 12 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 14 | - |
|
| 15 | 13 | use GraphQL\Type\Definition\ResolveInfo; |
| 16 | 14 | use WPGraphQL\AppContext; |
| 17 | 15 | use GraphQL\Error\UserError; |
@@ -42,15 +42,15 @@ discard block |
||
| 42 | 42 | * @throws InvalidDataTypeException |
| 43 | 43 | * @throws EE_Error |
| 44 | 44 | */ |
| 45 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) |
|
| 45 | + return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) |
|
| 46 | 46 | { |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Stop now if a user isn't allowed to create a datetime. |
| 50 | 50 | */ |
| 51 | - if (! current_user_can('ee_edit_events')) { |
|
| 51 | + if ( ! current_user_can('ee_edit_events')) { |
|
| 52 | 52 | // translators: the %1$s is the name of the object being mutated |
| 53 | - throw new UserError(sprintf(__('Sorry, you are not allowed to create %1$s', 'event_espresso' ), $type->name())); |
|
| 53 | + throw new UserError(sprintf(__('Sorry, you are not allowed to create %1$s', 'event_espresso'), $type->name())); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $args = DatetimeMutation::prepare_fields($input); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $id = $entity->save(); |
| 60 | 60 | |
| 61 | 61 | if (empty($id)) { |
| 62 | - throw new UserError(__( 'The object failed to create but no error was provided', 'event_espresso')); |
|
| 62 | + throw new UserError(__('The object failed to create but no error was provided', 'event_espresso')); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return [ |
@@ -243,7 +243,7 @@ |
||
| 243 | 243 | * @param mixed $payload The payload returned after mutation |
| 244 | 244 | * @param array $args The inputArgs on the field |
| 245 | 245 | * @param AppContext $context The AppContext passed down the GraphQL tree |
| 246 | - * @return string |
|
| 246 | + * @return null|EE_Base_Class |
|
| 247 | 247 | * @throws EE_Error |
| 248 | 248 | * @throws InvalidDataTypeException |
| 249 | 249 | * @throws InvalidInterfaceException |
@@ -29,235 +29,235 @@ |
||
| 29 | 29 | abstract class TypeBase implements TypeInterface |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var EEM_Base $model |
|
| 34 | - */ |
|
| 35 | - protected $model; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var string $name |
|
| 39 | - */ |
|
| 40 | - protected $name = ''; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var string $description |
|
| 44 | - */ |
|
| 45 | - protected $description = ''; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] $fields |
|
| 49 | - */ |
|
| 50 | - protected $fields = []; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var array $graphql_to_model_map |
|
| 54 | - */ |
|
| 55 | - protected $graphql_to_model_map = []; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var FieldResolver $field_resolver |
|
| 59 | - */ |
|
| 60 | - protected $field_resolver; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var bool $is_custom_post_type |
|
| 64 | - */ |
|
| 65 | - protected $is_custom_post_type = false; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * TypeBase constructor. |
|
| 69 | - */ |
|
| 70 | - public function __construct() |
|
| 71 | - { |
|
| 72 | - $this->setFields($this->getFields()); |
|
| 73 | - $this->field_resolver = new FieldResolver( |
|
| 74 | - $this->model, |
|
| 75 | - $this->getFieldsForResolver() |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
| 82 | - * @since $VID:$ |
|
| 83 | - */ |
|
| 84 | - abstract protected function getFields(); |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function name() |
|
| 91 | - { |
|
| 92 | - return $this->name; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param string $name |
|
| 98 | - */ |
|
| 99 | - protected function setName($name) |
|
| 100 | - { |
|
| 101 | - $this->name = $name; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function description() |
|
| 109 | - { |
|
| 110 | - return $this->description; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param string $description |
|
| 116 | - */ |
|
| 117 | - protected function setDescription($description) |
|
| 118 | - { |
|
| 119 | - $this->description = $description; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
| 125 | - * @since $VID:$ |
|
| 126 | - */ |
|
| 127 | - public function fields() |
|
| 128 | - { |
|
| 129 | - return (array) $this->fields; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] $fields |
|
| 135 | - */ |
|
| 136 | - protected function setFields(array $fields) |
|
| 137 | - { |
|
| 138 | - foreach ($fields as $field) { |
|
| 139 | - if ($field instanceof GraphQLField) { |
|
| 140 | - $this->fields[] = $field; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Creates a key map for internal resolver. |
|
| 148 | - * @return array |
|
| 149 | - * @since $VID:$ |
|
| 150 | - */ |
|
| 151 | - public function getFieldsForResolver() |
|
| 152 | - { |
|
| 153 | - $fields = []; |
|
| 154 | - foreach ($this->fields() as $field) { |
|
| 155 | - if ($field->useForOutput()) { |
|
| 156 | - $fields[$field->name()] = $field; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - return $fields; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @return bool |
|
| 165 | - */ |
|
| 166 | - public function isCustomPostType() |
|
| 167 | - { |
|
| 168 | - return $this->is_custom_post_type; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @param bool $is_custom_post_type |
|
| 174 | - */ |
|
| 175 | - protected function setIsCustomPostType($is_custom_post_type) |
|
| 176 | - { |
|
| 177 | - $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @param int $value |
|
| 183 | - * @return int |
|
| 184 | - * @since $VID:$ |
|
| 185 | - */ |
|
| 186 | - public function parseInfiniteValue($value) |
|
| 187 | - { |
|
| 188 | - $value = trim($value); |
|
| 189 | - return $value === null |
|
| 190 | - || $value === '' |
|
| 191 | - || $value === '∞' |
|
| 192 | - || $value === 'INF' |
|
| 193 | - || $value === INF |
|
| 194 | - || $value === EE_INF |
|
| 195 | - || is_infinite((float) $value) |
|
| 196 | - ? -1 |
|
| 197 | - : $value; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @param mixed $source |
|
| 203 | - * @return EE_Base_Class|null |
|
| 204 | - * @since $VID:$ |
|
| 205 | - */ |
|
| 206 | - private function getModel($source) |
|
| 207 | - { |
|
| 208 | - // If it comes from a custom connection |
|
| 209 | - // where the $source is already instantiated. |
|
| 210 | - if ($source instanceof EE_Base_Class) { |
|
| 211 | - return $source; |
|
| 212 | - } |
|
| 213 | - return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
| 219 | - * @param array $args The inputArgs on the field |
|
| 220 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 221 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 222 | - * @return string |
|
| 223 | - * @throws EE_Error |
|
| 224 | - * @throws InvalidDataTypeException |
|
| 225 | - * @throws InvalidInterfaceException |
|
| 226 | - * @throws UnexpectedEntityException |
|
| 227 | - * @throws UserError |
|
| 228 | - * @throws InvalidArgumentException |
|
| 229 | - * @throws ReflectionException |
|
| 230 | - * @since $VID:$ |
|
| 231 | - */ |
|
| 232 | - public function resolveField($source, $args, AppContext $context, ResolveInfo $info) |
|
| 233 | - { |
|
| 234 | - $source = $this->getModel($source); |
|
| 235 | - if ($source instanceof EE_Base_Class) { |
|
| 236 | - return $this->field_resolver->resolve($source, $args, $context, $info); |
|
| 237 | - } |
|
| 238 | - return null; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param mixed $payload The payload returned after mutation |
|
| 244 | - * @param array $args The inputArgs on the field |
|
| 245 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 246 | - * @return string |
|
| 247 | - * @throws EE_Error |
|
| 248 | - * @throws InvalidDataTypeException |
|
| 249 | - * @throws InvalidInterfaceException |
|
| 250 | - * @throws UnexpectedEntityException |
|
| 251 | - * @throws UserError |
|
| 252 | - * @throws InvalidArgumentException |
|
| 253 | - * @throws ReflectionException |
|
| 254 | - * @since $VID:$ |
|
| 255 | - */ |
|
| 256 | - public function resolveFromPayload($payload, $args, AppContext $context) |
|
| 257 | - { |
|
| 258 | - if ( empty( $payload['id'] ) || ! absint( $payload['id'] ) ) { |
|
| 259 | - return null; |
|
| 260 | - } |
|
| 261 | - return $this->model->get_one_by_ID($payload['id']); |
|
| 262 | - } |
|
| 32 | + /** |
|
| 33 | + * @var EEM_Base $model |
|
| 34 | + */ |
|
| 35 | + protected $model; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var string $name |
|
| 39 | + */ |
|
| 40 | + protected $name = ''; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var string $description |
|
| 44 | + */ |
|
| 45 | + protected $description = ''; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] $fields |
|
| 49 | + */ |
|
| 50 | + protected $fields = []; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var array $graphql_to_model_map |
|
| 54 | + */ |
|
| 55 | + protected $graphql_to_model_map = []; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var FieldResolver $field_resolver |
|
| 59 | + */ |
|
| 60 | + protected $field_resolver; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var bool $is_custom_post_type |
|
| 64 | + */ |
|
| 65 | + protected $is_custom_post_type = false; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * TypeBase constructor. |
|
| 69 | + */ |
|
| 70 | + public function __construct() |
|
| 71 | + { |
|
| 72 | + $this->setFields($this->getFields()); |
|
| 73 | + $this->field_resolver = new FieldResolver( |
|
| 74 | + $this->model, |
|
| 75 | + $this->getFieldsForResolver() |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
| 82 | + * @since $VID:$ |
|
| 83 | + */ |
|
| 84 | + abstract protected function getFields(); |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function name() |
|
| 91 | + { |
|
| 92 | + return $this->name; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param string $name |
|
| 98 | + */ |
|
| 99 | + protected function setName($name) |
|
| 100 | + { |
|
| 101 | + $this->name = $name; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function description() |
|
| 109 | + { |
|
| 110 | + return $this->description; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param string $description |
|
| 116 | + */ |
|
| 117 | + protected function setDescription($description) |
|
| 118 | + { |
|
| 119 | + $this->description = $description; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
| 125 | + * @since $VID:$ |
|
| 126 | + */ |
|
| 127 | + public function fields() |
|
| 128 | + { |
|
| 129 | + return (array) $this->fields; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] $fields |
|
| 135 | + */ |
|
| 136 | + protected function setFields(array $fields) |
|
| 137 | + { |
|
| 138 | + foreach ($fields as $field) { |
|
| 139 | + if ($field instanceof GraphQLField) { |
|
| 140 | + $this->fields[] = $field; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Creates a key map for internal resolver. |
|
| 148 | + * @return array |
|
| 149 | + * @since $VID:$ |
|
| 150 | + */ |
|
| 151 | + public function getFieldsForResolver() |
|
| 152 | + { |
|
| 153 | + $fields = []; |
|
| 154 | + foreach ($this->fields() as $field) { |
|
| 155 | + if ($field->useForOutput()) { |
|
| 156 | + $fields[$field->name()] = $field; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + return $fields; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @return bool |
|
| 165 | + */ |
|
| 166 | + public function isCustomPostType() |
|
| 167 | + { |
|
| 168 | + return $this->is_custom_post_type; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @param bool $is_custom_post_type |
|
| 174 | + */ |
|
| 175 | + protected function setIsCustomPostType($is_custom_post_type) |
|
| 176 | + { |
|
| 177 | + $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @param int $value |
|
| 183 | + * @return int |
|
| 184 | + * @since $VID:$ |
|
| 185 | + */ |
|
| 186 | + public function parseInfiniteValue($value) |
|
| 187 | + { |
|
| 188 | + $value = trim($value); |
|
| 189 | + return $value === null |
|
| 190 | + || $value === '' |
|
| 191 | + || $value === '∞' |
|
| 192 | + || $value === 'INF' |
|
| 193 | + || $value === INF |
|
| 194 | + || $value === EE_INF |
|
| 195 | + || is_infinite((float) $value) |
|
| 196 | + ? -1 |
|
| 197 | + : $value; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @param mixed $source |
|
| 203 | + * @return EE_Base_Class|null |
|
| 204 | + * @since $VID:$ |
|
| 205 | + */ |
|
| 206 | + private function getModel($source) |
|
| 207 | + { |
|
| 208 | + // If it comes from a custom connection |
|
| 209 | + // where the $source is already instantiated. |
|
| 210 | + if ($source instanceof EE_Base_Class) { |
|
| 211 | + return $source; |
|
| 212 | + } |
|
| 213 | + return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
| 219 | + * @param array $args The inputArgs on the field |
|
| 220 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 221 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 222 | + * @return string |
|
| 223 | + * @throws EE_Error |
|
| 224 | + * @throws InvalidDataTypeException |
|
| 225 | + * @throws InvalidInterfaceException |
|
| 226 | + * @throws UnexpectedEntityException |
|
| 227 | + * @throws UserError |
|
| 228 | + * @throws InvalidArgumentException |
|
| 229 | + * @throws ReflectionException |
|
| 230 | + * @since $VID:$ |
|
| 231 | + */ |
|
| 232 | + public function resolveField($source, $args, AppContext $context, ResolveInfo $info) |
|
| 233 | + { |
|
| 234 | + $source = $this->getModel($source); |
|
| 235 | + if ($source instanceof EE_Base_Class) { |
|
| 236 | + return $this->field_resolver->resolve($source, $args, $context, $info); |
|
| 237 | + } |
|
| 238 | + return null; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param mixed $payload The payload returned after mutation |
|
| 244 | + * @param array $args The inputArgs on the field |
|
| 245 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 246 | + * @return string |
|
| 247 | + * @throws EE_Error |
|
| 248 | + * @throws InvalidDataTypeException |
|
| 249 | + * @throws InvalidInterfaceException |
|
| 250 | + * @throws UnexpectedEntityException |
|
| 251 | + * @throws UserError |
|
| 252 | + * @throws InvalidArgumentException |
|
| 253 | + * @throws ReflectionException |
|
| 254 | + * @since $VID:$ |
|
| 255 | + */ |
|
| 256 | + public function resolveFromPayload($payload, $args, AppContext $context) |
|
| 257 | + { |
|
| 258 | + if ( empty( $payload['id'] ) || ! absint( $payload['id'] ) ) { |
|
| 259 | + return null; |
|
| 260 | + } |
|
| 261 | + return $this->model->get_one_by_ID($payload['id']); |
|
| 262 | + } |
|
| 263 | 263 | } |
| 264 | 264 | \ No newline at end of file |
@@ -255,7 +255,7 @@ |
||
| 255 | 255 | */ |
| 256 | 256 | public function resolveFromPayload($payload, $args, AppContext $context) |
| 257 | 257 | { |
| 258 | - if ( empty( $payload['id'] ) || ! absint( $payload['id'] ) ) { |
|
| 258 | + if (empty($payload['id']) || ! absint($payload['id'])) { |
|
| 259 | 259 | return null; |
| 260 | 260 | } |
| 261 | 261 | return $this->model->get_one_by_ID($payload['id']); |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | /** |
| 28 | 28 | * TypesManager constructor. |
| 29 | 29 | * |
| 30 | - * @param TypeCollection|TypeInterface[] $types |
|
| 30 | + * @param TypeCollection $types |
|
| 31 | 31 | */ |
| 32 | 32 | public function __construct(TypeCollection $types) |
| 33 | 33 | { |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | $config = $field->toArray(); |
| 76 | 76 | if ($field->useForInput()) { |
| 77 | 77 | // Register input fields for existing mutations. |
| 78 | - register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
| 79 | - register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
| 78 | + register_graphql_field('Update'.$typeName.'Input', $fieldName, $config); |
|
| 79 | + register_graphql_field('Create'.$typeName.'Input', $fieldName, $config); |
|
| 80 | 80 | } |
| 81 | 81 | if ($field->useForOutput()) { |
| 82 | 82 | $config['resolve'] = [$type, 'resolveField']; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | $typeName = $type->name(); |
| 110 | - if (! empty($outputFields)) { |
|
| 110 | + if ( ! empty($outputFields)) { |
|
| 111 | 111 | // Register the object type. |
| 112 | 112 | register_graphql_object_type( |
| 113 | 113 | $typeName, |
@@ -18,110 +18,110 @@ |
||
| 18 | 18 | class TypesManager |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var TypeCollection|TypeInterface[] $types |
|
| 23 | - */ |
|
| 24 | - private $types; |
|
| 21 | + /** |
|
| 22 | + * @var TypeCollection|TypeInterface[] $types |
|
| 23 | + */ |
|
| 24 | + private $types; |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * TypesManager constructor. |
|
| 29 | - * |
|
| 30 | - * @param TypeCollection|TypeInterface[] $types |
|
| 31 | - */ |
|
| 32 | - public function __construct(TypeCollection $types) |
|
| 33 | - { |
|
| 34 | - $this->types = $types; |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * TypesManager constructor. |
|
| 29 | + * |
|
| 30 | + * @param TypeCollection|TypeInterface[] $types |
|
| 31 | + */ |
|
| 32 | + public function __construct(TypeCollection $types) |
|
| 33 | + { |
|
| 34 | + $this->types = $types; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @throws CollectionDetailsException |
|
| 40 | - * @throws CollectionLoaderException |
|
| 41 | - * @since $VID:$ |
|
| 42 | - */ |
|
| 43 | - public function init() |
|
| 44 | - { |
|
| 45 | - $this->types->loadTypes(); |
|
| 46 | - add_action('graphql_register_types', [$this, 'configureTypes'], 10); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * @throws CollectionDetailsException |
|
| 40 | + * @throws CollectionLoaderException |
|
| 41 | + * @since $VID:$ |
|
| 42 | + */ |
|
| 43 | + public function init() |
|
| 44 | + { |
|
| 45 | + $this->types->loadTypes(); |
|
| 46 | + add_action('graphql_register_types', [$this, 'configureTypes'], 10); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @since $VID:$ |
|
| 52 | - */ |
|
| 53 | - public function configureTypes() |
|
| 54 | - { |
|
| 55 | - // loop through the collection of types and register their fields |
|
| 56 | - foreach ($this->types as $type) { |
|
| 57 | - if ($type->isCustomPostType()) { |
|
| 58 | - $this->extendCustomPostType($type); |
|
| 59 | - } else { |
|
| 60 | - $this->registerType($type); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 50 | + /** |
|
| 51 | + * @since $VID:$ |
|
| 52 | + */ |
|
| 53 | + public function configureTypes() |
|
| 54 | + { |
|
| 55 | + // loop through the collection of types and register their fields |
|
| 56 | + foreach ($this->types as $type) { |
|
| 57 | + if ($type->isCustomPostType()) { |
|
| 58 | + $this->extendCustomPostType($type); |
|
| 59 | + } else { |
|
| 60 | + $this->registerType($type); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param TypeInterface $type |
|
| 68 | - * @since $VID:$ |
|
| 69 | - */ |
|
| 70 | - public function extendCustomPostType(TypeInterface $type) |
|
| 71 | - { |
|
| 72 | - $typeName = $type->name(); |
|
| 73 | - foreach ($type->fields() as $field) { |
|
| 74 | - $fieldName = $field->name(); |
|
| 75 | - $config = $field->toArray(); |
|
| 76 | - if ($field->useForInput()) { |
|
| 77 | - // Register input fields for existing mutations. |
|
| 78 | - register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
| 79 | - register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
| 80 | - } |
|
| 81 | - if ($field->useForOutput()) { |
|
| 82 | - $config['resolve'] = [$type, 'resolveField']; |
|
| 83 | - // Register fields for queries. |
|
| 84 | - register_graphql_field($typeName, $fieldName, $config); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - if (is_callable([$type, 'extendMutations'])) { |
|
| 88 | - $type->extendMutations(); |
|
| 89 | - } |
|
| 90 | - } |
|
| 66 | + /** |
|
| 67 | + * @param TypeInterface $type |
|
| 68 | + * @since $VID:$ |
|
| 69 | + */ |
|
| 70 | + public function extendCustomPostType(TypeInterface $type) |
|
| 71 | + { |
|
| 72 | + $typeName = $type->name(); |
|
| 73 | + foreach ($type->fields() as $field) { |
|
| 74 | + $fieldName = $field->name(); |
|
| 75 | + $config = $field->toArray(); |
|
| 76 | + if ($field->useForInput()) { |
|
| 77 | + // Register input fields for existing mutations. |
|
| 78 | + register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
| 79 | + register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
| 80 | + } |
|
| 81 | + if ($field->useForOutput()) { |
|
| 82 | + $config['resolve'] = [$type, 'resolveField']; |
|
| 83 | + // Register fields for queries. |
|
| 84 | + register_graphql_field($typeName, $fieldName, $config); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + if (is_callable([$type, 'extendMutations'])) { |
|
| 88 | + $type->extendMutations(); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @param TypeInterface $type |
|
| 95 | - * @since $VID:$ |
|
| 96 | - */ |
|
| 97 | - public function registerType(TypeInterface $type) |
|
| 98 | - { |
|
| 99 | - $outputFields = []; |
|
| 100 | - $inputFields = []; |
|
| 101 | - foreach ($type->fields() as $field) { |
|
| 102 | - $fieldName = $field->name(); |
|
| 103 | - $config = $field->toArray(); |
|
| 104 | - if ($field->useForInput()) { |
|
| 105 | - $inputFields[$fieldName] = $config; |
|
| 106 | - } |
|
| 107 | - if ($field->useForOutput()) { |
|
| 108 | - $config['resolve'] = [$type, 'resolveField']; |
|
| 109 | - $outputFields[$fieldName] = $config; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - $typeName = $type->name(); |
|
| 113 | - if (! empty($outputFields)) { |
|
| 114 | - // Register the object type. |
|
| 115 | - register_graphql_object_type( |
|
| 116 | - $typeName, |
|
| 117 | - [ |
|
| 118 | - 'description' => $type->description(), |
|
| 119 | - 'fields' => $outputFields, |
|
| 120 | - ] |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - if (is_callable([$type, 'registerMutations'])) { |
|
| 124 | - $type->registerMutations($inputFields); |
|
| 125 | - } |
|
| 126 | - } |
|
| 93 | + /** |
|
| 94 | + * @param TypeInterface $type |
|
| 95 | + * @since $VID:$ |
|
| 96 | + */ |
|
| 97 | + public function registerType(TypeInterface $type) |
|
| 98 | + { |
|
| 99 | + $outputFields = []; |
|
| 100 | + $inputFields = []; |
|
| 101 | + foreach ($type->fields() as $field) { |
|
| 102 | + $fieldName = $field->name(); |
|
| 103 | + $config = $field->toArray(); |
|
| 104 | + if ($field->useForInput()) { |
|
| 105 | + $inputFields[$fieldName] = $config; |
|
| 106 | + } |
|
| 107 | + if ($field->useForOutput()) { |
|
| 108 | + $config['resolve'] = [$type, 'resolveField']; |
|
| 109 | + $outputFields[$fieldName] = $config; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + $typeName = $type->name(); |
|
| 113 | + if (! empty($outputFields)) { |
|
| 114 | + // Register the object type. |
|
| 115 | + register_graphql_object_type( |
|
| 116 | + $typeName, |
|
| 117 | + [ |
|
| 118 | + 'description' => $type->description(), |
|
| 119 | + 'fields' => $outputFields, |
|
| 120 | + ] |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + if (is_callable([$type, 'registerMutations'])) { |
|
| 124 | + $type->registerMutations($inputFields); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -18,40 +18,40 @@ |
||
| 18 | 18 | class ConnectionsManager |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var ConnectionCollection|ConnectionInterface[] $connections |
|
| 23 | - */ |
|
| 24 | - private $connections; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * ConnectionsManager constructor. |
|
| 29 | - * |
|
| 30 | - * @param ConnectionCollection|ConnectionInterface[] $connections |
|
| 31 | - */ |
|
| 32 | - public function __construct(ConnectionCollection $connections) |
|
| 33 | - { |
|
| 34 | - $this->connections = $connections; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @throws CollectionDetailsException |
|
| 40 | - * @throws CollectionLoaderException |
|
| 41 | - * @since $VID:$ |
|
| 42 | - */ |
|
| 43 | - public function init() |
|
| 44 | - { |
|
| 45 | - $this->connections->loadConnections(); |
|
| 46 | - add_action('graphql_register_types', [$this, 'registerConnections'], 20); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - public function registerConnections() |
|
| 51 | - { |
|
| 52 | - // loop through the collection of types and register their fields |
|
| 53 | - foreach ($this->connections as $connection) { |
|
| 54 | - register_graphql_connection($connection->config()); |
|
| 55 | - } |
|
| 56 | - } |
|
| 21 | + /** |
|
| 22 | + * @var ConnectionCollection|ConnectionInterface[] $connections |
|
| 23 | + */ |
|
| 24 | + private $connections; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * ConnectionsManager constructor. |
|
| 29 | + * |
|
| 30 | + * @param ConnectionCollection|ConnectionInterface[] $connections |
|
| 31 | + */ |
|
| 32 | + public function __construct(ConnectionCollection $connections) |
|
| 33 | + { |
|
| 34 | + $this->connections = $connections; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @throws CollectionDetailsException |
|
| 40 | + * @throws CollectionLoaderException |
|
| 41 | + * @since $VID:$ |
|
| 42 | + */ |
|
| 43 | + public function init() |
|
| 44 | + { |
|
| 45 | + $this->connections->loadConnections(); |
|
| 46 | + add_action('graphql_register_types', [$this, 'registerConnections'], 20); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + public function registerConnections() |
|
| 51 | + { |
|
| 52 | + // loop through the collection of types and register their fields |
|
| 53 | + foreach ($this->connections as $connection) { |
|
| 54 | + register_graphql_connection($connection->config()); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | \ No newline at end of file |
@@ -25,79 +25,79 @@ |
||
| 25 | 25 | interface TypeInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function name(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function description(); |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
| 42 | - * @since $VID:$ |
|
| 43 | - */ |
|
| 44 | - public function fields(); |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Creates a key map for internal resolver. |
|
| 49 | - * |
|
| 50 | - * @return array |
|
| 51 | - * @since $VID:$ |
|
| 52 | - */ |
|
| 53 | - public function getFieldsForResolver(); |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - public function isCustomPostType(); |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param int $value |
|
| 64 | - * @return int |
|
| 65 | - * @since $VID:$ |
|
| 66 | - */ |
|
| 67 | - public function parseInfiniteValue($value); |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
| 72 | - * @param array $args The inputArgs on the field |
|
| 73 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 74 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 75 | - * @return string |
|
| 76 | - * @throws EE_Error |
|
| 77 | - * @throws InvalidDataTypeException |
|
| 78 | - * @throws InvalidInterfaceException |
|
| 79 | - * @throws UnexpectedEntityException |
|
| 80 | - * @throws UserError |
|
| 81 | - * @throws InvalidArgumentException |
|
| 82 | - * @throws ReflectionException |
|
| 83 | - * @since $VID:$ |
|
| 84 | - */ |
|
| 85 | - public function resolveField($source, $args, AppContext $context, ResolveInfo $info); |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param mixed $payload The payload returned after mutation |
|
| 90 | - * @param array $args The inputArgs on the field |
|
| 91 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 92 | - * @return string |
|
| 93 | - * @throws EE_Error |
|
| 94 | - * @throws InvalidDataTypeException |
|
| 95 | - * @throws InvalidInterfaceException |
|
| 96 | - * @throws UnexpectedEntityException |
|
| 97 | - * @throws UserError |
|
| 98 | - * @throws InvalidArgumentException |
|
| 99 | - * @throws ReflectionException |
|
| 100 | - * @since $VID:$ |
|
| 101 | - */ |
|
| 102 | - public function resolveFromPayload($payload, $args, AppContext $context); |
|
| 28 | + /** |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function name(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function description(); |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
| 42 | + * @since $VID:$ |
|
| 43 | + */ |
|
| 44 | + public function fields(); |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Creates a key map for internal resolver. |
|
| 49 | + * |
|
| 50 | + * @return array |
|
| 51 | + * @since $VID:$ |
|
| 52 | + */ |
|
| 53 | + public function getFieldsForResolver(); |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + public function isCustomPostType(); |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param int $value |
|
| 64 | + * @return int |
|
| 65 | + * @since $VID:$ |
|
| 66 | + */ |
|
| 67 | + public function parseInfiniteValue($value); |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
| 72 | + * @param array $args The inputArgs on the field |
|
| 73 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 74 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 75 | + * @return string |
|
| 76 | + * @throws EE_Error |
|
| 77 | + * @throws InvalidDataTypeException |
|
| 78 | + * @throws InvalidInterfaceException |
|
| 79 | + * @throws UnexpectedEntityException |
|
| 80 | + * @throws UserError |
|
| 81 | + * @throws InvalidArgumentException |
|
| 82 | + * @throws ReflectionException |
|
| 83 | + * @since $VID:$ |
|
| 84 | + */ |
|
| 85 | + public function resolveField($source, $args, AppContext $context, ResolveInfo $info); |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param mixed $payload The payload returned after mutation |
|
| 90 | + * @param array $args The inputArgs on the field |
|
| 91 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 92 | + * @return string |
|
| 93 | + * @throws EE_Error |
|
| 94 | + * @throws InvalidDataTypeException |
|
| 95 | + * @throws InvalidInterfaceException |
|
| 96 | + * @throws UnexpectedEntityException |
|
| 97 | + * @throws UserError |
|
| 98 | + * @throws InvalidArgumentException |
|
| 99 | + * @throws ReflectionException |
|
| 100 | + * @since $VID:$ |
|
| 101 | + */ |
|
| 102 | + public function resolveFromPayload($payload, $args, AppContext $context); |
|
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -21,86 +21,86 @@ |
||
| 21 | 21 | class TypeCollection extends Collection |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - const COLLECTION_NAME = 'espresso_graphql_types'; |
|
| 24 | + const COLLECTION_NAME = 'espresso_graphql_types'; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var CollectionLoader $loader |
|
| 28 | - */ |
|
| 29 | - protected $loader; |
|
| 26 | + /** |
|
| 27 | + * @var CollectionLoader $loader |
|
| 28 | + */ |
|
| 29 | + protected $loader; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * TypeCollection constructor |
|
| 33 | - * |
|
| 34 | - * @throws InvalidInterfaceException |
|
| 35 | - */ |
|
| 36 | - public function __construct() |
|
| 37 | - { |
|
| 38 | - parent::__construct( |
|
| 39 | - 'EventEspresso\core\services\graphql\types\TypeInterface', |
|
| 40 | - TypeCollection::COLLECTION_NAME |
|
| 41 | - ); |
|
| 42 | - } |
|
| 31 | + /** |
|
| 32 | + * TypeCollection constructor |
|
| 33 | + * |
|
| 34 | + * @throws InvalidInterfaceException |
|
| 35 | + */ |
|
| 36 | + public function __construct() |
|
| 37 | + { |
|
| 38 | + parent::__construct( |
|
| 39 | + 'EventEspresso\core\services\graphql\types\TypeInterface', |
|
| 40 | + TypeCollection::COLLECTION_NAME |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @throws CollectionDetailsException |
|
| 47 | - * @throws CollectionLoaderException |
|
| 48 | - * @since $VID:$ |
|
| 49 | - */ |
|
| 50 | - private function loadCollection() |
|
| 51 | - { |
|
| 52 | - if (! $this->loader instanceof CollectionLoader) { |
|
| 53 | - $this->loader = new CollectionLoader( |
|
| 54 | - new CollectionDetails( |
|
| 55 | - // collection name |
|
| 56 | - TypeCollection::COLLECTION_NAME, |
|
| 57 | - // collection interface |
|
| 58 | - 'EventEspresso\core\services\graphql\types\TypeInterface', |
|
| 59 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
| 60 | - apply_filters( |
|
| 61 | - 'FHEE__EventEspresso_core_services_graphql_TypeCollection__loadCollection__collection_FQCNs', |
|
| 62 | - ['EventEspresso\core\domain\services\graphql\types'] |
|
| 63 | - ), |
|
| 64 | - // filepaths to classes to add |
|
| 65 | - array(), |
|
| 66 | - // file mask to use if parsing folder for files to add |
|
| 67 | - '', |
|
| 68 | - // what to use as identifier for collection entities |
|
| 69 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
| 70 | - CollectionDetails::ID_CLASS_NAME |
|
| 71 | - ), |
|
| 72 | - $this |
|
| 73 | - ); |
|
| 74 | - } |
|
| 75 | - } |
|
| 45 | + /** |
|
| 46 | + * @throws CollectionDetailsException |
|
| 47 | + * @throws CollectionLoaderException |
|
| 48 | + * @since $VID:$ |
|
| 49 | + */ |
|
| 50 | + private function loadCollection() |
|
| 51 | + { |
|
| 52 | + if (! $this->loader instanceof CollectionLoader) { |
|
| 53 | + $this->loader = new CollectionLoader( |
|
| 54 | + new CollectionDetails( |
|
| 55 | + // collection name |
|
| 56 | + TypeCollection::COLLECTION_NAME, |
|
| 57 | + // collection interface |
|
| 58 | + 'EventEspresso\core\services\graphql\types\TypeInterface', |
|
| 59 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
| 60 | + apply_filters( |
|
| 61 | + 'FHEE__EventEspresso_core_services_graphql_TypeCollection__loadCollection__collection_FQCNs', |
|
| 62 | + ['EventEspresso\core\domain\services\graphql\types'] |
|
| 63 | + ), |
|
| 64 | + // filepaths to classes to add |
|
| 65 | + array(), |
|
| 66 | + // file mask to use if parsing folder for files to add |
|
| 67 | + '', |
|
| 68 | + // what to use as identifier for collection entities |
|
| 69 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
| 70 | + CollectionDetails::ID_CLASS_NAME |
|
| 71 | + ), |
|
| 72 | + $this |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @return CollectionInterface |
|
| 80 | - * @throws CollectionDetailsException |
|
| 81 | - * @throws CollectionLoaderException |
|
| 82 | - * @since $VID:$ |
|
| 83 | - */ |
|
| 84 | - public function loadTypes() |
|
| 85 | - { |
|
| 86 | - $this->loadCollection(); |
|
| 87 | - return $this->loader->getCollection(); |
|
| 88 | - } |
|
| 78 | + /** |
|
| 79 | + * @return CollectionInterface |
|
| 80 | + * @throws CollectionDetailsException |
|
| 81 | + * @throws CollectionLoaderException |
|
| 82 | + * @since $VID:$ |
|
| 83 | + */ |
|
| 84 | + public function loadTypes() |
|
| 85 | + { |
|
| 86 | + $this->loadCollection(); |
|
| 87 | + return $this->loader->getCollection(); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * getIdentifier |
|
| 93 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
| 94 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
| 95 | - * |
|
| 96 | - * @param $object |
|
| 97 | - * @param mixed $identifier |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 100 | - public function getIdentifier($object, $identifier = null) |
|
| 101 | - { |
|
| 102 | - return ! empty($identifier) |
|
| 103 | - ? $identifier |
|
| 104 | - : get_class($object); |
|
| 105 | - } |
|
| 91 | + /** |
|
| 92 | + * getIdentifier |
|
| 93 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
| 94 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
| 95 | + * |
|
| 96 | + * @param $object |
|
| 97 | + * @param mixed $identifier |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | + public function getIdentifier($object, $identifier = null) |
|
| 101 | + { |
|
| 102 | + return ! empty($identifier) |
|
| 103 | + ? $identifier |
|
| 104 | + : get_class($object); |
|
| 105 | + } |
|
| 106 | 106 | } |
| 107 | 107 | \ No newline at end of file |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | private function loadCollection() |
| 51 | 51 | { |
| 52 | - if (! $this->loader instanceof CollectionLoader) { |
|
| 52 | + if ( ! $this->loader instanceof CollectionLoader) { |
|
| 53 | 53 | $this->loader = new CollectionLoader( |
| 54 | 54 | new CollectionDetails( |
| 55 | 55 | // collection name |
@@ -16,34 +16,34 @@ |
||
| 16 | 16 | class GraphQLOutputField extends GraphQLField |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 19 | + /** |
|
| 20 | 20 | * @param string $name |
| 21 | 21 | * @param string|string[] $type |
| 22 | - * @param string|null $key |
|
| 23 | - * @param string $description |
|
| 24 | - * @param callable|null $formatter |
|
| 25 | - * @param callable|null $resolver |
|
| 26 | - * @param array $caps |
|
| 27 | - */ |
|
| 28 | - public function __construct( |
|
| 22 | + * @param string|null $key |
|
| 23 | + * @param string $description |
|
| 24 | + * @param callable|null $formatter |
|
| 25 | + * @param callable|null $resolver |
|
| 26 | + * @param array $caps |
|
| 27 | + */ |
|
| 28 | + public function __construct( |
|
| 29 | 29 | $name, |
| 30 | - $type, |
|
| 31 | - $key = null, |
|
| 32 | - $description = '', |
|
| 33 | - callable $formatter = null, |
|
| 34 | - callable $resolver = null, |
|
| 35 | - array $caps = [] |
|
| 36 | - ) { |
|
| 37 | - parent::__construct( |
|
| 38 | - $name, |
|
| 39 | - $type, |
|
| 40 | - $key, |
|
| 41 | - $description, |
|
| 42 | - $formatter, |
|
| 43 | - $resolver, |
|
| 44 | - $caps |
|
| 45 | - ); |
|
| 30 | + $type, |
|
| 31 | + $key = null, |
|
| 32 | + $description = '', |
|
| 33 | + callable $formatter = null, |
|
| 34 | + callable $resolver = null, |
|
| 35 | + array $caps = [] |
|
| 36 | + ) { |
|
| 37 | + parent::__construct( |
|
| 38 | + $name, |
|
| 39 | + $type, |
|
| 40 | + $key, |
|
| 41 | + $description, |
|
| 42 | + $formatter, |
|
| 43 | + $resolver, |
|
| 44 | + $caps |
|
| 45 | + ); |
|
| 46 | 46 | |
| 47 | - $this->setUseForInput(false); |
|
| 48 | - } |
|
| 47 | + $this->setUseForInput(false); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -16,30 +16,30 @@ |
||
| 16 | 16 | class GraphQLInputField extends GraphQLField |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 19 | + /** |
|
| 20 | 20 | * @param string $name |
| 21 | 21 | * @param string|string[] $type |
| 22 | - * @param string|null $key |
|
| 23 | - * @param string $description |
|
| 24 | - * @param array $caps |
|
| 25 | - */ |
|
| 26 | - public function __construct( |
|
| 22 | + * @param string|null $key |
|
| 23 | + * @param string $description |
|
| 24 | + * @param array $caps |
|
| 25 | + */ |
|
| 26 | + public function __construct( |
|
| 27 | 27 | $name, |
| 28 | - $type, |
|
| 29 | - $key = null, |
|
| 30 | - $description = '', |
|
| 31 | - array $caps = [] |
|
| 32 | - ) { |
|
| 33 | - parent::__construct( |
|
| 34 | - $name, |
|
| 35 | - $type, |
|
| 36 | - $key, |
|
| 37 | - $description, |
|
| 38 | - null, |
|
| 39 | - null, |
|
| 40 | - $caps |
|
| 41 | - ); |
|
| 28 | + $type, |
|
| 29 | + $key = null, |
|
| 30 | + $description = '', |
|
| 31 | + array $caps = [] |
|
| 32 | + ) { |
|
| 33 | + parent::__construct( |
|
| 34 | + $name, |
|
| 35 | + $type, |
|
| 36 | + $key, |
|
| 37 | + $description, |
|
| 38 | + null, |
|
| 39 | + null, |
|
| 40 | + $caps |
|
| 41 | + ); |
|
| 42 | 42 | |
| 43 | - $this->setUseForOutput(false); |
|
| 44 | - } |
|
| 43 | + $this->setUseForOutput(false); |
|
| 44 | + } |
|
| 45 | 45 | } |