当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

graphql-prisma-typescript

授权协议 MIT License
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 衡翰翮
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Airbnb Clone - GraphQL Server Example with Prisma

This project demonstrates how to build a production-ready application with Prisma and graphql-yoga. The API provided by the GraphQL server is the foundation for an application similar to AirBnB.

Get started

Note: prisma is listed as a development dependency and script in this project's package.json. This means you can invoke the Prisma CLI without having it globally installed on your machine (by prefixing it with yarn), e.g. yarn prisma deploy or yarn prisma playground. If you have the Prisma CLI installed globally (which you can do with npm install -g prisma), you can omit the yarn prefix.

1. Download the example & install dependencies

Clone the repository with the following command:

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

Next, navigate into the downloaded folder and install the NPM dependencies:

cd graphql-server-example
yarn install

2. Deploy the Prisma database service

You can now deploy the Prisma service (note that this requires you to have Docker installed on your machine - if that's not the case, follow the collapsed instructions below the code block):

cd prisma
docker-compose up -d
cd ..
yarn prisma deploy
I don't have Docker installed on my machine

To deploy your service to a public cluster (rather than locally with Docker), you need to perform the following steps:

  1. Remove the cluster property from prisma.yml.
  2. Run yarn prisma deploy.
  3. When prompted by the CLI, select a public cluster (e.g. prisma-eu1 or prisma-us1).
  4. Replace the endpoint in index.ts with the HTTP endpoint that was printed after the previous command.

Notice that when deploying the Prisma service for the very first time, the CLI will execute the mutations from prisma/seed.graphql to seed some initial data in the database. The CLI is aware of this file because it's listed in prisma/prisma.yml under the seed property.

3. Start the GraphQL server

The Prisma database service that's backing your GraphQL server is now available. This means you can now start the server:

yarn dev

The dev script starts the server (on http://localhost:4000) and opens a GraphQL Playground where you get acces to the API of your GraphQL server (defined in the application schema) as well as the underlying Prisma API (defined in the auto-generated Prisma database schema) directly.

Inside the Playground, you can start exploring the available operations by browsing the built-in documentation.

Testing the API

Check queries/booking.graphql and queries/queries.graphql to see several example operations you can send to the API. To get an understanding of the booking flows, check the mutations in queries/booking.graphql.

Deployment

A quick and easy way to deploy the GraphQL server from this repository is with Zeit Now. After you downloaded the Now Desktop app, you can deploy the server with the following command:

now --dotenv .env.prod

Notice that you need to create the .env.prod file yourself before invoking the command. It should list the same environment variables as .env but with different values. In particular, you need to make sure that your Prisma service is deployed to a cluster that accessible over the web.

Here is an example for what .env.prod might look like:

PRISMA_STAGE="prod"
PRISMA_CLUSTER="public-tundrapiper-423/prisma-us1"
PRISMA_ENDPOINT="http://us1.prisma.sh/public-tundrapiper-423/prisma-airbnb-example/dev"
PRISMA_SECRET="mysecret123"
APP_SECRET="appsecret321"

To learn more about deploying GraphQL servers with Zeit Now, check out this tutorial.

Troubleshooting

I'm getting the error message [Network error]: FetchError: request to http://localhost:4466/auth-example/dev failed, reason: connect ECONNREFUSED when trying to send a query or mutation

This is because the endpoint for the Prisma service is hardcoded in index.js. The service is assumed to be running on the default port for a local cluster: http://localhost:4466. Apparently, your local cluster is using a different port.

You now have two options:

  1. Figure out the port of your local cluster and adjust it in index.js. You can look it up in ~/.prisma/config.yml.
  2. Deploy the service to a public cluster. Expand the I don't have Docker installed on my machine-section in step 2 for instructions.

Either way, you need to adjust the endpoint that's passed to the Prisma constructor in index.js so it reflects the actual cluster domain and service endpoint.

License

MIT

 相关资料
  • 我正在努力让普里斯玛和继电器工作。这是我的回购协议: https://github.com/jamesmbowler/prisma-relay-todo 这是一个简单的待办事项列表。我可以添加待办事项,但用户界面不会更新。当我刷新时,待办事项就在那里。 我能找到的所有更新存储的示例都对正在更新/创建的对象使用“父”。 看https://facebook.github.io/relay/docs/e

  • 我试图创建一个基于微服务的应用程序,它使用两个在Docker中运行的远程Prisma/GraphQL模式和一个使用模式拼接进行内省的网关。 Prisma/GraphQL模式: 现在在Gateway服务器中,我能够成功地使用图形工具内省和合并模式,并且我添加了扩展类型来允许两种类型之间的关系 我按照阿波罗GraphQL留档模式拼接与远程模式,这是我现在合并模式的解析器 我遇到的问题是,每次我查询用户

  • Prisma 是一个快速构建 GraphQL 服务、REST API、数据库服务的后端框架 已支持 MySQL, PostgreSQL, MongoDB 等数据库,其他流行数据库正在开发中 客户端已支持 JavaScript, TypeScript, Flow, Go 等语言 类型安全的数据库访问,包括过滤器、聚合、分页和事务 数据库的实时事件系统以获得有关数据库事件的通知 具有简单SDL语法的声

  • Serverless Prisma [Archived] — New projects should consider using Prisma2 Minimal Serverless + Prisma Project Template Getting Started Be sure to have Docker and Make installed on your machine. Docker

  • Prisma Examples Ready-to-run Prisma example projects �� Website   •   Docs   •   Blog   •   Slack   •   Twitter   •   Demo videos View full CI status This repository contains a number of ready-to-run

  • 我刚开始使用Prisma。以前,我主要使用firebase和mongodb来定义模式。 我正在尝试定义以下模式: 基本上,我想实现的是让用户能够投票给其他用户(给他们一个分数)。在MongoDB中,我将通过创建一个单独的集合来实现,如以下内容: 在这里,我只是将这些字段(from和for)指定为字符串,然后通过应用程序逻辑将它们与用户集合链接起来。 当然,在GraphQL Prisma中会有所不同