How to create a Follower following model in GraphQL? - data-structures

I saw many tutorials/article they have mentioned that following/followers field as an integer in user model in GraphQL schema. I know those are for demo purpose. But I don't know how to save the followers/following users with proper relational model and how unfollow works. I saw Twitter developer site here they mentioned their user model as follows:
{
"id": 6253282,
"id_str": "6253282",
"name": "Twitter API",
"screen_name": "TwitterAPI",
"location": "San Francisco, CA",
"profile_location": null,
"followers_count": 6133636,
"friends_count": 12,
"listed_count": 12936,
"created_at": "Wed May 23 06:01:13 +0000 2007",
"favourites_count": 31,
}
I don't know whether this is their original code or prototype. But I'm confused how they are saving the follower userID.
1. How can we create proper follower/following model in graphQL?
2. Also how to create post likes/dislikes in GraphQL?

Related

What is the proper format to expect when using an api to create a resource that references another resource

I am adding a feature that allows users to select from a list of people of a certain type, Type1 and Type2. A type would be chosen from a dropdown, and the data from the API would look like
{
"id": 1,
"name": "TYPE1",
"desc": "Type 1 Person"
}
I am creating a POST endpoint that allows an admin user to insert more people into the list, but I'm unsure on the best way for the admin to include the person's type. In other languages/frameworks, I would do something like this:
{
"first_name": "John",
"last_name": "Doe",
"type_id": 1
}
then handle adding the entry in my own SQL. In Spring though, I'm trying to leverage an object being created from the data automatically. For this to be successful, I've need to send the data as:
{
"first_name": "John",
"last_name": "Doe",
"type": {
"id": 1,
"name": "TYPE1",
"desc": "Type 1 Person"
}
}
My question is in two parts.
In Spring, is there anything I can leverage that would allow me to just pass an identifier for person type when creating a new person entry? (I've looked into DTOs, but I've never used them, so I don't know if that is the proper solution)
In REST in general, how much data should be required when adding a resource that references another resource?

Google Places API Difference between _id and place_id

Could someone please explain me the key difference between the attributes: _id and place_id?
I know: Place IDs uniquely identify a place in the Google Places database and on Google Maps.
But what does the attribute _key representing ?
Example Response Code from the Google Api:
{
"_id": "d5bcd8db4a52088350ffb502c31c6694918d3907",
"place_id": "ChIJb3D1a2mnkUcRxop5hdAGiwY",
"lat": 27.991789,
"lng": 3.865653,
"name": "We Are here",
"rating": 0,
"user_ratings_total": 0,
"types": [
"school",
"point_of_interest",
"establishment"
],
I believe the _id field was deprecated and should disappear from responses shortly.
The Places fields reference, id, alt_id, and scope are deprecated as of September 3, 2019, and will be turned off on June 3, 2020.
The id and reference request parameters have been replaced by the place_id request parameter.
the alt_id and scope fields have no equivalent, as they were only used for the Place Add service which was turned off in July 2018.
source: https://developers.google.com/maps/deprecations#places_fields_reference_id_alt_id_scope_-
I guess Google just renamed deprecated id field as _id.

How to fetch data using with via object in Laravel eloquent?

Actually, I want to fetch data using Model object not through Model facade like mention below.
$user = $this->getGuard()->user();
Above user is current logged user which is
"id": 6,
"name": "kuser",
"email": "kuser#gmail.com",
"phone": "03345154067",
"is_subscribed": 0,
"subscription_date": null
But when I try to fetch same $user object with its related model like cards, by execute $user->with(['cards'])->first(); than it gives first record of user table with cards like mentioned below.
"id": 1,
"name": "admin",
"email": "admin#gmail.com",
"phone": "03056494616",
"is_subscribed": 1,
"subscription_date": "2019-10-08",
"cards": []
Above mentioned record which is user object. It is first record of my user table.
Actually, I am expecting.
"id": 6,
"name": "kuser",
"email": "kuser#gmail.com",
"phone": "03345154067",
"is_subscribed": 0,
"subscription_date": null
with its related model cards like
"id": 6,
"name": "kuser",
"email": "kuser#gmail.com",
"phone": "03345154067",
"is_subscribed": 0,
"subscription_date": null
"cards":[] // array of cards those belongs to it.
You can use Lazy Eager Loading, you don't have to query for the user again, you already have it:
$user = $this->getGuard()->user();
$user->load('cards');
Laravel 6 Docs - Eloquent - Relationships - Lazy Eager Loading
Use a simple where ?
$user->where('id', Auth::id())->with(['cards'])->first();
won't that work?
Here is another way
User::with(['cards'])->find($user->id);

How to returns all public tweets regarding for specific location using tweeter api

Is there an API call which will returns all recent public tweets regarding for specific location?
I tried GET trends/place but it's WOEID not worked for Sri Lanka and Cities.
(Sri Lanka WOEID is 23424778)
I don't want to use tweeter GET search/tweets.json endpoint because search based on certain key words.
Is there any solution for this?
Finally, I got the answer. We could not get trends on each and every location using tweeter API 1.1.
you have to check our closest trending place using this API call. For Austalia
https://api.twitter.com/1.1/trends/closest.json?lat=37.781157&long=-122.400612831116
the response like be this.
[
{
"country": "Australia",
"countryCode": "AU",
"name": "Australia",
"parentid": 1,
"placeType": {
"code": 12,
"name": "Country"
},
"url": "http://where.yahooapis.com/v1/place/23424748",
"woeid": 23424748
}
]
after that, you can use GET trends/place.
even though you cannot use GET trends/place for geo-based filtering you can use tweeter search endpoint. if you do not want to filter it by keyword ignore the q parameter and use geocodeparameter. for example,
https://api.twitter.com/1.1/search/tweets.json?result_type=recent&geocode=5.954920,80.554956,12mi
In here mi is miles.

How do I create an all day event in the Google Classroom API Method: courses.courseWork.create?

I would like to add an all-day event to my Google Classroom Course as an assignment with the Classroom API found here: Method: courses.courseWork.create documentation
Here is the json request I've been using in their API explorer:
{
"title": "Lesson 1.1",
"workType": "assignment",
"state": "published",
"description": "This is a test assignment.",
"dueDate": {
"year": 2017,
"month": 9,
"day": 2
},
"dueTime": {
"hours": null,
"minutes": null
}
}
I've tried many variations, but it always posts the assignment due at 8:00 PM by default, never an allDay or all-day event. Removing the dueTime isn't allowed per the documentation. Yet, when I manually create a lesson it's an optional field. I inspected the post data and couldn't find out how this is happening.
It doesn't appear to mention how to create an all-day event in the Google Classroom API documentation and the Google Calendar API docs didn't give me any usable hints.
Any ideas?

Resources