I'm developing a real time chat app using graphql and I want to modify fetched data instead of refetch it again - in order to reduce unnecessary network requests.
When my app first init I'm fetching a list of users (that are not the current logged-in user) to display on the sidebar of the app.
Each user contains a lastMessage object that represent the last message that he sent or received.
When a user clicks on a user to chat with, another query is submitted in order to get all the messages between the users.
Using subscriptions, I'm updating the messages state when a new message is sent (either by the logged-in user or by the other user).
Now, I want to update the lastMessage object of the related user displayed on the sidebar, but I don't want to refetch all the users again in order to do so, because I have all the updated data in the client, which I received by the subscription event. Instead, I want to update the graphql queried data using js.
Is there a way to do that?
Thanks.
Apollo cache has a 'modify' method that you can use to set the cache of user's lastMessage.
Apollo docs for cache modify
Related
I have a form where users can update data. At the same time, an admin can update that same data.
In the user form I use useQuery. When the admin updates data, it sends a message through websockets to the user. The websocket hook on the user's side uses useLazyQuery to trigger it to update the user's form when an admin makes a change. However, useQuery and useLazyQuery seem to operate independently as far as I can tell even though they stem from the same builder. Both work perfectly fine independently.
The crux -> The isFetching is not triggered in useQuery when I trigger useLazyQuery.
How can I trigger useQuery to update the form data on the user's side when the websocket gets an update from the admin?
If you are sure you want to update the form data on the user's side by re-fetching the data from your API.
As described in the doc : https://redux-toolkit.js.org/rtk-query/usage/cache-behavior#re-fetching-on-demand-with-refetchinitiate you can use refetch in useQuery.
const { data, refetch } = useGetPostsQuery(5)
I want my app to have 3 different kinds of notifications which the user has the option to opt into each but I need to support all of them on the backend I think. I wanted to see if others had an approach which worked well for them. The three notification types are different:
Individual Notifications - A specific user related notification. When a specific event happens in their account they (and their team members) get notified of it.
Item Notifications - An item specific notification. Any user of the system can get notified when a specific item available to all reaches a certain stage of the process.
Topic Notifications - General system event, to be sent to anybody who has opted into receiving notifications for a system event.
If I am going to support badges for each, I need to track them by user I suppose, in order to send down the badge number with the notification. The icon would be the aggregation of each. I am thinking I need three Toggle settings, one for each. When the user sets each one, I would send a registration for that type of notification to a webapi which would store the user id in a registration table along with the registration type.
When sending the registration to the user, the registration table gets queried, a record goes into the notification_view table for that user and notification type, and the badge count is taken from that and sent to apns.
When the user views a notification, I will send a message to the api and update (or remove) the notification_view record associated with he viewed notification.
I know there are ways to have filter a notification, and I expect this will be incorporated. I'm using Azure NotificationHubs and this would be included under tags. So if a device had a tag (sports_news or something like that) the server side could send a notification with a sports_news tag and it would go to everybody who subscribed to it. That might work for category #3 above, provided we do not care about badge counts.
Is anybody else doing something like this? Do you use the same type of backend tables to support the process? Does my process mirror what you are doing?
I'm working on a chat app, developed using Apollo GraphQL and React and I have the following issue:
I have a component called "Conversation" which is fetching an array of messages between two users (the logged-in user and other user) using the "useQuery" hook of Apollo which is invoked every time the component mounts.
When a new message is sent by the logged-in user, I'm updating the cached array of messages using the "writeQuery" function provided by Apollo.
By doing that, the "Conversation" component is getting re-rendered, which is leading to an unnecessary network request because the "useQuery" hook is triggered again.
I would love to hear if there is a way of preventing "writeQuery" from triggering a re-render to the relevant component.
Thanks a lot in advance!
I am setting up an application with realtime events using nchan (https://github.com/slact/nchan). The application itself is built on the Laravel framework. However, for now everyone that subscripes to specific sub-channel will get new events as soon infomation is pushed to the corresponing pub-channel.
I want to limit that so only logged in users should be able to subscribe to events. Hence, if I am not logged in, it should not be possible to create a websocket and listen for events from for example http://www.example.com/chat/pubchat?id=some_id.
Is there any way to make this possible?
As far as I know, I cannot use Nginx/Nchan to make database queries to get only logged on users that way. And Laravel itself cannot limit subscribers since that is handled by Nginx/Nchan (but on the other side, can make database queries).
Thanks for any tips!
EDIT: Seems that I might can use the Drizzle module (https://github.com/openresty/drizzle-nginx-module) and use the session ID as identifier. So if that ID is not present in the session table the connection will be blocked.
Is it possible to find a list of Yammer users in the 'pending' state using the API?
(we have a growing list of old invites that need to be purged regularly)
Tried a number of options:
The find all users endpoint, paging to 50 per page seems to only return 'active' users (scanned 100+ pages).
https://www.yammer.com/api/v1/users.json
The find by email endpoint returns all user states, although requires knowing the email.
The export users API endpoint produces a .zip file
Pending users were recently added as mentionable:
https://about.yammer.com/yammer-blog/mentioning-pending-users-designing-building-testing-features-yammer Should this recent change have also made pending users visible via the users.json endpoint ?
I know pending users can be identified in the manual user.csv extract by having no join date, no deletion and no suspended date, although how can they be identified via the API? users.json seems to not provide this functionality.
Has anyone been able to automate the deletion of pending users in Yammer via the API?
You can use the Data Export API. Extract the users.csv from the ZIP file using code and then filter for pending users. Pending users do not have a joined_at, suspended_at, or deleted_at date.
NOTE: If you are intended to "remove" a pending user, you must always check if that email address also has an active user associated. An email address can show up multiple times in users.csv. When you do remove a user always suspend the user because it can be undone.
Here's an endpoint you can run a GET on an return the JSON output of the pending user list:
https://www.yammer.com/<your Yammer network>/contacts/network
Example:
https://www.yammer.com/contoso.com/contacts/network
Note: this is an undocumented endpoint so the functionality could change at any time.