AirbbCloe-GraphQLServerExamplewithPrisma
Thisprojectdemostrateshowtobuildaproductio-readyapplicatiowithPrismaadgraphql-yoga.TheAPIprovidedbytheGraphQLserveristhefoudatioforaapplicatiosimilartoAirBB.
GetstartedNote:prismaislistedasadevelopmetdepedecyadscriptithisproject'spackage.jso.ThismeasyoucaivokethePrismaCLIwithouthavigitgloballyistalledoyourmachie(byprefixigitwithyar),e.g.yarprismadeployoryarprismaplaygroud.IfyouhavethePrismaCLIistalledglobally(whichyoucadowithpmistall-gprisma),youcaomittheyarprefix.
1.Dowloadtheexample&istalldepedeciesCloetherepositorywiththefollowigcommad:
gitcloegit@github.com:graphcool/graphql-server-example.gitNext,avigateitothedowloadedfolderadistalltheNPMdepedecies:
cdgraphql-server-exampleyaristall2.DeploythePrismadatabaseserviceYoucaowdeploythePrismaservice(otethatthisrequiresyoutohaveDockeristalledoyourmachie-ifthat'sotthecase,followthecollapsedistructiosbelowthecodeblock):
cdprismadocker-composeup-dcd..yarprismadeployIdo'thaveDockeristalledomymachieTodeployyourservicetoapubliccluster(ratherthalocallywithDocker),youeedtoperformthefollowigsteps:
Removetheclusterpropertyfromprisma.yml.Ruyarprismadeploy.WhepromptedbytheCLI,selectapubliccluster(e.g.prisma-eu1orprisma-us1).Replacetheedpoitiidex.tswiththeHTTPedpoitthatwaspritedafterthepreviouscommad.NoticethatwhedeployigthePrismaservicefortheveryfirsttime,theCLIwillexecutethemutatiosfromprisma/seed.graphqltoseedsomeiitialdataithedatabase.TheCLIisawareofthisfilebecauseit'slistediprisma/prisma.ymludertheseedproperty.
3.StarttheGraphQLserverThePrismadatabaseservicethat'sbackigyourGraphQLserverisowavailable.Thismeasyoucaowstarttheserver:
yardevThedevscriptstartstheserver(ohttps://localhost:4000)adopesaGraphQLPlaygroudwhereyougetaccestotheAPIofyourGraphQLserver(defieditheapplicatioschema)aswellastheuderlyigPrismaAPI(defieditheauto-geeratedPrismadatabaseschema)directly.
IsidethePlaygroud,youcastartexplorigtheavailableoperatiosbybrowsigthebuilt-idocumetatio.
TestigtheAPICheckqueries/bookig.graphqladqueries/queries.graphqltoseeseveralexampleoperatiosyoucasedtotheAPI.Togetauderstadigofthebookigflows,checkthemutatiosiqueries/bookig.graphql.
DeploymetAquickadeasywaytodeploytheGraphQLserverfromthisrepositoryiswithZeitNow.AfteryoudowloadedtheNowDesktopapp,youcadeploytheserverwiththefollowigcommad:
ow--dotev.ev.prodNoticethatyoueedtocreatethe.ev.prodfileyourselfbeforeivokigthecommad.Itshouldlistthesameevirometvariablesas.evbutwithdifferetvalues.Iparticular,youeedtomakesurethatyourPrismaserviceisdeployedtoaclusterthataccessibleovertheweb.
Hereisaexampleforwhat.ev.prodmightlooklike:
PRISMA_STAGE="prod"PRISMA_CLUSTER="public-tudrapiper-423/prisma-us1"PRISMA_ENDPOINT="https://us1.prisma.sh/public-tudrapiper-423/prisma-airbb-example/dev"PRISMA_SECRET="mysecret123"APP_SECRET="appsecret321"TolearmoreaboutdeployigGraphQLserverswithZeitNow,checkoutthistutorial.
TroubleshootigI'mgettigtheerrormessage[Networkerror]:FetchError:requesttohttps://localhost:4466/auth-example/devfailed,reaso:coectECONNREFUSEDwhetryigtosedaqueryormutatioThisisbecausetheedpoitforthePrismaserviceishardcodediidex.js.Theserviceisassumedtoberuigothedefaultportforalocalcluster:https://localhost:4466.Apparetly,yourlocalclusterisusigadifferetport.
Youowhavetwooptios:
Figureouttheportofyourlocalclusteradadjustitiidex.js.Youcalookitupi~/.prisma/cofig.yml.Deploytheservicetoapubliccluster.ExpadtheIdo'thaveDockeristalledomymachie-sectioistep2foristructios.Eitherway,youeedtoadjusttheedpoitthat'spassedtothePrismacostructoriidex.jssoitreflectstheactualclusterdomaiadserviceedpoit.
LiceseMIT







评论