Are correlated sub queries supported by GraphQL - graphql

I am investigating the use of GraphQL
I have a use case which I cannot see how to achieve in a single GraphQL query.
I have the following data classes.
Type A Reference Data (Primary Key id)
Type A User Data (Foreign Key rd_id)
Type B User Data
I can execute three separate queries to retrieve all the necessary data
What I would like is to execute a single query and get all data
I can get Type A & B User data in one query fine.
However I also need the Type A Reference data returned with the associated Type A User Data.
Type A user data has a foreign key to the specific reference data row
I cannot see how I can write a GraphQL query that joins data from two separate types of data.
query experiment {
userA {
id
rd_id
name
address {
address_line_1
address_line_2
zip
}
}
userB {
id
business_name
trading_as
}
referenceData (id : $userA.rd_id) { // How can I achieve this join
type
type_name
limit
}
Does GraphQL allow me to join referenceData records to UserA type records like this in a "dynamic" way?

Related

How to back-reference objects in self-referencing many-to-many relationship?

I am building a blog application and one of the features is being able to follow other users. This creates many-to-many relationship between the user which I declared like so:
type User struct {
gorm.Model
Username string
Password string
Followers []*User `gorm:"many2many:user_followers"`
}
When migrating this model, the following join table is created:
join table: user_friends
foreign key: user_id, reference: users.id
foreign key: follower_id, reference: users.id
My question is, how can I retrieve the followings of a user?
To get the followers of a user, I can simply do:
var followers []User
db.Model(&user).Association("Followers").Find(&followers)
But I can't figure out a way to retrieve the followings in a similar manner. I know I can query the join table to get the followings but this means that for each object thats returned from this query, I'd need another query to get the user associated with the user_id. This seems super inefficient at scale.
How can I do this effectively and efficiently?
Thank you!

How to fetch records from same table using group by with where condition in laravel?

I have a cartitem table I where there are two field named vendor_id and cookie_identifier I want to retrieve a specific cookie identifiers records group by vendor id..how can it possible. I write a query which is given bellow it does not work
$addTocartItems = CartItem::groupBy('vendor_id')
->where('cookie_identifier', $getCookieIdentifier)
->get();

Master Data Mapping in ES Result

Is there any way in ES to map master data with search result.
Example:-
I have Employee and EmployeeType tables in RDBMS
EmployeeType has 2 fields - Id and EmployeeTypeName(Admin, Management, Job Level 1)
In Employee table I have mapped EmployeeTypeId (Foreign Key)
When I retrieve Employee Data I want to get EmployeeTypeName along with Id.

'include' data from two tables with same column name in single query

I have two tables(Reviews and Comments) with same column name userId, how can i differentiate them in parseQuery so i may get the data using the 'include' option, query is as follow:
query.whereEqualTo("businessId", parseBusiness);
query.include("userId"); // from the reviews table
query.include("lastComment");
query.include("userId"); // from he comments table
userId is a pointer to the User table

how to write parameter string for include for linq query?

If table Employee has foreign key for table person, department,
when get the entity of employee, I want to both associated entities loaded too.
how to write the linq query? like below?
var employee = this.Context.Employee.Include("Person, Department");
It seems not working.
var employee = this.Context.Employee.Include("Person").Include("Department");

Resources