#122 More on GraphQL - Organizing and Refactoring


In this episode, we take a look at our GraphQL API that we created from Episode 119 and refactor the mutations and queries so that we keep the structure and API manageable.
rails api graphql 10:32
  • Student & Teacher
  • $9.00 / month
  • Valid School Email Required
  • Same Access as Pro
  • Subscribe Now
  • Pro Membership
  • $15.00 / month
  • Access to Pro Episodes
  • Invite to Slack Channel
  • Priority Episode Suggestions
  • Ad Free
  • Subscribe Now
  • Teams
  • starts at $75.00 / month
  • 5 Users Minimum
  • $15.00 / user / month
  • Same Access as Pro
  • Subscribe to Teams
they're handing now yeah and that and that and learned linked in or three keys for the love said we love dead using the twenty to help to manipulate and and record store data base we also look at the wall to return records and over on the right hand side we can see that all the records returned as an air raid and it's a hundred feet name space stayed up and then in our case all users because as well he declared over here and are clearly and that's episode we wanna look to be back to some the grass q will stop because once or application grows in a pr he grows even the graphic you what makes it fairly manageable to work with these things the mutations in the query skin discharge get out of control with rescue well the mutation tied to the choir times seemed to be a dumping ground for most of the launch of the whole other side of the queue of you don't have too many models to work with the desk it to be a much bigger issue if you have pundits model say you were born to be exposing to the se pr so if we look within our grasp que else came up we ever mutations in there we also have for queries most reference for two files within the query type yeah some information an us so we have two fields that are relating to the user and the cell would want to extract out just so we're not putting in all hope when to code within your because answer application get to the more complicated or results may also get more complicated and to have all that this information right within the same file sounds good it cannot glee so water at a rescue well for her and then create a new folder called was all first and within year for example with their field user they create it was over the edges finds this particular user so they had no room in this for now and we're going to resolve the result years and with this field maybe in user and is going to have it called users here as well so within our result for us we can create a new file and we'll just call this the user daughter be then here we have our mortal resolve ers that we have our class user and it's going to expect a call method within the comment that we needed that center three arguments what safer not to be used in the object or the context then you could just know take these with underscore the no way you know that they're not being used poland recently the spacing in there we then find a reserve the only thing close everything else it's already this looks a lot cleaner especially in it or all users or this could also be a bit more complicated the within the result was okay a ton of wild in a call this the all users on her feet nope this is incredibly head from our user better be and i'm just going to change it up a little so we'll call this won't be all users and instead of finding a user versus going to return the call the lever we don't want to reference the user here as it would pertain to the user within our resolve ers and said we wouldn't have that tor project a week you get that with easy to call once they're fun of our user and same thing for our user daughter be where we want this reference to order an application back in or query time have resolve ers really bad center all users that name and so if we try to clear we are all users you see there we entered in the back to cycle was before and if we wanted to sell finding their user can't find the user with the id want them are just going to return the first name and then you see this works as well and again you want to determine what works well for your team and four year project glover i don't like having these different had agreed to answer me tissue types mixed a lift my actual field types that will be using so and creating another folder and this forward know it's probably not the best named oliver and just pinnacle models because of what this to reference to something that would they be pulling data from it's your user types like to move up into the models for her and i just want to recall this and and discord to call it the user so now are types user types will become the models and then user we will need to go to the application and change their name where for we used to it so within our queer retired you said in a few places will we reference finding the single user then what will we found all users so now we can change the study models users and then also within our mutations under the create user we also had this reference as well because we're we're we're turning the user object whenever we'd finish creating a and so if we were it passes out again so get hurt in the back alley go back to the all users and one this and we sold in our day the back and everyone rare mutation we're we're creating a user with a first name last name you know birthday and they were going to return a user object with the id first name email him birthday you see that we still get this information back and it also works so we've not affected anything on the client side or when you're in users would be interacting with water on the backside we have simplified how we are organizing the files and some some are quite happy yet because this is still kind of messy 'cause again if we had users company's products in a lot of other models so we're dealing with this is still going to be rather huge so i wanted narrow this down a little bit more so does feel abuser on what to remove all of this information in them woods we recruited we can pass and our query and the queer read that we're going to create integrating queries fall for it within their we're going to create one called users they will create a field called user so with an aircraft you are correct rate will create a new for the local this queries then the queries we need to know the new folder called users in the early game creator user data are being file and so within the user are being i need a color queries then the users and finally our user or setting the sequel to the graft you well and field and we needed called the following week has center block and then everything that we ate cut from our queer retired we had a skinnier so we reference or queries users user within or query type how does work so now if we weren't as you see that we get her dead back million also just as in something like he had he does make sure that we're getting our didn't and there we have it so well with are all users was good in tucson things some more we're we're gonna call queries again then our users and this time i'm anna calvi all users better remover feel properties here and then hundred queries folder in the user for o'grady new one called the all users it will basis in here let's wrap it with their queries users all users and this is you want to be graft you well field but declined there we pass center block then that show bark so now with the rescue out of the color all users query he has see that we entered in the back end it all works decided that before without any cannon changes or graph que el query and so what season it means spacing the queries you may want to also come back into the result hours their surnames be seen these as well when does call our users for her i am going to smooth these two files within their and then within each one of our queries what is set to update 'em to use the new users and so love this this maker for or structure of the more complex i think that this is going to be a lot more manageable in the long run at these are heading and hundreds of different kind of queries and mutations and if you remember from our previous episode one nineteen we are intended to something similar with thirty patients were we created the creed is repealed patient in in the mutation kind we just simply reference the creators are with the field in there we had her mutations create user don't feel as if acquiring more so than a bit different an incentive to call in the field and outfield it to me and you just simply call the object so with every day since the one what the policy and with everything else that we've done here where al which creating new folder called users would movie create user under there and i'm a clean this up the bed and i made changes cities of the like mutations users and so with having our mutations users create a user one in a calm down into our mutation type then bradford said there so is the deal i'm a big fan the name spacing especially when it said run into daylight that's just makes it all wrong on life easier for me to keep track of one thing they you may consider doing instead of having the different folders for the models mutations queries and resolve ers you could have with this round or you would have been for for users there within their you that the different than the mutations queries and resolve ers but again that's really up to howl your project is styled and when your team is going to be most comparable wet for me than ever endure with queries then hundred to come on to queries and then act i'm fine my name's they seem to find the users and know what i'm trying to interact with the dating get the day that i can come over and to the blues offers i can see where is making the calls out and about what to talk about the structure of that type making or her mom models and get it there as well what does offer this episode they get fortune