-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Array fieldtype in GraphQL (#3972)
- Loading branch information
1 parent
f0ac7c6
commit 63c6f26
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Statamic\GraphQL\Types; | ||
|
||
use GraphQL\Language\AST\Node; | ||
use GraphQL\Type\Definition\ScalarType; | ||
use GraphQL\Type\Definition\Type; | ||
use Rebing\GraphQL\Support\Contracts\TypeConvertible; | ||
|
||
class ArrayType extends ScalarType implements TypeConvertible | ||
{ | ||
const NAME = 'Array'; | ||
|
||
public function serialize($value) | ||
{ | ||
return $value; | ||
} | ||
|
||
public function parseValue($value) | ||
{ | ||
return $value; | ||
} | ||
|
||
public function parseLiteral(Node $valueNode, ?array $variables = null) | ||
{ | ||
return $valueNode->value; | ||
} | ||
|
||
public function toType(): Type | ||
{ | ||
return new static(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\GraphQL\Fieldtypes; | ||
|
||
/** @group graphql */ | ||
class ArrFieldtypeTest extends FieldtypeTestCase | ||
{ | ||
/** @test */ | ||
public function it_gets_arrays() | ||
{ | ||
$keyedConfig = ['type' => 'array', 'keys' => ['foo' => 'Foo', 'bar' => 'Bar']]; | ||
$dynamicConfig = ['type' => 'array']; | ||
|
||
$this->createEntryWithFields([ | ||
'keyed' => [ | ||
'value' => ['foo' => 'bar', 'baz' => 'qux'], | ||
'field' => $keyedConfig, | ||
], | ||
'keyed_incomplete' => [ | ||
'value' => ['foo' => 'bar'], | ||
'field' => $keyedConfig, | ||
], | ||
'keyed_undefined' => [ | ||
'value' => null, | ||
'field' => $keyedConfig, | ||
], | ||
'dynamic' => [ | ||
'value' => ['alfa' => 'bravo', 'charlie' => 'delta'], | ||
'field' => $dynamicConfig, | ||
], | ||
'dynamic_undefined' => [ | ||
'value' => null, | ||
'field' => $dynamicConfig, | ||
], | ||
]); | ||
|
||
$this->assertGqlEntryHas('keyed, keyed_incomplete, keyed_undefined, dynamic, dynamic_undefined', [ | ||
'keyed' => ['foo' => 'bar', 'baz' => 'qux'], | ||
'keyed_incomplete' => ['foo' => 'bar'], | ||
'keyed_undefined' => null, | ||
'dynamic' => ['alfa' => 'bravo', 'charlie' => 'delta'], | ||
'dynamic_undefined' => null, | ||
]); | ||
} | ||
} |