-
-
Notifications
You must be signed in to change notification settings - Fork 466
Closed
Labels
needs reproductionFailing test case neededFailing test case needed
Description
What problem does this feature proposal attempt to solve?
Let's say for example I have a user avatar filepath in the database, something like image_path. Now let's say I'd like to set image_pathvalue to null, based on the current Upload scalar, it is not possible for null to be passed as the value without an exception being thrown.
Which possible solutions should be considered?
Update the current Upload scalar to accept null as a value or create a new scalar such as NullableUpload to fill this edgecase.
Example argument (using upload directive from PR #2121):
image: NullableUpload @upload(path:"images/avatars/candidates") @rename(attribute: "image_path")Example scalar:
final class NullableUpload extends ScalarType
{
/**
* This always throws, as the Upload scalar can only be used as an argument.
*
* @throws InvariantViolation
*/
public function serialize($value): void
{
throw new InvariantViolation(
'"Upload" cannot be serialized, it can only be used as an argument.'
);
}
/**
* Parse a externally provided variable value into a Carbon instance.
*
* @throws Error
*/
public function parseValue($value): UploadedFile
{
if ($value !== null && !$value instanceof UploadedFile) {
throw new Error(
'Could not get uploaded file, be sure to conform to GraphQL multipart request specification: https://github.com/jaydenseric/graphql-multipart-request-spec Instead got: ' . Utils::printSafe($value)
);
}
return $value;
}
/**
* This always throws, as the Upload scalar must be used with a multipart form request.
*
* @param \GraphQL\Language\AST\Node $valueNode
* @param array<string, mixed>|null $variables
*
* @throws Error
*/
public function parseLiteral($valueNode, array $variables = null): void
{
throw new Error(
'"Upload" cannot be hardcoded in a query. Be sure to conform to the GraphQL multipart request specification: https://github.com/jaydenseric/graphql-multipart-request-spec'
);
}
}Metadata
Metadata
Assignees
Labels
needs reproductionFailing test case neededFailing test case needed