pagination on Hasura table and relationship - Relay API Hasura - graphql

I am working on a project where I need to get the combined pageInfo from Hasura Realy API.
I have one table and one relationship on table. I want to get the pageInfo like endCursor and startCursor hasNextPage flag so I can control the limit on the combined data and get combined pageInfo details.
so I can pass the endCursor in the next Query and get the rest data if available. I am able to do it on a single table but when I use table and relationship both in the same query then it is not showing any pageInfo details.
any help?
We are able to control the limit on tables and relationship both but pageInfo we are only getting of table not of relationship.

Related

Returning a totalCount field in apollo and Relay pagination

In our GraphQL Server we use relay style cursor pagination.
We want to add a totalCount field to queries. How can we do it so that the extra computations are only done if totalCount is queried by the user?
Explanation:
Our resolvers (say, BigmapResolver) use the filtering, sorting and pagination requested by the client to create and return a BigmapConnection that has relay specific fields: edges, pageInfo, cursor, node.
Now it's easy to add a totalCount fields to this, but then we have to compute it regardless of whether or not the user is querying for it.
What is the right way to do this in Apollo server?
The library graphql-parse-resolve-info allows parsing the resolve info and enables exactly the needed behavior.

Querying cache by fields other than ID?

I'm integrating GraphQL into my application and trying to figure out if this scenario is possible.
I have a schema for a Record type and a query that returns a list of Records from my service. Schema looks something like:
type Query {
records(someQueryParam: String!): [Record]!
}
type Record {
id: String!
otherId: String!
<other fields here>
}
There are some places in my application where I need to access a Record using the otherId value (because that's all I have access to). Currently, I do that with a mapping of otherId to id values that's populated after all the Records are downloaded. I use the map to go from otherId to id, and then use the id value to index into the collection of Record objects, to avoid iterating through the whole thing. (This collection used to be populated using a separate REST call, before I started using Apollo GQL.)
I'd like to remove my dependency on this mapping if possible. Since the Records are all in the Apollo cache once they've been loaded, I'd like to just query the cache for the Record in question using the otherId value. My service doesn't currently have that kind of lookup, so I don't have an existing query that I can cache in parallel. (i.e. there's no getIdFromOtherId).
tl;dr: Can I query my Apollo cache using something other than the id of an object?
You can't query the cache by otherId for the same reason you don't want to have to search through the record set to find the matching item -- the id is part of the item's key, and without the key Apollo can't directly access the item. Apollo's default cache is a key-value store, not a database that you can query however you like.
It's probably necessary to build a query into your data source that allows mapping between otherId and id, obviously it would be horribly inefficient at scale to search through the entire record set for your item.

Strapi update many-to-many relationships in strapi?

I have two collection types in Strapi, created with many-to-many relation.
What is the proper way to write a custom query to update only the relation?
**user**
id name
1 user1
**store**
id name
1 store1
**user_saved_stores__stores_saved_users**
id user_id store_id
1 1 1
I can use the default PUT API to update the relation like this, but I would need to find out every single user before calling the API, as it would overwrite all the many-to-many relations.
const xhr = new XMLHttpRequest();
xhr.open('PUT', '/stores/1', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(
JSON.stringify({
savedUser: ["1","2"],
})
);
If I would like to add or remove only one user to the relations, what should be the best way without writing custom SQL query?
Currently seems not any straight forward support in strapi for many to many relationships update. So either writing custom queries inside the above PUT api , of create separate api directly to update the ** user_saved_stores__stores_saved_users** table created by strapi

How to establish one to many relationship in Dynamo DB?

I have 2 different JSON Files. One with user details and other with order details. Order details table has a column user_id to match the user ordered for. I have to create a dynamo db table that has the order details nested inside the user details and insert the values from the Json files into this table using a spring-boot app. Can someone help me with this ? Do we have any example code ?
DynamoDB is NOT a relational DB so you can't have relations per se.
However, you have two ways (at least those come to my mind) to achieve what you want.
1) Have two tables: User and Order, the latter with userId field. When you load Order, get your userId and load also a User by the index id.
2) In your User.java you can have field List<Order> orders. Then you need to create Order.java and annotate this class with #DynamoDBDocument. This enables you to have custom objects in your #DynamoDBTable classes. Do not also forget about getters and setters since they are required.

Laravel/Lumen include a column from pivot table into results of relationship eager loading

In my application a user can add other users to the "favorites" list. All information about favorite users is stored in a table with the following structure:
user_id
favorite_id
In addition, each user has its services with prices. There are users and services tables in my application that are related to each other with service_user table which has the following structure:
user_id
service_id
price
In order to get all favorite users of a particular user with their services and prices I do the following:
$user->favorites()->with('services')->get();
However, there's no price column in each service object of the resulting list of services (this column is located in pivot).
Therefore, I want to know if there's a way to get the price column as part of each service object, instead of being in pivot table. The following question already solves my problem, but I want to know if there is way to do this without map() and/or foreach() to make performance better?
Currently, I have the following solution:
$user->favorites()->with('services')->get()
->map(function ($favorite) {
foreach ($favorite['services'] as &$item) {
$item['price'] = $item->pivot->price;
}
return $favorite;
});

Resources