Using AWS Amplify API with DataStore

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right i think we're live okay okay all right can y'all hear me i need to make sure last time i was talking for a while all right anyways hello everybody welcome to the live stream it's your boy kilo loco and we're gonna be having some fun today as usual all right so let's talk a little bit about what happened last time and what we actually plan on doing here right okay so last time uh on the stream we were working with uh aws amplify datastore and we were working with aws amplify api and we're trying to get it to update the same data because this is uh going to be super beneficial for anybody that's working on like a real-life project right so if you're not familiar with datastore uh qrik a quick update on it datastore is kind of like your local persistence layer it's essentially just think about it as like a local database right you can think about it as in um if your ios developer has core data what it's actually using under the hood i believe is sqlite so you think about it like that and then there's the second part of it where it's um where it uses the api category right and the api category is what allows you to sync your local database to a backend database which means that all the data stays in sync and you're essentially able to um you know have real-time data uh so that's one way to think about it that's how i choose to think about it now in regards to working with datastore and api both of the categories like separately um you know using datastore for some offline uh capabilities and uh you know um things that it's it's uh really good at and using the api category just like sending out graphql or doing graphql queries or mutations having those use cases are going to be very very beneficial because there are only so many things that you could do with datastore it's it does like pretty much everything that you need to do need it to do but there are still going to be things where graphql is going to be your out when you need to do something a little bit more complex or just out of the box so we're going to be working with putting those two things together we have a project from last time i got it all up and running and we're about to pull that up um but yeah let me know where you're watching from what time zone it is for you like or what time it is for you and what are you doing like why are you joining the stream so what's going on denny uh thanks for joining the stream really appreciate it uh really really do um but yeah it's going pretty good it's going pretty good whenever whenever you see me on a live stream that's when it's going good okay so let me just go ahead and make sure that we can see a lot more than just my big old head right we don't want to just see my big old head whoopsie editing the wrong thing all right do this i could be a little bit closer like this oh yes all right 10 12 p.m okay so you've had you've had your thursday yeah you you've had your thursday now you're just chilling all right cool all right so now i need to switch over to my mac mini do all my little things here pretty cool stuff and what we want to do is we want to open up the project from last time and it's going to be right here counter to data this is the project that uh i was working on danny where where are you coming in from that it's it's 10 hours in front of me definitely overseas but i'm thinking yeah i mean you're even past uh utc at that point ukraine what's up what's going on shout out to ukraine then all right so real quick this is what we've what we have so far so i have my back end up and running um all that data is being stored already and what we have simulator and move this closer to xcode because that's just so confusing i actually don't use beta no more so let's go ahead and move from doc okay all right there we go okay so let's take a look at some of this logic real quick so we can understand what's going on before we get started into the juicy stuff because don't get we gonna get that juiciness the worst thing about using a pc is that sometimes your fingers get messed up on shortcuts so okay um let's take a look all right so when we first initially load our view which is this very basic simple view right here right when we first load that up what's happening is we perform this on uh this on appear function right here this observe counter and if we throw a shortcut to jump to it just be right there but i thought it would okay whatever anyway um we do this uh observe counter right and all this is going to do is it's going to essentially allow us to observe any changes that happen to our counter object and we are simply getting the first one from this snapshot and we are updating the counter id right here and the count as well so that's why we have this three that magically appeared we already updated that count to three before in the past so what we can do is we can use this data store update right here which you can see we're just doing whatever the current count is which is three plus one which is four we we send that new counter we're going to save it to the backend it's going to do an update since we're using the same calendar id and then we and then that's when we're actually going to be displaying that new saved counter value to count which then it's going to re-render swift ui and we're going to get all that all that goodness 9 15 in poland all right all right so you still got a little bit more time left in your day don't worry i'm gonna use up all your time muhammad uh uh my mood i'm sorry my mood my bad um but yeah all right so let's go ahead and show that we can update it to for nothing crazy right we're just updating it to four instantaneous nothing crazy all right now the the real test right here is if we can actually get the api to update so that's the important part we want to be able to update and as you can see look at so we're doing a basic data store save right here right we want to be able to do essentially the same thing but from api we do this api mutate we're going to do a update request with the counter same logic right here same counter logic right just count plus one right and what we want to do is we want to see this count go up by that counter value right so if we hit api update we should see it go up to five the problem the problem is that it's not doing that right so we get this error instead and the reason for that is because we're missing this value for field right value for field underscore version and it must be a number let's go ahead and take a look at where this is actually showing up in our database to help you understand what's going on but before that we got assad sorry if i butchered your name but from somalia it's 11 15 at night it's over it's already almost tomorrow uh so hopefully i could end out your day on a bang all right denny quick question what about flutter are you going to continue actually yes uh there was a recent release 2.8 i think yesterday flutter 2.8 i'm looking into flame right now y'all going to get some flame content whether you want it or not but yes you're going to get some flutter but you're also going to get a little bit android in there a little bit of ios in there i'm going to try to i'm going i'm going to try to not play favorites i favor ios native i'm sorry but i'm going to try to not play favorites but i'm gonna get you guys your content out be on the lookout on the channel next week it's gonna be a lot of good stuff all right so good morning to you uh i use i use remember i'm terrible at names it's not that i hate you it's i hate myself but i i i'm trying to say hi to everybody all right so let's go ahead and take a look at what's going on and why we can't do this update using the api so the first place i'm going to try to show you this is uh with dynamodb dynamodb is the the resource that we're using behind the scenes it's essentially our back-end database that's storing all of our data and i'm gonna i'm going to try and show you what's going on there so let me go ahead and clear all this out and i think we're in repos um it actually might be it actually might be a temporary folder uh counter yep all right so neat little trick once you're at the root of your amplify project what you can do is you can run amplify console actually i don't even want to do amplify console oh that's right i'm still working on that geo thing um hold up um i'd run into some errors for sure but it's okay let's see what we can do amplify console and if you do api if you do amplify console api it will take you to dynamodb i believe um [Music] and we're going to be doing graphql maybe it'll take us to appsync so let's see where it opens up to i'm logged out i may have to log in okay didn't seem to work maybe it's because i'm on that old old clf but let's see if we can get to the data all right so if i am at data let's see there might be a way for me to get to this resource but i haven't done it from studio before let's see the content is the data like this is actually showing you the the values and stuff in the backend um as you can see since we only have one field for our counter object it just has value and it's four and i can update it here too matter of fact while we're here let's just go ahead and update it f go ahead and do five watch this see all right let's do save counter and as you can see we get the update on the app so that's essentially what we want to do but we want to do it from the api right so see what's another way to do this i suppose i could just do amplify console amplify console will take you to the actual console and then you'll be able to see all the different backend resources from there um but yeah to be honest i've quit full-time flutter job for learning ios and i really fell in love thanks for amazing content uh yeah always happy to help um i'm kind of interested to hear what made you want to switch over to um what made you want to switch over to uh which one call it uh native ios just okay like what was like the determining factor for you like don't get me wrong i really enjoy flutter i do i actually i actually prefer flutter over swift ui the problem is is that i prefer swift over dart okay so once you get to your amplify console you can you can go to the aws console go through amplify you can see all your apps select your app and you'll get here if you go to api i believe you should be able to see your uh your table so you can see counter table you should be able to view that in um dynamodb oh this is appsync um sync all squished so i can't really tell this might actually be dynamodb i have it like way zoomed in for y'all so all right where am i what is this this is dynamodb okay okay um i feel like something's changed since the last time i've been here do overview and we should just be able to see the should just be able to see the data few items i don't know why it was so hard for me to think about that all right so once once we get over to our dynamodb we can actually see it let's see if we could get this to blow up a little bit okay so as you can see there's a couple of different a couple of different fields that we got here right we have type name we have this last change that we have version updated at and value and right now uh we're getting the error saying that we're not uh receiving this version so that's like one of the problems can you can you little bit zoom out aws yeah is it too big i feel like it would be too small if anything um let's see oops i didn't mean to do that go back all right it's just real quick i just want to show you this real quick anyways we do have this version that that it's been updated right and this value just happens to be the same number because every time we update it we're just doing plus one um i could change this number to like seven or ten or whatever and then um the next time that we get a version update it will just be six so these numbers aren't tied to each other they just happen to coincidentally be the same since we're incrementing by one so uh what we want to do uh is we want to also take a look at our the app sync for our our project so the way that we can do that i believe is from amplify studio i believe that we can get to i think that we can get to the app sync studio from app sync from here okay perfect yeah so this is appsync you can see it right here a lot of apps open up focus on what we need all right cool so this is appsync now appsync is the technology that's used in order to sync the local data with the backend data so your local database is synced with dynamodb using appsync right kind of hear that in the name a little bit and you can take a look at not the schema but the [Music] where is it i think maybe maybe it is the schemas yeah the schemas right here okay so these are the different um schemas or the graphql requests that you can perform right now since we are working with um datastore and it has that version on it it's required when whenever we do um an update or a create so create counter input right here you can see that it's uh it has this version right here um and then it also has a update counter input it has a version right here now even though it's not uh even though it's not like a required field on the graphql itself it's something that needs to be passed when we're working directly with datastore so let's go ahead and try to do that let me see and if we take a look at like the the counter object you'll notice that there's like no version field on it as well right there's like we have the created and the updated app but we don't have a version and if we also take a look at the schema schema there's no version field in here so that's essentially why it's failing um yeah so what we could do what we could do is um we can actually create a graphql mutation manually and that will allow us to do it so the bummer about this is like once you start using once you start using datastore you won't really be able to use the the default mutations right you'll have to use custom mutations in order to get it to work so what i'm going to do is i'm going to head over to the docs because i haven't done this in a while but i know the information is in here we just have to go to libraries api graphql and then i think we might need to do maybe advanced workflows where we create our own document this is where it's telling you to essentially do that create your own document and what we want to do [Music] is we want to essentially um we want we essentially want to create our own mutation that is going to include that version so that it can go through and we don't have any issues so let's go ahead and take a look at where they do something similar and this type um right here so we want to essentially have this extension on graphql request where we're able to do this get post with comments that's what they're doing they're doing a query but they're doing like an advanced query we kind of want to do the same thing but we want to do a mutation essentially let's see if they have a mutation they might not which is okay but let's see let's take a look uh what's going on sticky thanks for joining all right so what i'm gonna do is i'm gonna kind of start by working with um we have to use we have to create a graphql request or we have to return a graphql request of type post um and that's just simply for the response type okay well we're about to learn a little bit i've done this before but it it took a little bit of tinkering to figure it out so we're gonna tinker today we're gonna figure it out together uh hey uh reynaldo uh welcome to the stream and happy that i could provide you with some content hopefully you're getting hopefully you're learning something if i'm if i'm teaching you something then i feel good that's when i feel good all right so what i want to do is i want to essentially do something like this where we're doing an extension on a graphql request and then we're returning uh some type of result in which case i want to get back um i want to get i want to return this graphql json value we want to essentially get the response type as what we're trying to get back so in our case i'm trying to get back the counter so that's the type of graphql request we're going to be doing so we're going to be popping back and forth between these two things let's see if i can shrink it and maybe come on see if we could reference it and code at the same time because that would be ideal right that would be ideal all right so let's start off by creating a new file and we'll just go ahead and do next and we'll call this a graph ql request plus extensions that's how i like to do my extensions file so in this case we're probably going to need to import amplify right and that looks terrible so let's go ahead and swipe it swap it around and then we're going to do an extension on graph ql request like so and we have this static func uh and what do we want to do we want to um we want to update we want to update counter update counter with value right and we'll just do value is going to be int it's going to return a graphql request that request is generic we're going to be returning a counter object this does not look right it must be just this right and if we if we scroll over here maybe we can see a little bit of some samsung scroll sideways okay dot self okay i suppose that you need that okay all right next we have to see this all right let's just try it like this because this feels better um miss the beginning what are we building what's going on renee uh so i'm trying to show how we're gonna be uh updating our back-end object which is essentially initially created with datastore and we want to use the api category to also update it and the benefit here being that if we can update it using api then we kind of have an idea how to update it if we wanted to update our data using lambda or any other type of uh way to update it using the appsync api so yeah sticky you have used or have you used ios object capture no i haven't what is that ios object capture is that like a debugging tool sure right so let's do let document whoa equals triple like that so now we just need to put something in here so as you can see the name doesn't really matter right here um i don't think it actually matters right here here but we just essentially create a um a either a query or a mutation inside of this document and we pass that document down here and we can also use variables and pass in the variables like so so let's go ahead and pretend that our document's ready and what we can do is we can return this graph ql request json value and we haven't done it yet we haven't done the important part yet but at least get there document like so variables variables will be um we're going to do value and it's going to be value then lastly response type is going to be counter dot self right so this theoretically should work response type so like so and like so yeah okay cannot thinking that maybe that's supposed to be json value up there cannot convert that to that and cannot convert oh let's see response type [Music] see okay so first issue is going to be that these two are not matching so json value that's what i would expect that to be that resolves that issue the problem here is counter dot type um and it's looking for all what see can jump to the definition we could figure out what exactly it's looking for uh it wants a response type type r decodable counter should be decodable no by default because model i believe is decode yeah it's weird i actually think x hood might be wrong on this one unless this is supposed to be counter this is supposed to be counter okay i guess that's what it was okay so note to self update docs this right here is incorrect okay all right i'm back uh it is essentially a 3d scanning function never used it sounds cool though um object capture now that i'm thinking about it is that the thing that came out during one of the wwdcs where you're able to like scan something and then move it into uh like um scene kit or something like that and then you can like interact with it all right i'm back firstly i really wanted to try ios earlier but i didn't have mac secondly i want to work in big companies in their future and i think native is more suitable for it by the way flutter awesome yep totally agree um big companies still definitely using native you can still find um you know things like react native at big companies too uh but i don't think natives going anywhere to be honest all right we need to get this important part right here the document up and running so what we can do is i believe that we should be able to go to um appsync and we should be able to construct the same um graphql right here if we do queries yeah queries now what we want to do is we actually want to do a mutation so we're going to um clear this query right here and the mutation is going to be to update counter so we could get more screen real estate and what we want to do is we want to input value and what we want to do is we want to get back want to get back the id the value updated at and create it at oh we need id too so let me see so if we're going to do update then we need to have the id we need to have the value and we need to have the version so this is essentially what we want to do so instead of having to figure out how to write the graphql what we can do is we can just create it right here now i also want the id to be a variable um so we can do id how to do it like id or something anyways if you know how to use um the app scene console it will essentially allow you to create the query or the mutation the graphql code that you need in order to pass that value so um let me think i think if we copy this we might be okay you may also need this is the stuff that we're getting back then we don't really need it we'll keep that for now let's take a look let's take a look let's copy this let's see what happens that's all coding is just just do stuff and then you see what happens and if it blows up well it did something bad oh man i think because it's a data store enabled api you also need to have last change that uh version and delete it in the selection uh these additional fields in the selection set will allow other data store clients to react correctly in real time what's going on ivan all right so renee knows way more than i do so we'll also need to include um i think i think delete it is optional last change step you might need last change now i've done this before in the past and i know that i need it too but i couldn't remember what the second one was and i think it's last let's change that let's see what happens let's just let's let's bang our head on this wall until we figure it out but yeah i'm pretty sure renee's right we might need all three okay um are you dealing with uh realm no um i'm actually working with uh aws amplify data store uh it'll work without these fields but for the best real time experience you need to include those fields i got it okay okay so in the past i've done it with those two and i think it worked and then i think the deleted field actually only comes up in dynamo once one field has deleted in which case in which case everything else is set to null so i think that's what's up but yeah i know that you i know that you're right i'm just like hard-headed okay so let's go ahead and figure out how we actually pass in variables okay so id if you just go ahead and put it like that and then yeah pass it in like that what all right so we want to do mutation we want to do right here i believe we can just do id need to include this in our variables let's do id like so id eu id or this will actually be a string i believe string value all right id like that and then we will also need the version which is an integer like that all right i wish there was a better reformatting thing for xcode that did it the way that i wanted to do my format all right so then we do [Music] all right now we just simply need to plug in these values like that and trying to remember if this is it may need that last updated at that last change that i mean and this this is a big ass number okay so how do we make big ass numbers out of time pretty interesting let's see if we can do see if we can do an aws time time something date time date time let's do date time what was it called don't need to supply last change that oh okay cool because it makes sense that hey we're updating it now auto-generated service set awesome cool okay so let's see if this works we have the values that we believe okay so this is what we were trying to do before right let's see if it's still in the logs okay and if we take a content view let's take a look at what we were trying to do before before we were trying to do api mutate with a request we're going to do an update to the counter object right it's an update because we're using the id which we um already have right we're passing in a value but we weren't passing in an aversion and we're trying to just use the regular api api mutate api an api sandwich for you um anyways what we were trying to do wasn't working and we were getting this error right here right where you at right here something about underscore version not included uh we can't sync it when right it cries so then we create this graphql request um extension right and now all we need to do is provide the the id which we're already doing the value and the version if we could provide those three things then we should be good now um what we're going to do is we're going to first provide this how we're going to provide this we're going to provide this uh in a hardcore hard-coded manner where we're actually going to do uh what is it six well manually pass a six in here and then we'll essentially be sending this mutation doesn't matter what you call it let's go ahead and just keep that consistency right here where we do this and place it right there doesn't matter what you call it and we should be able to get back our id our value are updated at and are created at yeah so let's see what happens let's see what happens so we'll do funk api update with document then what we could do is we could do let request equals graphql request dot what do i call it update update counter right there we provide the the id so this is the counter id you provide the value which is going to be the current value plus one and then uh we do wait did we call it oh it's count let's count it's a variable that i have at the top i'll show you right now and right here we're going to do a hard-coded six just so that we can get it to work so complaining what's going on r could not be inferred it's weird i thought it was obvious that we were going to have a graph ql graph ql request counter like this r could not be inferred oh is it because i didn't do it like this there we go watch this that should work we could also just do this that should be right all right that looks like it's working now we just make it look pretty we have the request now what we do is amplify dot api dot mutate and then we pass in a request right which is our request let's call this something different update counter request just so that it's a little bit more legible right for readability too sometimes you know not all the time only sometimes we copy it paste it kablamo then then we do result publisher we do receive on uh dispatch q main then do sync completion we are only interested in the completion if it's an error otherwise we don't really care that it finished keep doing control c instead of command c there we go um we have this result we're gonna do essentially the same exact thing that we wanted but right here i'm gonna paste this here that should all continue to work and then we're also grabbing this a counter might not work only because we're working with a request and it doesn't know what type it's working with so maybe schema model schema schema maybe it'll be that i don't know see now get if we can get auto complete to work just a little bit better just a little bit better um [Music] okay okay it doesn't look like i'm gonna be able to find it here that's all right so then what we can do is let's just see what this sync result is uh oh we'll just say um let updated count equals count plus one for right now do updated count and updated account right updated count like so okay so so maybe it'll work maybe right we're using our manual request that we created ideally ideally we should get our simulator to pop back up come on ideally we would be able to hit this function when we hit api update and it's going to go to 6 automatically will it work i don't know let's find out let's find out together now maybe it'll update in the back end but we won't get like an update here locally on the ios app that can happen too so we just need to kind of figure out where the problem's at but now what i want to do is api update and we'll do with document then let's run it let's run it like a like a running back all right so we can see that we're at five we know that data store update is gonna work that goes to six probably shouldn't have done that now i have to go ahead and update this to seven idiot shouldn't have done that all right let's go ahead do this again um now there are logs let's see what happens when we do api update and we get an error okay so we didn't do something right um undefined variable id [Music] okay so when we were creating this we did something wrong on the request so at least it's kind of specific in that sense and we just go back over here right we go back over here let's see did we do something wrong i might need to add the inputs here yeah um okay so the problem if i spent a little bit more time with appsync i'd be able to do it manually but the problem is is that we actually don't have any values being passed in this i've done this before but oh here we go conditions maybe here we go oh is that that what i want i don't think this is even what i want hold on not sure if i broke it or not let's go ahead and exit this one out we'll we could create a new one it's okay don't need any of those we just need mutation and we do add and then we want to actually do this okay my mutation uh what's going on alexander we want to do input of these fields right and we need to get back the id updated value and this right but there's also a way to do like additional input all right so this isn't helping me i'm going to go back to the docs and just kind of copy it the way that they did it so if you look they're kind of specifying what is being passed in and i'm gonna do the same exact thing so uh we can see that we can actually copy this part right here and then just add to it from there only problem is that i need to figure out how integer is represented in apps uh in graphql so i think it might be int as well let's figure it out let's figure it out together i want to say it's in just like that that should be fine so first let's go ahead and paste this right here that is i don't know what that is what that is mate all right we do the mutation we have id we have um [Music] value and that's going to be an int and then we have um version and that is also going to be an int so assuming assuming that i actually know how to specify the type we should be able to do this api update and get a little bit further so hopefully the request isn't the issue now okay so graphql service returned a successful response um client version is greater than the corresponding server version client version client version is greater than the server version message client version is greater than the corresponding server version um let's see graphql error contains service service specific okay so i've done this before and i think we you need to pass in the same version number of what you have locally oh [Music] okay got it okay i don't understand it but i got it i understand where to make the change okay so version is this we do let's let's see what happens aren't you supposed to be on vacation man api update let's take a look all right let's see delta decode graphql response that's okay to the response type so that's okay so this is a decoding error which i'm very familiar with this could be a decoder error or something like that but but if we actually reload the app this will probably say seven let's check it out let's check it out oh oh look at that oh okay so notice it was six for a second then it needed to do it needed to do like a little bit of sinking but when he got the sink kablammo you got the seven okay we're getting there oh siddharth yeah you gotta do all that man thank you siddharth i really and i'm sorry if i butcher your name but i am super appreciative for for the for the generous donation really appreciate it thanks for all your videos kyle i found them very useful please make videos about amplified graphql transformer library especially v2 and resolvers i actually you know if this didn't take me so long i definitely was gonna cover some resolver stuff but i have something really cool that i'm working on and um yes there will be some stuff on that it's not going to be super deep because it's not something that i enjoy especially resolvers you're dealing with vtl files absolutely hate vtl um but i figured out how to do something really really cool which is doing an auto increment on something like this where we wouldn't even have to know the value that we're passing in we simply just do a plus one to the back end and it would automatically update and we wouldn't even know which value it is you could think about this as in like a likes counter right you hit like on auto increments to the next value so yes um you know i actually have that code you know what i could put you know what i have that code if you want to screenshot it and figure it out yourself by all means you can do that let me pull it up i have that code i've done it it was a pain in the butt to figure it out but i figured it out please let me just be signed in um hold up i gotta find it that's why i'm saying i know how to do all of the i've done all these things before but it's been a minute right here on this app watch here where do i go forget api right here see no it's appsync how do i get to the app sync thing again right here auto increment here it comes hold up been a minute back did i put it somewhere in here like it's like increment value we're pretty cool what the hell is it here it is can't see there it is okay okay i'm gonna stay right here and i'm gonna do this there we go if you wanna know how to do incrementing values it has to do with something right here then you have to do something like this right here remember you're going to need to use version if you're using datastore but if you want to screenshot this real quick this is how you do auto increment it has to do with oh and it has to be a specific version i think this is the specific version i'm using uh you have to do something about this expression you have to do this add balance plus one and then you have to like specify what the plus one is and it's like this something like that so yeah i'm gonna create a video on that i just need to go back revisit understand what i did and then um yeah it was crazy made it for a discord bot yeah okay so um so conflict detection happens in the back end which means that we need to do a query to get the latest version before we do that okay um we were getting some type of decoding error so we're not really using we're not we're not really doing anything that says like i'm actually kind of surprised that this doesn't work though because if you take a look at it i think we have everything being returned that's required to decode it but it's just not working okay coding keys id value created at updated at i would really expect this to work but um it doesn't that's all right i don't really care but i don't understand why it doesn't it's just kind of weird so um yeah it's just kind of weird that it doesn't so what we should be able to do is change this to json value and we put it right here and right here shouldn't have a problem right so now what i need to do because we did the update is change this to seven because in our back end it should also be seven if we check dynamodb if we do a refresh on this okay so according to renee what we need to do is we need to make sure that the version is the same as the doesn't say client version is not the same as backend version essentially this version has to be the same so essentially what we need to do is we need to do a query before we do the update um i might take a look at that but first i want to just make sure that we can get it working without any errors at all that would be ideal so we're going to do count plus one that should update it to eight i should update this to um so we have seven we're gonna turn it to eight we send that update up with the mutation request and then if everything works out we get this right here so let's go ahead and run that let's see if that works boom let's see let's see api update boom we got the eight looks like it worked to get any um bad i forgot to clear the logs before i did it okay um this all looks successful to me yeah i mean looks like nothing but success yeah okay so next what i need to do is i need to like understand what the type is and we printed that out right so everything seems to be working and we have this sync result printed so that's what i want to see now that's probably this object right here update counter value updated at oh it's a string okay id created okay so it's working there's there's two things that i want to do the first is i want to see if there's a way that i could fix it to where we receive a counter object back that would definitely be ideal let's see what's on the sink result object okay so this is a json value this is actually json value this is essentially what we specified in the request what we plan on getting back okay so theoretically we should be able to get that this json value and then pass in the number that we get for our value now there's got to be something in the docks that'll be something it doesn't might need a foul bug but okay so notice how they're receiving post back right and they did do something i think they did do something to the object to make it work does anybody know if you wanted to do multiple multiple operations right we can do a query right we do this this is doing two queries fine okay whatever i what i want to do is i want to do a query then i want to do a mutation can i do that do you think or do they have to be done separately like could i do mutation this be a mutation i do a get let's say a mutation i get post right and then i pass in a value of the return value somewhere in here that's what i want to know seems like it'd be a little bit too complex for graphql but never know graphql is pretty powerful um yeah yeah yeah oh i think i see okay hold on ah okay okay i see what i see what's going on response i see i see okay so what we need to do is we need to create a response object that's codable give it the same name as our thing get a response object hold up break it down in your head kyle what's going on i just do it in swift and flat map the result of one operation into another that's probably the cleanest way you're actually right this way i'm not like all working inside of the same string document right that makes sense okay so we create an object doesn't we create yeah we create an object doesn't matter what it's called then what we need to do is we need to we need to have a variable the same name as the actual function right and that and that variable is going to be of type whatever that type is so so if we were going to apply this same concept to our code what we would do i'ma just do it right here you'll look at everything so this okay so we would have our struct update counter record response right it's going to be decodable it doesn't need to be codable decodable will be fine um then what we want is uh we want to have a variable called update counter of type post like that not post you really man like so yep that seems right then what we do update update counter response that's what we're actually going to be receiving back do a copy you do a paste do another paste houston we have liftoff let's see if it works before we do that got a couple comments typically i try to avoid hard-coded graphql queries as much as possible because when the data model changes you need to review them carefully each time so it sounds like siddharth like it sounds like you work with graphql quite a bit like um so let me ask you a question because i don't work with graphql a whole lot i use graphql because datastore uses graphql um and i don't really want to build a whole entire rest api right so when you're writing graphql and you're working extensively with it in your project are you constantly creating these small little objects like i just did like we just created a small object right like do you constantly create small things like this like a whole entire object like this and for for both the input and the output i'm kind of curious like what that workflow is like because i haven't had to work with that not a whole lot but i've been using it since april this year i mean that's still a lot more than me for sure but like yeah are you constantly creating objects nope that's something i've been considering so what do you do do you create graphql documents in string format because i'm i feel like there's like this gap in in terms of creating these graphql documents like i hate the fact i hate the fact that this is a string right here and what i was thinking i was like maybe there should be like um a graphql components thing that builds this out for you like you know how there's url component like there should be graphql component i'm thinking about like just open sourcing something some little tool that would build this for you i don't know i need i need somebody that actually uses graphql to like kind of talk a little bit about that okay so you are using hard-coded string queries okay then there definitely needs to be some type of tool what's going on flutter map what's up i think i just i think i just saw something that you released on twitter yesterday regarding the update good stuff man yeah we can work on an orm or at least a query builder for graphql yeah like i feel i feel like that might be something something lacking but yeah if y'all are into flutter make sure you follow flutter map great content some of the best top of the line chef kiss you know good stuff all right so now we're at this eighth stage i believe we're at eight let's do a little refresher yep we're at eight and now i'm expecting to get back this this um update thing response right we have a response response and ideally if this does work we have response and then it has our update our update counter thing and then we do value like so let's see if it works shall we if this works i might be a genius all right so we're at eight now when we hit update we need to be at nine whoa okay okay all right docs need to be updated a little bit but yeah i got it all right it's almost it's almost like i know what i'm doing oh man that's pretty cool all right so we got some stuff in here i don't know what all that it's about but yeah all right so that's cool but but i don't know if that's exactly what we want to do because watch we're at nine right now so i need to change this to nine we're gonna fix we're gonna fix this little issue in a bit we we're at nine right now so we need to update this tonight but when i do the query when i do a query on what's happening locally it's not getting that update so it takes a second it needs to do its sinking little magic before it goes to nine so it's not really working and what we want to do is we want to observe the updates and this is the query observe is good for observing maybe new objects but maybe not for updated objects so let's see if we can actually observe a specific object or something like that observe specific counter let's try this all right so then we do amplify data store dot um [Music] what is it publisher or counter then we do um [Music] we'll just do a quick receive on and then we'll do the dispatch queue dot main and we will also do the sync let's just go ahead and do completion we'll just print the whole completion who cares just get it out of the way i don't even want to deal with it all right mutation event so then we have the event um print event let's just print it out i just want to see what happens before we get into the whole entire coding knit up and it doesn't even work right man i wish you a wonderful evening you are awesome for doing lives and helping people keela logo to the moon thanks thanks flutter map i appreciate that much much appreciated all right so let's go ahead and let's go ahead and do both of these functions observe counter and then observe specific kind of this is it's actually not even this is terrible naming about get counter reserve counter all right so um we'll do this observe counter do this get counter counter there we go so now we're gonna run both of them at launch and we're still at that nine so that should be nine down here yep all right so let's go ahead and run this it we should get 10 hold up all right so we're observing see if there's any changes let's see did we print out anything response 10 there we go so it is working okay so you can see here that it actually got the value updated right there that's pretty good so like in that it's looking pretty schmancy sexy schmancy pants all right next what we have to do is a guard let uh what is we want like the counter or something like that counter is equal to event dot decode decoded model as a counter dot self assert as self and then we do else return that right so we're going to get the counter white crying okay then we do self dot count is equal to counter [Music] dot value right run it back run it back also okay so see how that got updated see hold on yeah okay so we're about to test two different things at once right now kilo coin i actually thought actually there is a coin that i made somewhere on here watches oh you know what actually sketch kind of destroyed a lot of my stuff oh actually it's right there look at this look at that a code coin because um you know how i told you that i made something for uh the the increment counter it was actually a coin system on my discord so i actually had coins working and um i had to stop it because there was a bug in the code and i actually never restarted it again but yeah i made this little coin in sketch and i copied it from this vapor coin and uh i set up a lambda to do the auto increment thing um with appsync and then i was i would actually be able to tell the different um the different balances from my my app but i got busy and i never got to actually go back and fix it and finish it but yeah there's a code coin yeah it's lit for sure all right so we're gonna test two different things what happens if we have an older version that we try to push up with a new value and then also we're trying to see will this value get updated because we're no longer updating it right here we are only updating it when it comes in through the observed counter so let's do api update let's see what happens all right so it doesn't look like it worked and the reason for that is because the value that we're trying to pass is older than it's older than the um the one that's in the back end essentially so let's do api update watches should give us the same error and we shouldn't get an update so now we know now we know see does it give us like an error it doesn't really give us an error but it didn't work and it's kind of expected kind of expected a little bit of a bummer but it's kind of expected okay now another thing that i want to try is what happens if i remove the version here no that definitely won't work it's part of the logic that's what we were getting before i didn't work okay okay so what we need to do is you will need to perform a query to get the version and then we will need to do the rest of this all right so let's go ahead and try that now let's we're going to do api this is api update this is not the one we want to modify okay so it's this one update document should this happen all right so let's go ahead and do amplify api query oh so then we would also need the bang thing we'd also need to do a request for that bummer bummer [Music] bummer okay let's go ahead and build that query real quick it'll be fast i don't like that though do not like the queries are your outlier all right so get counter that means we need to provide the id yeah oh yeah yeah and what we want to get back is the version right yeah that's what we want to do then we'll just call this get counter and then we should be able to just loop and we do another another little another little blue here this is gonna be the query one static shock i mean function uh static function get counter version and all we need is the id this is going to do string and we do our whole little document like this like that piece it in like that and then we do um a return statement so this also needs to return a request graph ql request what kind of response we'll put the response up here say struct counter version response i call that get counter version let's get counter fonts decodable let get counter that this is gonna this would have to be a object bummer call it struct version version and then we'll do this decodable like that and then we'll do uh let value it uh enum [Music] this will be like a private enum right private enum coding keys uh string coding case value that should work this will then be version might as well just turn this diversion huh private uh enum coding keys and this will be string coding coding key case version get counter like that right all right there we go so now we should be able to say we want to get back this get counter version response like that copy it we will then do turn graph ql request this it right document document document variables id we also need to pass it here so id don't do that no don't do that this gosh what's going on uh id id that um lastly will be response response type is going to be get counter version all right so i think that's it all right uh are you using uh for what mmhm for overlaying your webcam feed over your screencast uh no i actually don't even know what that is mmhm i am using obs go ahead and take a look this looks correct so now we should be able to do uh request dot get counter version by counter id like that then uh we'll do result publisher then we'll do flat map then this little part where it's going to get a little bit tricky what does it give us back it should be giving us that response back it's going to give us back the same thing that comes here so then we need to switch on the result um oh man leave i forgot how to handle the results in a flat map that's pretty intense are you typing what what just happened okay so switch result case should all be the same right theoretically uh we should be getting back this type of object in case we have a success let response break case a failure let let error print the error right but then we also still need to return an object right here so we are going to be returning is this any publisher of success and failure with that's not helpful at all actually um okay so this returns like a any publisher something like this then you have to do this and it's going to return essentially the result of the get counter version and some type of error what is it the error is this a graphql response error graph ql response error let's see if it'll take this probably not okay and we will return this right here see now tell me that let's type not being heard what is this let me equals that and we should be able to get the type out sure interesting um the result api error api error okay so let's do api error bolts response error counter response that and that's probably going to work let's see it's a complicated system let's see let's see then we have to do see if we add the rest of it it'll work or not because you just gotta add the rest and it will start working a lot of times it does not this also might be result in error or something maybe all right so expect at least one argument oh this is it um sometimes you have to just run it and see what happens let's see what happens if we run it it will give us an update on the errors all right so see i don't think it's that either don't hold on results um [Music] i think we're missing one right here that's what it is hey what's going on cola um i'm not quite sure yet i am not quite sure i just really want to fix this if i go fix this then probably be done damn openings this should be two things go let's see a result and an api error okay yeah so that looks i think that we got all the all the little closing angle braces in there let's just assume that this is correct let's just assume that it's correct all right now what are you complaining about um this is definitely not correct okay so we call this r maybe maybe we can get a different thing one i feel like we're pretty close i guess without more context i have no idea what you mean we have this go ahead and copy it let's set it down again let p equals this find out what p is of course all right let me know what p is all right so if i were to just use this it should work but it's not this should just work not really sure why it wouldn't if all the types are matching it should work oh xcode had me trippin man okay so then what we'll do is we'll put this in here like so do uh response dot version dot value like that so now we'll be using the response version value perversion and then we need to when we need to actually do failure we can return just or what is it fail return fail and then we can provide an error but it has to be an api error dot um see if we could just do this one um okay that works that works now we need to race race to any publisher and we should be good and then we uh recovery suggestion do error error dot error description oh stupid hello there's an error right there for you to use why wouldn't you just use it duh uh cannot convert value of type um that error to that type of error oh that's why silly me error description and error dot recovery suggestion like so now what do you mean the immutable response was never used beautiful value response where is this coming from then you talking about xcode you're tripping goodness weird stuff okay so let's do uh do an api update okay so something broke along the way which is fine let's figure out where that break is all right let's okay so we actually never even tested the thing but let's see all right within parent counter what you're trying to say to me okay cannot return null for null type and within current counter oh do i still have bad stuff all right see let's try this again api update didn't work let's see what happened let's clear this let's do api update let's try it again and update response counter id value 11 there response websocket message not return null so i'm going to print the response here so print um what is this this is the counter version response and we got the response itself all right then we do the update counter and we'll do update counter response response like that i think this would work api update clear it pull it up counter response value should be 18. right it's coming up um so it should be like 18 or 19 now 19. okay so it was 18 when it made the query which is correct then it did the update to 19 which is also correct um update counter response value is 12. the value is 12 but it never gets updated okay discord you're being kind of weird right now sudden okay so what happens if we do this 12. and then i feel like we're not getting the data store updates anymore print data datastore update value saved value and this is not even the right place to do it so that's pretty cool um observe counter event dot and we'll do event counter or we'll do counter there we go all right so now we should see where this thing is breaking down okay um have you read jordan morgan's book would you recommend it um without trying to sound rude i don't even know who that is jordan i don't know who that is uh let me shadow you to become uh s-e-s-m-e for amplify uh well i can't really just let you shout i mean you could i'm gonna be on twitch a lot you shadow that way you go over an amplify a lot that's one way um yeah but other than that yeah all right so let me see one second all right so [Music] let's find out where this is breaking down api update because we're sending up the data so we get the the counter version it's on 20 that seems about right right so if we made an update then if we check down dynamodb it should be 21 which means that it was right when we did it so that's that seems like it's correct um if we go back to our app uh update counter response okay we get the response back the value is 13. right okay however we never made it we never made it to the update area so i'll use 13 we're still stuck on 12. yeah we're still stuck on 12 which means that it's somewhere at this point up here in the observed counter that we are not getting it so we'll go ahead and print the event all right so we get the mutation here get the event here all right let's clear all this out let's do another update api update we don't get another event so it's being stored properly i'm not getting the update to trigger that's interesting we're getting the update to trigger before and we're not getting the update to trigger now if i take out this bottom half this out do this and paste it back up here some stuff will undoubtedly break right worse uh this will just be like 21 or something like that 22 i think go back to dynamodb figure out what the current version is go to dynamodb we do a refresh we're going to manually enter in a 22. all right we enter into is it 21 or 22 yeah 22 that's correct manually enter in the 22 then we do this and move this everything else should just kind of fall into place there we go so this is essentially the code that we had before we tried to get the version dynamically all right so if we run this i believe this was working so then when we do the update you see that the number is 14 right 14 like it was here we'll do a refreshes and next just to make sure everything's you know up to date see let's take a look at our simulator as well we do api update and we're not getting anything so this was working before i'm pretty sure but now it's not working and it could be that we are that we broke the sink somehow could be that so what i want to do is i also want to modify the this one right here just do print saved counter run it so the update happened the only thing is that we're not getting the the event to come back and say that it happened right so if we do a data store update right here we're still getting that update see so we got the up the mutation event right here this worked so that worked i'm going to also go back to dynamodb let's refresh it should be 20 24. i hit twice something like that 16. if all right 16 that's looking correct now if we go to studio we go up to our content go ahead and do we have the freshest so now when i do 17 right i save counter should 17 right there dynamodb should still be out of date because we haven't refreshed the page it should go up to 25 and 17. 25 and 17 that's looking correct so that's working there so it really comes down to our mutation there's something wrong with our mutation 25 and 17 right so now if i if i put 25 let me double check i might have i might have done the test wrong because remember we have to update that one number every time when we're doing it manually so now we're at this 25 number so those two numbers match and when we do [Music] api update we're still not getting the correct value okay let's see should've um let's see if we can figure out exactly what happened right when it happened update counter response seventeen data store update value oh that's right okay so this is 18 what happened right here update counter response we have the value 18 um [Music] okay cannot return null for non-null type aws timestamp and parent counter on update last change i wonder if it's because we're missing the last change that value could have broken something that's definitely possible but all right so i think we have aws timestamp right i have to import something else or aws something ews time stamp dot now admit the serialization that's not even what i want that's not even what i want all right um let's take a look at our amplify models because they have dates and then temporal date time and schema all right so let's go ahead and go back over to this update counter thing let's do um let temple let time stamp temporal um date time dot now i wonder if this is the right one i think it would be this all right so print timestamp let's just print it out i need to see it i need to see it all right so we'll do that's all updated clear it api update okay not sure if this is what it's going to want that's the only problem i don't want to figure it out though the dynamo where's our appsync query created at happens if i do this oh hold up it's not gonna work don't all right we need to actually have a value to pass in right here i can manually do it like that we run it we get version 27 looking pretty snazzy going on cozy jose all right let's do let's change that again this is a number get that number uh right now i'm working on using aws store with um the api category and updating the values um like being able to like actually update those values so that we can have them update in datastore as well so now not this format right now right at the second i'm trying to figure out how to get this into a hmm like let's see i want it to be this but i want it to be a number maybe foundation date dot time sense and if we run that we can check how close it is check how close it is to the number so we do api update it prints out big number like this all right so [Music] let's go ahead and co because the other one doesn't have any decimals at all looks like it's 10 numbers long so 3 3 3 ten so that's ten plus another six numbers after that so 16 numbers in length let's see what it's showing us back here so three three three and then this so we need to do it times a thousand and then send up that value let's see what happens if we do that so this is a number times a thousand and then what happens if we um in int round do we have round uh this should actually work see it's definitely a number is it a integer let's see what happens if we try to send it up like this well let's print it first time stamp so run it how did i teach myself how to code um a lot of youtube videos um anything i could just learn for either free or cheap that's kind of what i did and i just kind of kept following like what i was interested in three three zero one two three okay that's the correct format let's go and put it in time stamp time stamp like that and if we do time stamp let's just do in let's see what happens maybe it'll blow up maybe it won't uh and the value we want is going to be the last changed app right there we go yep let's see what happens all right see let's see check filled value update counter input oh i do have two two of those huh thanks thanks cozy um i don't think that this would have worked anyways because we are actually trying to do something that is not allowed because this function doesn't exist once again errors timestamp okay unused it's unused me me me me me what just let it ride all right so let's try this again not really sure why it's not updating non-nullable message cannot return null or non-nullable type cannot return null for non-nullable type maybe i need to return version is that what you're saying that can't be right that most certainly can't be right i'll return null for non-nullable type but for which field do not return null for non-nullable type aws timestamp with last changed who told you to do all that would hold you to do all know that let's see then this looks different this looks more successful hold on there didn't update hold on okay so yeah okay so this is a little bit weird but let's go ahead and make sure that we're sending the right version now so we'll go back over to dynamodb you know pass in version 34 and theoretically we would get everything back so now let's go ahead and clear this we pass in 34 we do it and we get 19 boom okay all right so jeez that is um that's that's tough okay the problem problem was with the decoding key interesting so the coding where where's the decoding logic though oh shoot that's interesting okay hold on i bet you they're decoding they're i bet they're overwriting the decoding method and it's doing something weird okay okay okay i think i understand now all right something weird was happening um essentially so that in case you get lost too or is it essentially what's going on is like i think in the background they're decoding something using this model method and it was not working because we were missing a couple of those values and this would not be a problem i think it should have still worked it shouldn't matter what i'm trying to get back that's a weird thing yeah we have to look into that okay so now that that's working now that this is working should be able to comment it out go back to this logic over here where we're dynamically looking up the value of the version and then we're updating high kilo trying to design an app to send pics from ios device to mac os for processing any suggestions on how to start things um i think the first thing that i would try if it was me i would just be probably trying to work with amplify you know um and i would probably just try to set up storage upload the image to storage and then i'd be able to download that image on storage and then you could theoretically do the processing whatever your program does and then send it back up to storage and then it would be done on um it would be updated next time you open the app or whatever that's probably the way that i would do it but i mean i'm obviously amplify biased and that's like my comfort zone so i would try okay cool look at that it's updating properly cool all right so we got it all updated it took forever this is like a really long stream i thought it was going to be like an hour long it took like a while it took a while because we kept running into these little things but at least we got it so now we're able to actually use api and um datastore together and the only reason that we're able to do that is because we're manually creating these documents we're manually creating these documents and then what we're doing is making sure that all these values are included this is still this still is kind of weird to me i don't know why this is like even if you're not interested in this it needs to come back that's kind of weird but yeah anyway yeah i don't know it's just like i don't know it's kind of weird it didn't start working until i started doing that i wonder if it's trying to observe those things locally that would be interesting not to ask the team what's going on joseph welcome to the stream but we are actually closing out so um i had a lot of fun today i got to code a lot um learned a lot and uh yeah like i will be compiling this into a very short video so that we can understand it a little bit easier take all these files compile it into a little video for y'all and i'll put it out sometime next week but yeah really appreciate everybody for coming uh once again want to say big shout out to uh uh what was the name i want to make sure that i pronounce it right before i like mess up siddharth for giving that 20 cad really appreciate that and yeah be on the lookout for streams i'm thinking about doing streams around time you know as often as i possibly can and we'll go from there but yeah thank you for joining the stream and make sure you go out there and keep going passionately you
Info
Channel: Kilo Loco
Views: 457
Rating: undefined out of 5
Keywords:
Id: uoGsGtj_bks
Channel Id: undefined
Length: 147min 3sec (8823 seconds)
Published: Thu Dec 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.