Skip to content

Commit

Permalink
cleaned all meta info from GraphQL Types
Browse files Browse the repository at this point in the history
  • Loading branch information
saqueib committed Aug 30, 2017
1 parent f236efb commit 0d45544
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 281 deletions.
34 changes: 6 additions & 28 deletions app/GraphQL/Type/LikeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,32 @@

class LikeType extends GraphQLType {

protected $attributes = [
'name' => 'Like',
'description' => 'A user like on a tweet'
];

/*
* Uncomment following line to make the type input object.
* http://graphql.org/learn/schema/#input-types
*/
// protected $inputObject = true;

public function fields()
{
return [
'id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of like'
'type' => Type::nonNull(Type::int())
],
'user_id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of the user'
'type' => Type::nonNull(Type::int())
],
'tweet_id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of the tweet'
'type' => Type::nonNull(Type::int())
],
'created_at' => [
'type' => Type::string(),
'description' => 'Creation datetime'
'type' => Type::string()
],
'updated_at' => [
'type' => Type::string(),
'description' => 'Updating datetime'
'type' => Type::string()
],

// Nested Resource
'user' => [
'type' => GraphQL::type('User'),
'description' => 'A User type',
'type' => GraphQL::type('User')
]
];
}

protected function resolveUserField($root, $args)
{
return $root->user;
}

protected function resolveCreatedAtField($root, $args)
{
return (string) $root->created_at->diffForHumans();
Expand Down
36 changes: 8 additions & 28 deletions app/GraphQL/Type/ProfileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,35 @@

class ProfileType extends GraphQLType {

protected $attributes = [
'name' => 'Profile',
'description' => 'A user profile'
];

/*
* Uncomment following line to make the type input object.
* http://graphql.org/learn/schema/#input-types
*/
// protected $inputObject = true;

public function fields()
{
return [
'id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of the user'
'type' => Type::nonNull(Type::int())
],
'bio' => [
'type' => Type::string(),
'description' => 'The bio of user'
'type' => Type::string()
],
'designation' => [
'type' => Type::string(),
'description' => 'The designation of user'
'type' => Type::string()
],
'company' => [
'type' => Type::string(),
'description' => 'The company of user'
'type' => Type::string()
],
'city' => [
'type' => Type::string(),
'description' => 'The city of user'
'type' => Type::string()
],
'country' => [
'type' => Type::string(),
'description' => 'The country of user'
'type' => Type::string()
],
'dob' => [
'type' => Type::string(),
'description' => 'The date of birth of user'
'type' => Type::string()
],
'created_at' => [
'type' => Type::string(),
'description' => 'Creation datetime'
'type' => Type::string()
],
'updated_at' => [
'type' => Type::string(),
'description' => 'Updating datetime'
]
];
}
Expand Down
31 changes: 7 additions & 24 deletions app/GraphQL/Type/ReplyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,26 @@

class ReplyType extends GraphQLType {

protected $attributes = [
'name' => 'Reply',
'description' => 'A reply for a Tweet'
];

/*
* Uncomment following line to make the type input object.
* http://graphql.org/learn/schema/#input-types
*/
// protected $inputObject = true;

public function fields()
{
return [
'id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of reply'
'type' => Type::nonNull(Type::int())
],
'body' => [
'type' => Type::nonNull(Type::string()),
'description' => 'Body of of a reply'
'type' => Type::nonNull(Type::string())
],
'user_id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of the user of reply'
'type' => Type::nonNull(Type::int())
],
'tweet_id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of the tweet which receives reply'
'type' => Type::nonNull(Type::int())
],
'created_at' => [
'type' => Type::string(),
'description' => 'Creation datetime'
'type' => Type::string()
],
'updated_at' => [
'type' => Type::string(),
'description' => 'Updating datetime'
'type' => Type::string()
],
'user' => [
'type' => GraphQL::type('User')
Expand All @@ -53,7 +36,7 @@ public function fields()

// If you want to resolve the field yourself, you can declare a method
// with the following format resolve[FIELD_NAME]Field()
protected function resolveEmailField($root, $args)
protected function resolveBodyField($root, $args)
{
return nl2br($root->body);
}
Expand Down
65 changes: 12 additions & 53 deletions app/GraphQL/Type/TweetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,47 @@

class TweetType extends GraphQLType {

protected $attributes = [
'name' => 'Tweet',
'description' => 'A Tweet'
];

/*
* Uncomment following line to make the type input object.
* http://graphql.org/learn/schema/#input-types
*/
// protected $inputObject = true;

public function fields()
{
return [
'id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of the tweet'
'type' => Type::nonNull(Type::int())
],
'body' => [
'type' => Type::nonNull(Type::string()),
'description' => 'Body of of a tweet'
'type' => Type::nonNull(Type::string())
],
'user_id' => [
'type' => Type::nonNull(Type::int()),
'description' => 'The id of the user of reply'
'type' => Type::nonNull(Type::int())
],
'created_at' => [
'type' => Type::string(),
'description' => 'Creation datetime'
'type' => Type::string()
],
'updated_at' => [
'type' => Type::string(),
'description' => 'Updating datetime'
'type' => Type::string()
],
// Counts
'replies_count' => [
'type' => Type::int(),
'description' => 'count of replies'
'type' => Type::int()
],
'likes_count' => [
'type' => Type::int(),
'description' => 'count of likes'
'type' => Type::int()
],

// Nested Resource
'user' => [
'type' => GraphQL::type('User')
],
'replies' => [
'args' => [
'id' => [
'type' => Type::int(),
'description' => 'id of the reply',
],
'first' => [
'type' => Type::int(),
'description' => 'limit result',
],
],
'type' => Type::listOf(GraphQL::type('Reply')),
'description' => 'reply description',
],
'likes' => [
'args' => [
'id' => [
'type' => Type::int(),
'description' => 'id of the like',
],
'first' => [
'type' => Type::int(),
'description' => 'limit result',
],
],
'type' => Type::listOf(GraphQL::type('Like')),
'description' => 'A Like type',
]
];
}


// If you want to resolve the field yourself, you can declare a method
// with the following format resolve[FIELD_NAME]Field()
protected function resolveBodyField($root, $args)
{
return nl2br($root->body);
}

protected function resolveCreatedAtField($root, $args)
{
return (string) $root->created_at->diffForHumans();
Expand Down
Loading

0 comments on commit 0d45544

Please sign in to comment.