lighthouse: [Lumen] Working with relations - Call to undefined function Nuwave\Lighthouse\resolve()
Hi all,
I’m trying to get relations working following the video tutorial (and any other info I can find), but I keep getting the following error: Call to undefined function Nuwave\Lighthouse\resolve()
I have the following configuration in place (simple Room -> Comments relation): App\GraphQL\Schemas\pms.graphql
type Room {
id: ID! @globalId
name: String
available: String
reference: String
details: String
location: String
comments: [Comment!]! @hasMany
}
type Comment {
id: ID! @globalId
reference: String
title: String
content: String
created_at: DateTime
room: Room! @belongsTo
}
App\GraphQL\Queries\Rooms.php
<?php
namespace App\GraphQL\Queries;
use Nuwave\Lighthouse\Support\Schema\GraphQLResolver;
use Illuminate\Auth\Access\AuthorizationException;
use App\Models\Room\Room;
class Rooms extends GraphQLResolver
{
public function resolve()
{
if(!$this->context || !$this->context->user){
throw new AuthorizationException('Unauthorized');
return null;
}
// query
$roomsQuery = Room::query();
return $roomsQuery
->where('reference', 'NOT LIKE', '%9999')
->orderBy('lft')
->get()
;
}
}
App\GraphQL\schema.graphql
#import ./Schemas/pms.graphql
scalar DateTime @scalar(class: "DateTime")
type ResponsesPayload {
success: Boolean!
msg: String
payload: String
}
type Query @group(middleware: ["auth:api", "scopes:graphql"]) {
rooms: [Room!]!
}
As soon as I try the following query, I get the forementioned error
query getRooms {
rooms {
id
name
available
comments {
reference
title
content
}
}
}
I’m probably overlooking something obvious here… I still have some other questions related to this:
- how do I declare a different model name in the .graphql type definition? (eg. I have a App\Model\Room\Comment and a App\Model\Booking\Comment model) -> can I add eg
type Comment @model(model: "App\\Models\\Room\\Comment") { ... } - how should I go about structuring the various graphql files? I can’t seem to define multiple
Queryentries when I try to separate them into different files - how can I learn the ins and outs about the various schema elements? I went through the various test files to look for examples but I couldn’t find eg. the uses of the
@modeldirective - when creating Query classes, should I extend
GraphQLResolverorGraphQLQuery
Thanks again for this great library, I hope I can get rolling with it very soon!
Kind regards,
Erik
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 28 (28 by maintainers)
Hey @4levels,
From the looks of the error it seems that Lighthouse doesn’t know where to look to get the initial set of rooms. You just need to add a
@fieldto theQuerytype like so:The namespace argument isn’t required
As for the other questions
interfacewith the nameCommentand name the othersRoomCommentandBookingCommentor just rename the two.Querytype in different files like so:@modelis only used if you are using Relay with theNodequery, which allows you to resolve any node just by using it’s globalId.Hope that helps!