File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 66
77use GraphQL \Error \Error ;
88use GraphQL \Language \AST \Node as ASTNode ;
9+ use GraphQL \Language \AST \StringValueNode ;
910use GraphQL \Type \Definition \ScalarType ;
1011
1112use function base64_decode ;
@@ -23,7 +24,14 @@ class Blob extends ScalarType
2324
2425 public function parseLiteral (ASTNode $ valueNode , array |null $ variables = null ): string
2526 {
26- throw new Error ('Blob fields cannot be parsed literally. ' , $ valueNode );
27+ // @codeCoverageIgnoreStart
28+ if (! $ valueNode instanceof StringValueNode) {
29+ throw new Error ('Query error: Can only parse strings got: ' . $ valueNode ->kind , $ valueNode );
30+ }
31+
32+ // @codeCoverageIgnoreEnd
33+
34+ return $ this ->parseValue ($ valueNode ->value );
2735 }
2836
2937 public function parseValue (mixed $ value ): mixed
Original file line number Diff line number Diff line change @@ -55,12 +55,15 @@ public function testParseValueInvalid(): void
5555
5656 public function testParseLiteral (): void
5757 {
58- $ this ->expectException (Error::class);
58+ $ jsonType = new Blob ();
59+ $ file = file_get_contents (__DIR__ . '/../../../docs/banner.png ' );
60+ $ encoded = base64_encode ($ file );
5961
60- $ jsonType = new Blob ();
6162 $ node = new StringValueNode ([]);
62- $ node ->value = ' search string ' ;
63+ $ node ->value = $ encoded ;
6364 $ result = $ jsonType ->parseLiteral ($ node );
65+
66+ $ this ->assertEquals ($ file , $ result );
6467 }
6568
6669 public function testSerialize (): void
You can’t perform that action at this time.
0 commit comments