Redux Toolkit - Can a state update invalidate RTK Query Data? - redux

We currently have such values set in a settings slice;
settingsSlice: {
projectId: 'a'
}
The projectId in the example above is used to compose a dynamic URL that an RTK Query API uses for requests, e.g. https://projectId...
Is it possible to invalidate the API data upon a change to the settings slice?
From the documentation, it seems possible to invalidate other API's using tags, but that doesn't seem to be supported within state slices.

No you would have to manually call dispatch(api.invalidateTags(...)).

Related

Dynamic IAM Policy for DynamoDB

I am exploring fine-grained access for an API that we are building. APIs are hosted on API Gateway with a lambda handler and the datastore is DynamoDB. I need to apply row-level and attribute-level restrictions on the queries, depending upon the user invoking the API.
DynamoDB supports horizontal (row) and vertical (attribute) restrictions through Policies. This aws doc covers it. Let's say I have the access controls defined in a separate DB and my lambda handler has the access definition for the current user. What I want to do is be able to use some custom attributes to define my condition. e.g.
"Condition": {
"ForAllValues:StringEquals": {
"dynamodb:LeadingKeys": ["${customcontext:customerId}"],
"dynamodb:Attributes": [${customcontext:ListOfVisibleAttributes}]
},
"StringEqualsIfExists": {
"dynamodb:Select": "SPECIFIC_ATTRIBUTES"
}
}
Also, can this policy be used to restrict the rows returned based on a dynamic condition? e.g. I want to filter further based on a custom list of values on sort-key.
And lastly, is it worth handling this using a Policy, instead of a Lambda with dynamic query?
You wouldn't be able to dynamically create a policy per request. Its not scalable as you can't create an unbounded number of IAM policies, not to mention the increased latency that would be introduced.

PageInfo in Firestore not usable

I would like to use pagination in Firestore so I can save a query state and automatically allow users to submit a page token to start a query again. The challenge I am seeing with this is that Firestore does not offer a query token or page token to resume iteration. However, after looking through the docs for GoLang, it looks like there is an exported PageInfo() method that returns a token I am interested in and an unexported fetch method.
Is there a method to use the exported PageInfo() values to allow me to fetch a new set of documents using that existing token?
To use pagination in Firestore Database you can use query cursors with limit() method as mentioned in this document. You can go through this youtube link to know more about it.
You may also consider using pageSize & pageToken query parameters and nextPageToken field with Firestore REST API as mentioned in this document to achieve pagination. There is a similar StackoverFlow thread which may help you.

AWS Amplify + Appsync - Is it possible to use #connection transform to cascade delete related data?

I am developing a web application using AWS Amplify and AppSync to read and write my data to DynamoDB tables. Using the Amplify's GraphQL Transforms, it is easy enough to establish a connection between data types using the #connection transform. I wish to know if it is possible to delete related data in a simplified or semi-automated way.
Supposing a simple blog example, where a user has a blog, which has posts, which in turn has comments owned by other users. If a post is deleted, I would like to delete the comments associated with that post. If a user is deleted, I would like to delete their blog(s), posts, and comments related to those posts, and any comment the user has left on other posts. This example is contrived in that perhaps it is desirable to have some of this data be maintained in some form. However, in some cases this behaviour is exactly what I am looking for.
When working with Prisma in the past, I used their #relation directive to make a relationship similar to using Amplify's #connection.
However, in cases where I wanted cascading deletion, I would write something along the lines of:
type Post {
id: ID! #unique
title: String!
body: String!
owner: ID!
comments: [Comment!] #relation(name: "PostComments",
onDelete: CASCADE)
}
I could use and set the onDelete parameter to CASCADE or SET_NULL depending on how I wanted to handle it.
Is there a way to do something similar through Amplify? Of course I can write a bunch of VTL or Lambda resolvers to handle each case, but I wanted to check first if there is a faster / easier way to implement this.
This is not yet supported natively by Amplify. As you said, you are able to replicate this behavior using pipeline resolvers & some VTL and then deploy that via the Amplify CLI or on your own. There are plans to allow you to write your own transformers to encode reproducible logic like this as a resolver (see https://github.com/aws-amplify/amplify-cli/issues/1060) as well as plans to move towards pipeline resolvers for all Amplify CLI projects (see https://github.com/aws-amplify/amplify-cli/issues/1055).

Passing value between two components in angular2-meteor project

I am using angular2-meteor.
When I try to pass a value between two components (when the value change in the first component, create an event in second component and use this new value), I have two ways right now:
One way is meteor way: using this.autorun and Session.get.
Another way is angular2 way: using Injectable service with EventEmitter.
Which way should be prior? Or is there any other better way? Thanks
Now I used angular2-meteor a while.
Although the angular2-meteor tutorial has no example so far about using or choosing Angular 2 service or Meteor Session.
But I feel angular 2 takes the lead in the front end, while meteor makes reactivity easier and also handle all back end things.
So I went with angular2 way using service to share between components. And service is very powerful like #todd-w-crone said.
If anyone has better answer, I will switch to accept that one.
I find it practical to create a new service called App.states.ts which is accessed globally and mimics Session (get / set).
I commonly import this service to all necessary components to get or set new value such as User.status, company.profile, lastProduct, etc.
Since this service is #injectable it can also make use of other services, in case a value hasn't been set already.
This allows me to ask for a variable in a component appState.getLastModifiedItem(), then in app.states.ts I'll write this function to pass this.modifiedItem or either:
Request another service item.service.ts to fetch data
Call another function with itemCollection.findOne({...}) and return such value.
You can configure Mongo queries as you want and either store static data in appState or keep subscription items in appState.
Do take into consideration that all subscriptions handled by an #injectable within a component are imported by such component. Be wary of conflicting subscriptions between components/services.

Meteor drop collection after every query

I am writing an application which communicates with an API and stores the response in a Meteor Collection so I can have the power of mongo to sort/filter.
I would like to clear the collection for every new result set. But a Meteor Collection is persistent.
What is the preferred way of clearing the collection? I know you can drop the meteor collection, but is that the preferred method?
Help appreciated. Thank you!
I would go about creating a local mongo collection which will be available on client side only. To create a client-side collection, just don't give it a name argument.
//This collection is client-only, and will not be sync with server
myCollection = new Mongo.Collection();
//To be more explicit, you can use `null` for the name:
myCollection = new Mongo.Collection(null);
Once you are done using the data empty the collection
myCollection.remove({});
myCollection.remove({}) is the syntax for removing all documents from a collection. This will only work on the server unless the collection is a client-side collection as per #Nakib's example. Otherwise documents can only be deleted by _id on the client side. Normally your allow/deny rules should block any attempt to delete anything on the client as it provides a great attack vector.
Not completely familiar with the Meteor best practice but if you were going to clear out an array in javascript the best practice would be to run the following.
myArrary.length = 0;
For more information I recommend this blog post by David Walsh where he details the reasoning behind zeroing out an array as follows:
Setting the length equal to zero empties the existing array, not
creating another array! This helps you to avoid pointer issues with
arrays as well.

Resources