Sorry, i'm fairly new to graphQL and lighthouse. I'm not sure if this is a bug, or if i missed something in the docs. I used the default paginator resolver and queries worked fine. However i needed to add some parameters, so followed the documentation to build my own... builder. Two of my fields have custom types. There is no problem when using the default paginator, but using my custom builder, i get errors like this
Expected a value of type "ViewingRequestStatus" but received: 3
i'm thinking this has something to do with using the regular DB Builder instead of the eloquent one, but the paginator requires the regular DB builder.
Schema
type ViewingRequest @model(class: "\\AppViewingRequestRead"){
uuid: String!
requestorUuid: String!
scheduleUuid: String!
districtUuid: String!
congregationUuid: String!
siteUuid: String
status: ViewingRequestStatus
language: Languages
user_uuid: String
streamEventUuid: String!
}
type Languages{
name: String
id: Int
}
extend type Query {
viewingRequests(
streamEventUuid: String,
scheduleUuid: String,
requestorUuid: String
): [ViewingRequest!]! @paginate(model: "App\\ViewingRequestRead", builder: "App\\ViewingRequestRead@showRequests")
}
App\ViewingRequestRead
class ViewingRequestRead extends IncRead
{
protected $enumCasts = [
'status' => ViewingRequestStatus::class,
'language' => Languages::class,
];
protected $casts = [
'status' => 'int',
'language' => 'int'
];
public function showRequests($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Builder
{
return DB::table('viewing_requests')
->when(key_exists("streamEventUuid", $args), function ($q) use ($args) {
return $q->where('streamEventUuid', '=', $args["streamEventUuid"]);
})->when(key_exists("scheduleUuid", $args), function ($q) use ($args) {
return $q->where('scheduleUuid', '=', $args["scheduleUuid"]);
})->when(key_exists("requestorUuid", $args), function ($q) use ($args) {
return $q->where('requestorUuid', '=', $args["requestorUuid"]);
});
ViewingRequestEnum (IncEnum Extends BenSampo\Enum\Enum) as noted in lighthouse docs.
<?php
namespace App\Enums;
use App\Enums\IncEnum;
final class ViewingRequestStatus extends IncEnum
{
const Archived = 0;
const New = 1;
const LocaleSubmitted = 2;
const DistrictSubmitted = 3;
const LocaleApproved = 4;
const DistrictApproved = 5;
const CentralApproved = 6;
const Cancelled = 7;
const Denied = 8;
const Draft = 9;
}
This is registered via GraphQlServiceProvider.
Output/Logs
Click to expand
"debugMessage" => "Expected a value of type "Languages" but received: 1"
"message" => "Internal server error"
"extensions" => array:1 [
"category" => "internal"
]
"locations" => array:1 [
0 => array:2 [
"line" => 8
"column" => 21
]
]
"path" => array:4 [
0 => "viewingRequests"
1 => "data"
2 => 2
3 => "language"
Environment
Lighthouse Version: 4.11.0 Laravel Version: 7.5.1