mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-14 11:33:13 +03:00
Minor comment tweaks + ability to define enum values as simple k=>v pairs
This commit is contained in:
parent
3ba187ec04
commit
2369454687
@ -1,16 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace GraphQL\Language\AST;
|
namespace GraphQL\Language\AST;
|
||||||
|
|
||||||
interface Value
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
export type Value = Variable
|
export type Value = Variable
|
||||||
| IntValue
|
| IntValue
|
||||||
| FloatValue
|
| FloatValue
|
||||||
| StringValue
|
| StringValue
|
||||||
| BooleanValue
|
| BooleanValue
|
||||||
| EnumValue
|
| EnumValue
|
||||||
| ListValue
|
| ListValue
|
||||||
| ObjectValue
|
| ObjectValue
|
||||||
*/
|
*/
|
||||||
|
interface Value
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,12 @@ use GraphQL\Utils;
|
|||||||
class EnumType extends Type implements InputType, OutputType, LeafType
|
class EnumType extends Type implements InputType, OutputType, LeafType
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array<EnumValueDefinition>
|
* @var EnumValueDefinition[]
|
||||||
*/
|
*/
|
||||||
private $values;
|
private $values;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ArrayObject<mixed, EnumValueDefinition>
|
* @var Utils\MixedStore<mixed, EnumValueDefinition>
|
||||||
*/
|
*/
|
||||||
private $valueLookup;
|
private $valueLookup;
|
||||||
|
|
||||||
@ -44,11 +44,13 @@ class EnumType extends Type implements InputType, OutputType, LeafType
|
|||||||
|
|
||||||
if (!empty($config['values'])) {
|
if (!empty($config['values'])) {
|
||||||
foreach ($config['values'] as $name => $value) {
|
foreach ($config['values'] as $name => $value) {
|
||||||
|
if (!is_array($value)) {
|
||||||
if (is_string($value) && is_int($name)) {
|
if (is_string($name)) {
|
||||||
$value = ['name' => $value, 'value' => $value];
|
$value = ['name' => $name, 'value' => $value];
|
||||||
|
} else if (is_int($name) && is_string($value)) {
|
||||||
|
$value = ['name' => $value, 'value' => $value];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// value will be equal to name only if 'value' is not set in definition
|
// value will be equal to name only if 'value' is not set in definition
|
||||||
$this->values[] = new EnumValueDefinition($value + ['name' => $name, 'value' => $name]);
|
$this->values[] = new EnumValueDefinition($value + ['name' => $name, 'value' => $name]);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ class ObjectType extends Type implements OutputType, CompositeType
|
|||||||
Config::INTERFACE_TYPE,
|
Config::INTERFACE_TYPE,
|
||||||
Config::MAYBE_THUNK
|
Config::MAYBE_THUNK
|
||||||
),
|
),
|
||||||
'isTypeOf' => Config::CALLBACK, // ($value, ResolveInfo $info) => boolean
|
'isTypeOf' => Config::CALLBACK, // ($value, $context, ResolveInfo $info) => boolean
|
||||||
'resolveField' => Config::CALLBACK
|
'resolveField' => Config::CALLBACK
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -156,6 +156,7 @@ class ObjectType extends Type implements OutputType, CompositeType
|
|||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
* @param $context
|
* @param $context
|
||||||
|
* @param ResolveInfo $info
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function isTypeOf($value, $context, ResolveInfo $info)
|
public function isTypeOf($value, $context, ResolveInfo $info)
|
||||||
|
@ -50,8 +50,8 @@ abstract class ScalarType extends Type implements OutputType, InputType, LeafTyp
|
|||||||
/**
|
/**
|
||||||
* Parses an externally provided literal value to use as an input
|
* Parses an externally provided literal value to use as an input
|
||||||
*
|
*
|
||||||
* @param $valueAST
|
* @param \GraphQL\Language\AST\Value $valueAST
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
abstract public function parseLiteral(/* GraphQL\Language\AST\Value */$valueAST);
|
abstract public function parseLiteral($valueAST);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user