Skip to content

Commit ab3ed26

Browse files
committed
debug
1 parent 2ff031c commit ab3ed26

11 files changed

+97
-3
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\GraphQL\Mutations;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Validation\ValidationException;
8+
9+
final class DeleteAcount
10+
{
11+
/**
12+
* @param null $_
13+
* @param array{} $args
14+
*/
15+
public function __invoke($_, array $args)
16+
{
17+
// TODO implement the resolver
18+
$user = User::where("email", $args["email"])->first();
19+
20+
if(!($user || Hash::check($args["password"], $user->password))){
21+
throw ValidationException::withMessages([
22+
"email" => ["the provided credentials are incorrect."]
23+
]);
24+
}
25+
$user->delete();
26+
return $user;
27+
}
28+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\GraphQL\Mutations;
4+
5+
use App\Models\Post;
6+
7+
final class PopularPosts
8+
{
9+
/**
10+
* @param null $_
11+
* @param array{} $args
12+
*/
13+
public function __invoke($_, array $args)
14+
{
15+
// TODO implement the resolver
16+
$posts = Post::where("views", ">", 5000)->orWhere("likes", ">", 50)->all();
17+
return $posts;
18+
}
19+
}

app/GraphQL/Mutations/Search.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\GraphQL\Mutations;
4+
5+
use App\Models\Post;
6+
7+
final class Search
8+
{
9+
/**
10+
* @param null $_
11+
* @param array{} $args
12+
*/
13+
public function __invoke($_, array $args)
14+
{
15+
// TODO implement the resolver
16+
$posts = Post::where("content", "like", "%" . $args["key"] . "%")->orWhere("title", "like", "%" . $args["key"] . "%")->all();
17+
return $posts;
18+
}
19+
}

app/Models/Category.php

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\HasMany;
78

89
class Category extends Model
910
{
1011
use HasFactory;
12+
13+
public function posts(): HasMany
14+
{
15+
return $this->hasMany(Post::class, "category");
16+
}
1117
}

app/Models/Post.php

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use Illuminate\Database\Eloquent\Relations\HasMany;
89

910
class Post extends Model
1011
{
@@ -19,4 +20,9 @@ public function category(): BelongsTo
1920
{
2021
return $this->belongsTo(Category::class, "category");
2122
}
23+
24+
public function comments(): HasMany
25+
{
26+
return $this->hasMany(Comment::class, "comment");
27+
}
2228
}

graphql/auth.graphql

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
extend type Query {
2-
me: User! @auth
2+
me: User! @guard @auth
33
}
44

55
extend type Mutation {
6-
login(email: String! @rules(apply: ["email"]), password: String! @rules(apply:["min:8"])): String
6+
login(email: String! @rules(apply: ["email"]), password: String! @rules(apply:["min:8"])): String!
77
register(name: String!, username: String! @rules(apply: ["unique:users"]), password: String! @rules(apply: ["min:8"]), email: String! @rules(apply: ["email", "unique:users"])): User! @create
8+
deleteAcount(email: String! @rules(apply: ["email"]), password: String! @rules(apply: ["min:8"])): User!
89
}

graphql/category.graphql

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extend type Query {
2+
categories: [Category!]! @all
3+
category(id: ID! @eq): Category @find
4+
}

graphql/post.graphql

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extend type Query {
2+
posts: [Post!]! @all
3+
post(id: ID! @eq): Post @find
4+
search(key: String!): [Post]! @all
5+
popularPosts: [Post]! @all
6+
myPosts: [Post]! @guard
7+
}

graphql/tag.graphql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extend type Query {
2+
tags: [Tag!]! @all
3+
}

graphql/types.graphql

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Category {
1717
description: String!
1818
created_at: String
1919
updated_at: String
20+
posts: [Post]! @hasMany
2021
}
2122

2223
type Post {

graphql/user.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
extend type Query {
2-
users: [User!]! @paginate
2+
users: [User!]! @paginate @guard
33
}

0 commit comments

Comments
 (0)