Skip to content

Commit 726426a

Browse files
committed
seprate files in graphql folder - complete login user
1 parent 3ea15ac commit 726426a

File tree

10 files changed

+85
-65
lines changed

10 files changed

+85
-65
lines changed

app/GraphQL/Mutations/Login.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace App\GraphQL\Mutations;
44

5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Validation\ValidationException;
8+
59
final class Login
610
{
711
/**
@@ -11,5 +15,14 @@ final class Login
1115
public function __invoke($_, array $args)
1216
{
1317
// TODO implement the resolver
18+
$user = User::where("email", $args["email"])->first();
19+
20+
if(! ($user || Hash::check($args["password"], $user->password)))
21+
{
22+
throw ValidationException::withMessages([
23+
"email" => ["the provided credentials are incorrect."]
24+
]);
25+
}
26+
return $user->createToken($user->username)->plainTextToken;
1427
}
1528
}

graphql/auth.graphql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extend type Query {
2+
users: [User!]! @paginate
3+
}
4+
5+
extend type Mutation {
6+
login(email: String! @rules(apply: ["email"]), password: String! @rules(apply:["min:8"])): String
7+
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+
}

graphql/category.graphql

Whitespace-only changes.

graphql/comment.graphql

Whitespace-only changes.

graphql/notification.graphql

Whitespace-only changes.

graphql/post.graphql

Whitespace-only changes.

graphql/schema.graphql

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,8 @@
1-
type User {
2-
id: ID!
3-
name: String!
4-
username: String!
5-
email: String!
6-
email_verified_at: String
7-
password: String!
8-
created_at: String!
9-
updated_at: String!
10-
posts: [Post]! @hasMany
11-
}
12-
13-
14-
type Category {
15-
id: ID!
16-
name: String!
17-
description: String!
18-
created_at: String
19-
updated_at: String
20-
}
21-
22-
type Post {
23-
id: ID!
24-
title: String!
25-
content: String!
26-
author: User! @belongsTo
27-
category: Category! @belongsTo
28-
likes: Int!
29-
views: Int!
30-
isPublished: Boolean!
31-
created_at: String
32-
updated_at: String
33-
}
34-
35-
type Tag {
36-
id: ID!
37-
name: String!
38-
description: String!
39-
created_at: String
40-
updated_at: String
41-
}
42-
43-
type Notification {
44-
id: ID!
45-
message: String!
46-
user: User!
47-
created_at: String
48-
}
49-
50-
type Comment {
51-
id: ID!
52-
content: String!
53-
user: User!
54-
created_at: String
55-
updated_at: String
56-
}
57-
58-
type Query {
59-
users: [User!]! @all
60-
}
61-
62-
63-
type Mutation {
64-
65-
}
1+
#import types.graphql
2+
#import auth.graphql
3+
#import category.graphql
4+
#import comment.graphql
5+
#import notification.graphql
6+
#import post.graphql
7+
#import tag.graphql
8+
#import user.graphql

graphql/tag.graphql

Whitespace-only changes.

graphql/types.graphql

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
type User {
2+
id: ID!
3+
name: String!
4+
username: String!
5+
email: String!
6+
email_verified_at: String
7+
password: String!
8+
created_at: String!
9+
updated_at: String!
10+
posts: [Post]! @hasMany
11+
}
12+
13+
14+
type Category {
15+
id: ID!
16+
name: String!
17+
description: String!
18+
created_at: String
19+
updated_at: String
20+
}
21+
22+
type Post {
23+
id: ID!
24+
title: String!
25+
content: String!
26+
author: User! @belongsTo
27+
category: Category! @belongsTo
28+
likes: Int!
29+
views: Int!
30+
isPublished: Boolean!
31+
created_at: String
32+
updated_at: String
33+
}
34+
35+
type Tag {
36+
id: ID!
37+
name: String!
38+
description: String!
39+
created_at: String
40+
updated_at: String
41+
}
42+
43+
type Notification {
44+
id: ID!
45+
message: String!
46+
user: User!
47+
created_at: String
48+
}
49+
50+
type Comment {
51+
id: ID!
52+
content: String!
53+
user: User!
54+
created_at: String
55+
updated_at: String
56+
}

graphql/user.graphql

Whitespace-only changes.

0 commit comments

Comments
 (0)