mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-11 10:09:24 +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
|
||||
namespace GraphQL\Language\AST;
|
||||
|
||||
interface Value
|
||||
{
|
||||
/**
|
||||
export type Value = Variable
|
||||
| IntValue
|
||||
| FloatValue
|
||||
| StringValue
|
||||
| BooleanValue
|
||||
| EnumValue
|
||||
| ListValue
|
||||
| ObjectValue
|
||||
| IntValue
|
||||
| FloatValue
|
||||
| StringValue
|
||||
| BooleanValue
|
||||
| EnumValue
|
||||
| ListValue
|
||||
| ObjectValue
|
||||
*/
|
||||
interface Value
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -11,12 +11,12 @@ use GraphQL\Utils;
|
||||
class EnumType extends Type implements InputType, OutputType, LeafType
|
||||
{
|
||||
/**
|
||||
* @var array<EnumValueDefinition>
|
||||
* @var EnumValueDefinition[]
|
||||
*/
|
||||
private $values;
|
||||
|
||||
/**
|
||||
* @var \ArrayObject<mixed, EnumValueDefinition>
|
||||
* @var Utils\MixedStore<mixed, EnumValueDefinition>
|
||||
*/
|
||||
private $valueLookup;
|
||||
|
||||
@ -44,11 +44,13 @@ class EnumType extends Type implements InputType, OutputType, LeafType
|
||||
|
||||
if (!empty($config['values'])) {
|
||||
foreach ($config['values'] as $name => $value) {
|
||||
|
||||
if (is_string($value) && is_int($name)) {
|
||||
$value = ['name' => $value, 'value' => $value];
|
||||
if (!is_array($value)) {
|
||||
if (is_string($name)) {
|
||||
$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
|
||||
$this->values[] = new EnumValueDefinition($value + ['name' => $name, 'value' => $name]);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class ObjectType extends Type implements OutputType, CompositeType
|
||||
Config::INTERFACE_TYPE,
|
||||
Config::MAYBE_THUNK
|
||||
),
|
||||
'isTypeOf' => Config::CALLBACK, // ($value, ResolveInfo $info) => boolean
|
||||
'isTypeOf' => Config::CALLBACK, // ($value, $context, ResolveInfo $info) => boolean
|
||||
'resolveField' => Config::CALLBACK
|
||||
]);
|
||||
|
||||
@ -156,6 +156,7 @@ class ObjectType extends Type implements OutputType, CompositeType
|
||||
/**
|
||||
* @param $value
|
||||
* @param $context
|
||||
* @param ResolveInfo $info
|
||||
* @return bool|null
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param $valueAST
|
||||
* @param \GraphQL\Language\AST\Value $valueAST
|
||||
* @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