Butinactuality, allgraphiculisis a specificwaytousetoolsthatwealreadyhave.
Graphic.
You'llisjust a specificationsinbuiltaroundHttp, forhowyougetandreceived.
Resourceisfrom a server.
Normally, you'llbeusingsomethinglikerestwhenyouinteractwith a serverandyou'reusingrestfulendpointsandthehttppostgetdelete, updateallthatfunstuffforhttprequestsusingrest.
Using a typicalrest a p i n pointasourfirstchoice, wehavetoendpointswecanuse, whichistheauthors, andpointtogetalltheauthorsandthen a separateandpointtogetallofthebooksfor a particularauthor.
Sothefirstthingthatweneedtodoisweneedtoaccessthatauthorsandpointtogetback a listofallauthorsandwiththatlistofauthorsweregoingtobegettingbacktheideaofauthorsandthename, whichiswhatwewantforapplication.
We'realsogoingtobegettingback a bunchofextrainformation, suchaswherethatauthorlivesandhowoldthatauthoris, whichwedon't reallywantforthispagethatweredisplaying.
Sowithjustonequerytotheserver, youweregoingtobegettingback a listofalltheauthorsandtheirnamesand a listofalloftheirbooksandtheirnamesandnoextrainformation.
Later, we'regoingtotake a lookatbuilding a graphicyou'llserverusingknowJsandexpressanotherthing.
Thatgraphicyou'lldoesthat's incrediblypowerfulisitallowsyoutomutatedataonyourserversoitallowsyoutocreate, updateanddeletedatajustlikeyoucoulddoanarrest, a p I.
ItalsohassupportforAres, soyoucoulddoairhandleinside a graph.
Cool.
Andreallyitdoeseverythingthatarrest a P I cando, exceptforitmakesitsomucheasierforthefrontendofworkwithanditmakesitsomuchlighterweight, sinceyouonlyhavetoaccesstheserveronetimeeachtimeyouneedsomethinginsteadofmultipletimestogetalltheinformationyouneed.
Sonowthatwehave a basicunderstandingofwhatGraficoisandwhyit's sopowerful, let's getstartedbybuildingoutandnoJsexpressapplicationusinggraphicyouOh, wherewe'regoingtotakethatbookandauthorexampleandfullyimplementtheserversideofittogetstarted.
Theveryfirstthingthatweneedtodoisactuallysetupourexpressserver, whichisjustgoingtobe a verybasicexpressservice.
Thefirstthingthatweneedtodoistorunin P m init.
Inordertocreateourdifferentpackage, JasonFilesandwejusthitenter a bunchoftimesheretogetallofthedefaultvalues.
Andasyoucansee, wenowhave a packageJasonfilewithallofourinformationinsideofit.
Now, ifwesavethatandgotothateurographicyouOh, you'llseethatwegetanairsayingthatweneed a schemaforourgraphicyouwillandthewaythatgraphicyou'llknowswhichdataaccessbasedonthequerythatyousenditisyouhavetodefine a schemaofhowallofyourdatainteractstogetherandthatSeemaiswhatweneedtopassintoourexpressgraphiculfunctionsothatourexpresscraftColeknowswhatareactualGraffkilldatalookslike.
Solet's justcreate a dummyqueryheretoseehowthisworks.
Soinordertocreate a query, weactuallyneedtoimport a fewthingsintoourapplication.
Soifwegouphere, wecansaythatwewanttoimport a fewdifferentthingsfromthelibraryofgraphicyou'llthatwementionedearlier, andwewanttoimportourschemeofFirstofall.
Sothere's anobjectcalledgraphque o schema, andwealsowanttoimporttheobjecttypebecauseingraphic, you'lleverythingisactuallystronglytype.
Soanobjecttypejustallowsyoutocreate a dynamicobjectfullof a dufferandotherdifferentothertypes.
SoinherewecouldjustsaygraphicyouOh, objecttype.
Andthatwillbeanactualobjecttypethatwecanimport.
Andnowweneedtocreate a newschemeofSowe'lljustcallourschemethathereequalto a newgraphiculschema.
Andhereiswherewedefineouractualschema.
So, like I said, we'rejustgoingtobecreating a dummyschemeithere.
Andthenwecanusethatasourtypedownherefor a message.
Sonowgraphicalknowsthatourhelloworldobjecthas a messagefieldandthatmessagefieldisgoingtoreturn a string.
Andthenlastly, weneededtotelegraphcool.
Wheretogetthismessagefromsoanarchist.
Wejustwanttogiveit a staticmessageofhelloworld, Andthisisgoingtousetheresultssectionofthisobject, whichisjustgoingtobe a functionthattellsgraphicyou'llwheretogettheinformationfrom.
Sowejusthave a simplefunctionhere, andthisfunctionisjustgoingtoreturn.
Sonowifwesavethatandrefreshoverhere, you'llseethatwegetthisgraphicalinterfaceoverhere, andyounoticeimmediatelythatwegetintheresayingthatthenamefor a helloworlddoesnotactuallyworkbecauseitcontains a spacewhichisnotvalid.
Inourcase, thiswillbeauthorsandbooksinourrealapplication, butfornowitisjust a singlehelloworldobjectnext, insideofeachofourdifferentobjects, wehavewhatarecalledfields, whichareallofthedifferentsectionsofthatobjectthatwecanactuallyquerytoreturndatafrom, inourcase, just a singlefieldofmessage.
Butfor a book, thiscouldbethenameofthebook I ESPNthecoverartofthebookandsoon.
Andthenwehave a resolvefunctiondownhere, whichisgoingtobe, whatactualinformationarewereturningforthisfield?
Thisisjustdataforthreedifferentauthorsandeightdifferentbooksassociatewiththosethreedifferentauthorsandwherethere's goingtobeusingthisinplaceofsomethinglike a database.
Becausewedon't actuallywanttoworryabouthookingup a databaseforthissimpleapplicationandthesetwocollectionsofdata, thisauthorisvariableinhisbooks.
Variablewilljustbeourdatabaseforthisapplication.
Next, we'regonnawanttocreatewhat's called a routequeryscope.
Solet's removewhatwehaverightnowandcreatethatrecruittypesowecouldjustsaycreatedVariablewillcallrouteClearytypeandthisisjustgoingtobeanobjectsowecanjustsetitto a newgraphic.
Sowhathaspassedthis a functionandthereason I'm wrappingthisfunctioninparenthesesthat's returnhereisthat I don't actuallyneedtoadd a returnstatement, sincethiswilljustreturneverythinginsideofthepremises, whichisjustthesingleobject.
Soit's justsavingus a littlebitofwritingthere, andwhatwewanttodoiswe'renotactuallyreturnbooksfromthisquery.
Sowecansaywewanttoreturn a listofbooks, whichisgoingtobethisbook's keywordhere.
Andwejustneedtosupply a differentobjectforthis, andweneedtogiveit a type.
Andinourcasebooksisjustgoingtobe a cuffsaccustomedgraphic.
You'llobjecttype.
Sowewanttocreatethatgraphicalobjecttype.
We'lljustcallit a booktype, butwehaven't createdyet.
Butthisisjust a placeholderforthattypewillbecreating.
Well, then, giveit a descriptionhere.
Wejustwantedtogivethisthedescriptionof a listofbooks, andthenweneedtodoresolveforthis.
Soasweknow, thisbooktypeisjustgoingtobe a customobjectsowecancallcreativevariablecalledbooktype.
Saiditequaltothatnewgraphicyou'llobjecttype.
Sincethisis a customobjectandinhere, weneedtodothesamething.
Weneedtogiveit a name, which, inourcase, justgoingtobecalled a book.
Giveit a description.
Thisisjustgoingtosaythisrepresents a bookwrittenbyanauthor, andweneedtospecifythefieldsforthebooksoagainpasses a functionwrappingitinthoseparenthesessowecouldjustreturnthatobject.
Andinhereweneededtofindourfields.
Asyoucansee, wehaveour i d field.
OurnamefieldaswallsareauthorField.
SowhatSpecifiedthoseNowwehave i d Thisisgoingtobethetypeofgraftyouwillinwhichwehaven't actuallyimportedyet.
Andthisisjustsayingthatthisisgoingtobeanimager.
Solet's importantthistypeuphereandoneotherthingweneedtoimportiswhat's calledthegraphque o nonknoll.
Andessentially, thismeansthatyoucanneverreturn a novalueforthistype.
Animagerisalwaysgonnabesupplied.
It's nevergonnabeno.
Sowecanactuallyjustwrapthisin a newgraphic.
Youwillnotknow.
Actually, youdon't evenneedthenewhere, sowejust a graphiciononnographic.
You'llend, andthat's thetypeofour I D.
Andwedon't actuallyneedtosupply a resolvefor I D.
Because, as I saidearlier, sincewehaveanobjectherethatalreadyhasan I.
D property, it'llpullthat I d propertydirectlyfromthatobject.
Sothenextthingwewanttodoisaddthenameinhere.
We'regoingtobeverysimilartothe i D.
Butthetypeinhereinsteadisgonnabe a graphic.
You'llstringandagain, it's goingtobenonknowable.
SowegotthenonNo, andthat's allweneedtodo.
Wedon't needtoadd a resultagainforthis.
Andlastly, wehaveourauthor I d Whatisgoingtobeexactlythesameasourintforidea?
Pierce, Wecanjustcopyandpastethatdown.
Andtherewego.
Wehaveourfullbooktypealreadytofind.
Sonowthatwehave a rootquerytypewhichisusingourbooktype, wejustneedtocreate a schemaandthenusethatschema.
Sojustcreativevariableherecalledschema.
We'regoingtosetitto a newgraphic.
You'llschemaandthisscheme.
As I said, it's goingtotake a queryobjectandthisisjustgonnabeourroutequerytype.
Weneedtospecify a customresolveforhowwegetthisauthor.
Sowhat's atourresolve?
Makeit a functionhereandthisfunction?
Wejustwanttoreturnhere.
Wewanttoreturn.
Wewanttosearchtheauthors.
Wewanttofindtheauthor, andwewanttofindtheauthorwiththe i.
D.
Fromthebook.
Buthowdowegetthebookthatthisisbeingcalled?
As I mentionedearlier, thisresolvetakesapparentpropertyhere, whichinourcase, isjustgoingtobe a book.
Sothisauthorisinsideofthisbooktype.
Sothisisgoingtogetthebookpassedinherethatisbeingqueriedforthisfieldsowecouldjustcheckwhenthisauthor I d.
Isequalforthebookofftheidea.
Thenweknowthatthisistheauthorforthebook.
Andnowwhatweneedtodoiscreatethisauthortypesothatwecanactuallyreturnit, andwe'rejustgonnadothatexactlylikewecreated a booktypehere I'm actuallygoingtocopythisbecause a lotofitisgoingtobeexactlythesame.
Wejustwanttogetitwherethebooks I D fortheauthorisequaltotheauthorthat I D.
Thisisjustgoingtogetus a listofallthebooksfortheauthor.
Andnow, ifwesavethatrefreshoverhere, younowsaythatweget a listofallthebooksforeachauthor, andthat's perfect.
Thisisonesinglequerythatwe'rerunninghereandin a normalrest a p I.
Thiswouldrequireustorunonecareerfortheauthor's Anotherqueryforthebooksforauthor, oneauthortoandoftenthreeFlowbeforequeriestotal, anditwouldreturnus a bunchofinformationthatwedon't actuallywant, suchastheideaofthebookandtheauthorideaofthebook.
Butwhatifwewanttojustgetonesingleauthorinsteadofgetting a listofalltheauthorseverytime?
Well, that's alsoincrediblyeasytodowithGraficobecausewecanactuallypassargumentstoourgraphque o methodshere.
Solet's lookatdoingthat.
Ifwegodowntoourroutequeryhere, wecanjustdefine a newquery.
Soinstead, AquarianBooks.
Let's saywejustwant a query, a singlebook, andthisisgoingtoworkverysomeoneonlytwobookshere.
So I'm justgonnacopythis, pasteitdownhere, andwearen't returning a listthistimewerejustreturning a singlebooktypesowecanchangedescriptionhereaswelltojustsay a singlebook.
Andinsteadofreturningbookshere, wedon't reallyturnjust a singlebookbasedontheargumentwepassin.
Sowewanttopassinthe i d ofthebookwewanttoquery, andwejustneedtogiveit a typehereSowecouldjustsaythetypehereis a graphicyou'llintandthatwe'veactuallyfindthatthisbookqueryrightherefor a singlebooktakesonesingleargumentof I D.
Andinherewecanactuallyusethat i d argumenttoqueryourbookssowecouldjustsaidbooksnotfindWewanttogetthebookwiththatidea.
Soourideaisgoingtobethat I d argumentwedidfindrighthere.
Andthisisjustgoingtoget a singlebookbasedonthe I d.
Again, Ifyouhad a database, youwoulddodatabasequeriesinordertogetthis.
Andnowifwegooverhereand a graphicalrefreshitsothatwegetoursyntaxhighlightingWeakenQuerybookandwejustpassand I D inhereofwhatSaywewanttogetthevery 1st 1 I d.
Let's justgoauthor, wewant I d to, forexample, andwewanttogettheirnamenowifwerunthat, yousaidthatwegetinthereandthat's becausein a result, functionhere, weactuallyneedtospecifythatwe'reusingthearguments.
Sowegiveit a typeinourcaseisadding, a bookisgoingtoreturn a booktypeforus, giveit a description, justsayat a book, andthenifwewanttopassartsbecauseweactuallyneeddatatopasstotheserverforustoeadd a book.
Inourcase, weonlyneedtwoparameters.
Weneed a name.
Firstofallforthewhatthebookisgoingtobecalledandthisisgoingtobe a typewhichisgoingtobe a stringtype.
Insteadofstringanauthor, I d isgoingtobeanimagerandthenourresolvefunctioninsteadofactuallyqueentoreturndata.
It's goingtoeadddatatoourlistsowecansayresolve.
We'regoingtouseparentandArgushereagainbecausewewanttobuildaccessthatartistparameterAndthenthefirstthingwewanttodoiswewanttocreatebooksowe'llcreate a bookobject.
It's goingtohavean I.
D whichisjustgoingtobethelengthofourbooksare a plusone.
Ifyouhad a database, thisthiswouldbeautomaticallygenerated.
Soyoureallydon't needtoworryaboutthistoomuch.
Ournameisgoingtobeourguestdotnameandourauthor I d isgoingtobeharddockauthoridea.
Wewanttobereturnedinourcasewilljustreturnthenameandthe i d for a book.
Now, ifwerunthat, youshouldgetanideaofnineand a nameofnewnamewhich, ifwelookupatourRayoverhere, weseethattheideaofnineisthenextinthelist, whichisperfect.
Sonowifwegotoqueryallofourdifferentbooksandifwejustwanttogetthe I d andthenameandwerunthatyouseethatwenowgetourninthbookdownherewiththatnewnamethatwespecified.
Now, assoonaswerestartourserver, thisisgoingtobedisappearedbecausewe'renotactuallypersistingto a database.
Butyoucanseehowthisworksfor.
Ifyouwantedtouseitin a realapplicationwiththedatabase, youwouldn't havetoworryaboutthatproblemofitdisappearing.
Butinsteadofcoinat a book, we'regoingtocallitatauthor, andit's goingtobeanauthortype.
It's goingtoaddanauthor.
Wehaveourname, whichiswhatwe'regoingtoadd, andwedon't actuallyhaveanythingelsethatweneedtoaddforanauthor, and I resolveddownhereisgoingtolookverysimilar.
Butinsteadofbeing a book, we'regoingtobecreated a newauthor.
It's goingtobeauthorsdotlengthforthe I D, andwedon't actuallyhaveanauthor.
I d forourauthorandwewanttoaddthistoourauthorsreadyinsteadoftoourbookarrayandthenreturnthatauthorandeveryguiltwe'vecreatedfor, addedanauthor.
Sinceyoudon't havetocreate a bunchofcustomandpointseverytimeyouwanttoget a differentsetofdataback, youjusttelltheserveryouwantdifferentdataanditgivesittoyou.
Itjustissmartenoughtoknowthat.
Andthat's allthebasicsofwhatyoucoulddowith a graphicalserver.
Usingthesetoolsinthisvideo, youcancreateaninfinitelylargegraphicyou'llserverthatcandoeverythingfromupdatingtodeleting, tocreating, togettingdatain a muchmoreefficientandfasterwaythanarrest.