{"id":22430134,"url":"https://github.com/2wce/fpl-prisma-vercel","last_synced_at":"2025-03-27T07:14:23.444Z","repository":{"id":40708093,"uuid":"316702158","full_name":"2wce/fpl-prisma-vercel","owner":"2wce","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-06T16:45:00.000Z","size":1603,"stargazers_count":0,"open_issues_count":15,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T12:12:11.974Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2wce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-28T09:49:00.000Z","updated_at":"2020-11-28T09:49:07.000Z","dependencies_parsed_at":"2023-02-06T06:47:12.568Z","dependency_job_id":null,"html_url":"https://github.com/2wce/fpl-prisma-vercel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"2wce/prisma-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2wce%2Ffpl-prisma-vercel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2wce%2Ffpl-prisma-vercel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2wce%2Ffpl-prisma-vercel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2wce%2Ffpl-prisma-vercel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2wce","download_url":"https://codeload.github.com/2wce/fpl-prisma-vercel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245798356,"owners_count":20673902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T21:07:30.181Z","updated_at":"2025-03-27T07:14:23.430Z","avatar_url":"https://github.com/2wce.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prisma-template\n\nThis example shows how to implement an **GraphQL server (SDL-first) with TypeScript** based on [Prisma Client](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/api), [graphql-yoga](https://github.com/prisma/graphql-yoga) and [graphql-tools](https://www.apollographql.com/docs/graphql-tools/). It is based on a SQLite database, you can find the database file with some dummy data at [`./prisma/dev.db`](./prisma/dev.db).\n\n## How to use\n\n### 1. Download example \u0026 install dependencies\n\nClone this repository:\n\n```\ngit clone git@github.com:2wce/prisma-template.git\n```\n\nInstall npm dependencies:\n\n```\ncd prisma-template\nnpm install\n```\n\nNote that this also generates Prisma Client JS into `node_modules/@prisma/client` via a `postinstall` hook of the `@prisma/client` package from your `package.json`.\n\n### 2. Start the GraphQL server\n\nLaunch your GraphQL server with this command:\n\n```\nnpm run dev\n```\n\nNavigate to [http://localhost:4000](http://localhost:4000) in your browser to explore the API of your GraphQL server in a [GraphQL Playground](https://github.com/prisma/graphql-playground).\n\n## Using the GraphQL API\n\nThe schema that specifies the API operations of your GraphQL server is defined in [`./src/schema/schema.graphql`](./src/schema/schema.graphql). Below are a number of operations that you can send to the API using the GraphQL Playground.\n\nFeel free to adjust any operation by adding or removing fields. The GraphQL Playground helps you with its auto-completion and query validation features.\n\n### Retrieve all published posts and their authors\n\n```graphql\nquery {\n  feed {\n    id\n    title\n    content\n    published\n    author {\n      id\n      name\n      email\n    }\n  }\n}\n```\n\n\u003cDetails\u003e\u003cSummary\u003e\u003cstrong\u003eSee more API operations\u003c/strong\u003e\u003c/Summary\u003e\n\n### Create a new user\n\n```graphql\nmutation {\n  signupUser(data: { name: \"Sarah\", email: \"sarah@prisma.io\" }) {\n    id\n  }\n}\n```\n\n### Create a new draft\n\n```graphql\nmutation {\n  createDraft(\n    title: \"Join the Prisma Slack\"\n    content: \"https://slack.prisma.io\"\n    authorEmail: \"alice@prisma.io\"\n  ) {\n    id\n    published\n  }\n}\n```\n\n### Publish an existing draft\n\n```graphql\nmutation {\n  publish(id: __POST_ID__) {\n    id\n    published\n  }\n}\n```\n\n\u003e **Note**: You need to replace the `__POST_ID__`-placeholder with an actual `id` from a `Post` item. You can find one e.g. using the `filterPosts`-query.\n\n### Search for posts with a specific title or content\n\n```graphql\n{\n  filterPosts(searchString: \"graphql\") {\n    id\n    title\n    content\n    published\n    author {\n      id\n      name\n      email\n    }\n  }\n}\n```\n\n### Retrieve a single post\n\n```graphql\n{\n  post(where: { id: __POST_ID__ }) {\n    id\n    title\n    content\n    published\n    author {\n      id\n      name\n      email\n    }\n  }\n}\n```\n\n\u003e **Note**: You need to replace the `__POST_ID__`-placeholder with an actual `id` from a `Post` item. You can find one e.g. using the `filterPosts`-query.\n\n### Delete a post\n\n```graphql\nmutation {\n  deleteOnePost(where: { id: __POST_ID__ }) {\n    id\n  }\n}\n```\n\n\u003e **Note**: You need to replace the `__POST_ID__`-placeholder with an actual `id` from a `Post` item. You can find one e.g. using the `filterPosts`-query.\n\n\u003c/Details\u003e\n\n## Evolving the app\n\nEvolving the application typically requires four subsequent steps:\n\n1. Migrating the database schema using SQL\n1. Update your Prisma schema by introspecting the database with `prisma introspect`\n1. Generating Prisma Client to match the new database schema with `prisma generate`\n1. Use the updated Prisma Client in your application code\n\nFor the following example scenario, assume you want to add a \"profile\" feature to the app where users can create a profile and write a short bio about themselves.\n\n### 1. Change your database schema using SQL\n\nThe first step would be to add a new table, e.g. called `Profile`, to the database. In SQLite, you can do so by running the following SQL statement:\n\n```sql\nCREATE TABLE \"Profile\" (\n  \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n  \"bio\" TEXT,\n  \"user\" TEXT NOT NULL UNIQUE REFERENCES \"User\"(id) ON DELETE SET NULL\n);\n```\n\nTo run the SQL statement against the database, you can use the `sqlite3` CLI in your terminal, e.g.:\n\n```bash\nsqlite3 dev.db \\\n'CREATE TABLE \"Profile\" (\n  \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n  \"bio\" TEXT,\n  \"user\" TEXT NOT NULL UNIQUE REFERENCES \"User\"(id) ON DELETE SET NULL\n);'\n```\n\nNote that we're adding a unique constraint to the foreign key on `user`, this means we're expressing a 1:1 relationship between `User` and `Profile`, i.e.: \"one user has one profile\".\n\nWhile your database now is already aware of the new table, you're not yet able to perform any operations against it using Prisma Client. The next two steps will update the Prisma Client API to include operations against the new `Profile` table.\n\n### 2. Introspect your database\n\nThe Prisma schema is the foundation for the generated Prisma Client API. Therefore, you first need to make sure the new `Profile` table is represented in it as well. The easiest way to do so is by introspecting your database:\n\n```\nnpx prisma introspect\n```\n\n\u003e **Note**: You're using [npx](https://github.com/npm/npx) to run Prisma 2 CLI that's listed as a development dependency in [`package.json`](./package.json). Alternatively, you can install the CLI globally using `npm install -g @prisma/cli`. When using Yarn, you can run: `yarn prisma dev`.\n\nThe `introspect` command updates your `schema.prisma` file. It now includes the `Profile` model and its 1:1 relation to `User`:\n\n```prisma\nmodel Post {\n  author    User?\n  content   String?\n  id        Int     @id\n  published Boolean @default(false)\n  title     String\n}\n\nmodel User {\n  email   String   @unique\n  id      Int      @id\n  name    String?\n  post    Post[]\n  profile Profile?\n}\n\nmodel Profile {\n  bio  String?\n  id   Int     @id\n  user User\n}\n```\n\n### 3. Generate Prisma Client\n\nWith the updated Prisma schema, you can now also update the Prisma Client API with the following command:\n\n```\nnpx prisma generate\n```\n\nThis command updated the Prisma Client API in `node_modules/@prisma/client`.\n\n### 4. Use the updated Prisma Client in your application code\n\nYou can now use your `PrismaClient` instance to perform operations against the new `Profile` table. Here are some examples:\n\n#### Create a new profile for an existing user\n\n```ts\nconst profile = await prisma.profile.create({\n  data: {\n    bio: 'Hello World',\n    user: {\n      connect: { email: 'alice@prisma.io' },\n    },\n  },\n})\n```\n\n#### Create a new user with a new profile\n\n```ts\nconst user = await prisma.user.create({\n  data: {\n    email: 'john@prisma.io',\n    name: 'John',\n    profile: {\n      create: {\n        bio: 'Hello World',\n      },\n    },\n  },\n})\n```\n\n#### Update the profile of an existing user\n\n```ts\nconst userWithUpdatedProfile = await prisma.user.update({\n  where: { email: 'alice@prisma.io' },\n  data: {\n    profile: {\n      update: {\n        bio: 'Hello Friends',\n      },\n    },\n  },\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2wce%2Ffpl-prisma-vercel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2wce%2Ffpl-prisma-vercel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2wce%2Ffpl-prisma-vercel/lists"}