-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test to query node type w/o id attribute
- Loading branch information
Showing
4 changed files
with
129 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,62 @@ | ||
<?php | ||
|
||
namespace Nuwave\Lighthouse\Tests\Support\GraphQL\Types; | ||
|
||
use GraphQL; | ||
use GraphQL\Type\Definition\Type; | ||
use Nuwave\Lighthouse\Support\Definition\GraphQLType; | ||
use Nuwave\Lighthouse\Support\Interfaces\RelayType; | ||
use Nuwave\Lighthouse\Tests\Support\Models\Post; | ||
|
||
class PostType extends GraphQLType implements RelayType | ||
{ | ||
/** | ||
* Attributes of type. | ||
* | ||
* @var array | ||
*/ | ||
protected $attributes = [ | ||
'name' => 'Post', | ||
'description' => 'A post that does not have a regular id field.' | ||
]; | ||
|
||
/** | ||
* Get model by id. | ||
* | ||
* Note: When the root 'node' query is called, this method | ||
* will be used to resolve the type by providing the id. | ||
* | ||
* @param mixed $id | ||
* @return mixed | ||
*/ | ||
public function resolveById($id) | ||
{ | ||
return factory(Post::class)->make([ | ||
'post_id' => $id, | ||
'title' => 'Foobar', | ||
]); | ||
} | ||
|
||
/** | ||
* Type fields. | ||
* | ||
* @return array | ||
*/ | ||
public function fields() | ||
{ | ||
return [ | ||
'title' => [ | ||
'type' => Type::string(), | ||
'description' => 'Title of the post.' | ||
], | ||
'content' => [ | ||
'type' => Type::string(), | ||
'description' => 'Content of the post.' | ||
], | ||
'user_id' => [ | ||
'type' => Type::int(), | ||
'description' => 'ID of user who wrote the post.' | ||
] | ||
]; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Nuwave\Lighthouse\Tests\Support\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Nuwave\Lighthouse\Support\Traits\RelayModel; | ||
|
||
class Post extends Model | ||
{ | ||
use RelayModel; | ||
|
||
/** | ||
* The primary key for the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $primaryKey = 'post_id'; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'title', 'content', 'user_id', | ||
]; | ||
} |