graphql-prisma-typescript开源项目

我要开发同款
匿名用户2021年11月23日
172阅读

技术信息

开源地址
https://gitee.com/MTrun/react-big-screen
授权协议
MIT License

作品详情

AirbbCloe-GraphQLServerExamplewithPrisma

Thisprojectdemostrateshowtobuildaproductio-readyapplicatiowithPrismaadgraphql-yoga.TheAPIprovidedbytheGraphQLserveristhefoudatioforaapplicatiosimilartoAirBB.

Getstarted

Note:prismaislistedasadevelopmetdepedecyadscriptithisproject'spackage.jso.ThismeasyoucaivokethePrismaCLIwithouthavigitgloballyistalledoyourmachie(byprefixigitwithyar),e.g.yarprismadeployoryarprismaplaygroud.IfyouhavethePrismaCLIistalledglobally(whichyoucadowithpmistall-gprisma),youcaomittheyarprefix.

1.Dowloadtheexample&istalldepedecies

Cloetherepositorywiththefollowigcommad:

gitcloegit@github.com:graphcool/graphql-server-example.git

Next,avigateitothedowloadedfolderadistalltheNPMdepedecies:

cdgraphql-server-exampleyaristall2.DeploythePrismadatabaseservice

YoucaowdeploythePrismaservice(otethatthisrequiresyoutohaveDockeristalledoyourmachie-ifthat'sotthecase,followthecollapsedistructiosbelowthecodeblock):

cdprismadocker-composeup-dcd..yarprismadeployIdo'thaveDockeristalledomymachie

Todeployyourservicetoapubliccluster(ratherthalocallywithDocker),youeedtoperformthefollowigsteps:

Removetheclusterpropertyfromprisma.yml.Ruyarprismadeploy.WhepromptedbytheCLI,selectapubliccluster(e.g.prisma-eu1orprisma-us1).Replacetheedpoitiidex.tswiththeHTTPedpoitthatwaspritedafterthepreviouscommad.

NoticethatwhedeployigthePrismaservicefortheveryfirsttime,theCLIwillexecutethemutatiosfromprisma/seed.graphqltoseedsomeiitialdataithedatabase.TheCLIisawareofthisfilebecauseit'slistediprisma/prisma.ymludertheseedproperty.

3.StarttheGraphQLserver

ThePrismadatabaseservicethat'sbackigyourGraphQLserverisowavailable.Thismeasyoucaowstarttheserver:

yardev

Thedevscriptstartstheserver(ohttps://localhost:4000)adopesaGraphQLPlaygroudwhereyougetaccestotheAPIofyourGraphQLserver(defieditheapplicatioschema)aswellastheuderlyigPrismaAPI(defieditheauto-geeratedPrismadatabaseschema)directly.

IsidethePlaygroud,youcastartexplorigtheavailableoperatiosbybrowsigthebuilt-idocumetatio.

TestigtheAPI

Checkqueries/bookig.graphqladqueries/queries.graphqltoseeseveralexampleoperatiosyoucasedtotheAPI.Togetauderstadigofthebookigflows,checkthemutatiosiqueries/bookig.graphql.

Deploymet

AquickadeasywaytodeploytheGraphQLserverfromthisrepositoryiswithZeitNow.AfteryoudowloadedtheNowDesktopapp,youcadeploytheserverwiththefollowigcommad:

ow--dotev.ev.prod

Noticethatyoueedtocreatethe.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:coectECONNREFUSEDwhetryigtosedaqueryormutatio

ThisisbecausetheedpoitforthePrismaserviceishardcodediidex.js.Theserviceisassumedtoberuigothedefaultportforalocalcluster:https://localhost:4466.Apparetly,yourlocalclusterisusigadifferetport.

Youowhavetwooptios:

Figureouttheportofyourlocalclusteradadjustitiidex.js.Youcalookitupi~/.prisma/cofig.yml.Deploytheservicetoapubliccluster.ExpadtheIdo'thaveDockeristalledomymachie-sectioistep2foristructios.

Eitherway,youeedtoadjusttheedpoitthat'spassedtothePrismacostructoriidex.jssoitreflectstheactualclusterdomaiadserviceedpoit.

Licese

MIT

功能介绍

Airbnb Clone - GraphQL Server Example with Prisma This project demonstrates how to build a produc...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论