{"id":15890009,"url":"https://github.com/nampdn/ekklisia-prisma","last_synced_at":"2025-07-06T20:38:49.986Z","repository":{"id":96647843,"uuid":"229160502","full_name":"nampdn/ekklisia-prisma","owner":"nampdn","description":"Ekklisia Prisma Server","archived":false,"fork":false,"pushed_at":"2020-03-01T04:16:19.000Z","size":469,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T17:14:47.638Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ekklisia-prisma.now.sh","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/nampdn.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-20T00:26:46.000Z","updated_at":"2020-03-01T04:16:22.000Z","dependencies_parsed_at":"2023-03-26T02:18:40.655Z","dependency_job_id":null,"html_url":"https://github.com/nampdn/ekklisia-prisma","commit_stats":{"total_commits":73,"total_committers":1,"mean_commits":73.0,"dds":0.0,"last_synced_commit":"6fd6326b8da9f79bd3ba9495b242dcf47a234ec5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nampdn/ekklisia-prisma","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nampdn%2Fekklisia-prisma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nampdn%2Fekklisia-prisma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nampdn%2Fekklisia-prisma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nampdn%2Fekklisia-prisma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nampdn","download_url":"https://codeload.github.com/nampdn/ekklisia-prisma/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nampdn%2Fekklisia-prisma/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263969563,"owners_count":23537448,"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-10-06T07:02:28.277Z","updated_at":"2025-07-06T20:38:49.963Z","avatar_url":"https://github.com/nampdn.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL Server with Authentication \u0026 Permissions\n\nThis example shows how to implement a **GraphQL server with an email-password-based authentication workflow and authentication rules**, based on Prisma, [graphql-yoga](https://github.com/prisma/graphql-yoga), [graphql-shield](https://github.com/maticzav/graphql-shield) \u0026 [GraphQL Nexus](https://nexus.js.org/).\n\n## How to use\n\n### 1. Download example \u0026 install dependencies\n\nClone the `prisma2` branch of this repository:\n\n```\ngit clone --single-branch --branch prisma2 git@github.com:prisma/prisma-examples.git\n```\n\nInstall Node dependencies:\n\n```\ncd prisma-examples/typescript/graphql-auth\nnpm install\n```\n\n### 2. Run Prisma's development mode\n\n\u003cDetails\u003e\u003cSummary\u003eLearn more about the development mode\u003c/Summary\u003e\n\nPrisma's [development mode](https://github.com/prisma/prisma2/blob/master/docs/development-mode.md) watches your [Prisma schema](https://github.com/prisma/prisma2/blob/master/docs/prisma-schema-file.md) on the file system. Whenever there's a change in the schema, the Prisma Framework CLI performs two major tasks in the background:\n\n- map the Prisma schema to your database schema (i.e., perform a schema migration in the database) \n- regenerate the Photon.js database client based on the new Prisma schema\n\nIt also runs a web server to host [Prisma Studio](https://github.com/prisma/studio), typically at [`http://localhost:5555`](http://localhost:5555).\n\nIn this case, the command also creates a new [SQLite database](https://www.sqlite.org/index.html) file at `./prisma/dev.db` since that didn't exist in the project yet.\n\n\u003c/Details\u003e\n\nStart the development mode with the following command:\n\n```\nnpx prisma2 dev\n```\n\n\u003e **Note**: You're using [npx](https://github.com/npm/npx) to run the Prisma Framework CLI that's listed as a development dependency in [`package.json`](./package.json). Alternatively, you can install the CLI globally using `npm install -g prisma2`. When using Yarn, you can run: `yarn prisma2 dev`.\n\nYou can now open [Prisma Studio](https://github.com/prisma/studio). Open your browser and navigate to the URL displayed by the CLI output (typically at [`http://localhost:5555`](http://localhost:5555)).\n\n\u003cDetails\u003e\n\u003cSummary\u003e\u003cb\u003eAlternative: \u003c/b\u003eConnect to your own database\u003c/Summary\u003e\n\nPrisma supports MySQL and PostgreSQL at the moment. If you would like to connect to your own database, you can do so by specifying a different data source in the [Prisma schema file](prisma/schema.prisma).\n\nFor a MySQL provider:\n```\ndatasource mysql {\n    provider = \"mysql\"\n    url      = \"mysql://johndoe:secret42@localhost:3306/mydatabase\"\n}\n```\n\n*OR*\n\nFor a PostgreSQL provider:\n```\ndatasource postgresql {\n  provider = \"postgresql\"\n  url      = \"postgresql://johndoe:secret42@localhost:5432/mydatabase?schema=public\"\n}\n```\n\n\u003e Note: In the above example connection strings, `johndoe` would be the username to your database, `secret42` the password, `mydatabase` the name of your database, and `public` the [PostgreSQL schema](https://www.postgresql.org/docs/9.1/ddl-schemas.html). \n\nThen to migrate your database schema, run:\n\n```sh\nnpx prisma2 lift save --name 'init'\nnpx prisma2 lift up\n```\n\n\u003c/Details\u003e\n\n### 3. Seed the database with test data\n\nThe `seed` script from `package.json` contains some code to seed the database with test data. Execute it with the following command:\n\n```\nnpm run seed\n```\n\n\u003e **Note**: You need to execute the command in a new terminal window/tab, since the development mode is taking up your currrent terminal session.\n\n\n### 4. 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### 5. Using the GraphQL API\n\nThe schema that specifies the API operations of your GraphQL server is defined in [`./src/schema.graphql`](./src/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#### Register a new user\n\nYou can send the following mutation in the Playground to sign up a new user and retrieve an authentication token for them:\n\n```graphql\nmutation {\n  signup(name: \"Sarah\", email: \"sarah@prisma.io\", password: \"graphql\") {\n    token\n  }\n}\n```\n\n#### Log in an existing user\n\nThis mutation will log in an existing user by requesting a new authentication token for them:\n\n```graphql\nmutation {\n  login(email: \"sarah@prisma.io\", password: \"graphql\") {\n    token\n  }\n}\n```\n\n#### Check whether a user is currently logged in with the `me` query\n\nFor this query, you need to make sure a valid authentication token is sent along with the `Bearer`-prefix in the `Authorization` header of the request:\n\n```json\n{\n  \"Authorization\": \"Bearer __YOUR_TOKEN__\"\n}\n```\n\nWith a real token, this looks similar to this:\n\n```json\n{\n  \"Authorization\": \"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjanAydHJyczFmczE1MGEwM3kxaWl6c285IiwiaWF0IjoxNTQzNTA5NjY1fQ.Vx6ad6DuXA0FSQVyaIngOHYVzjKwbwq45flQslnqX04\"\n}\n```\n\nInside the Playground, you can set HTTP headers in the bottom-left corner:\n\n![](https://imgur.com/ToRcCTj.png)\n\nOnce you've set the header, you can send the following query to check whether the token is valid:\n\n```graphql\n{\n  me {\n    id\n    name\n    email\n  }\n}\n```\n\n#### Create a new draft\n\nYou need to be logged in for this query to work, i.e. an authentication token that was retrieved through a `signup` or `login` mutation needs to be added to the `Authorization` header in the GraphQL Playground.\n\n```graphql\nmutation {\n  createDraft(\n    title: \"Join the Prisma Slack\"\n    content: \"https://slack.prisma.io\"\n  ) {\n    id\n    published\n  }\n}\n```\n\n#### Publish an existing draft\n\nYou need to be logged in for this query to work, i.e. an authentication token that was retrieved through a `signup` or `login` mutation needs to be added to the `Authorization` header in the GraphQL Playground. The authentication token must belong to the user who created the post.\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\nYou need to be logged in for this query to work, i.e. an authentication token that was retrieved through a `signup` or `login` mutation needs to be added to the `Authorization` header in the GraphQL Playground. \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\nYou need to be logged in for this query to work, i.e. an authentication token that was retrieved through a `signup` or `login` mutation needs to be added to the `Authorization` header in the GraphQL Playground. \n\n```graphql\n{\n  post(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\nYou need to be logged in for this query to work, i.e. an authentication token that was retrieved through a `signup` or `login` mutation needs to be added to the `Authorization` header in the GraphQL Playground. The authentication token must belong to the user who created the post.\n\n```graphql\nmutation {\n  deletePost(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### 6. Changing the GraphQL schema\n\nTo make changes to the GraphQL schema, you need to manipulate the [`Query`](./src/resolvers/Query.ts) and [`Mutation`](./src/resolvers/Mutation.ts) types. \n\nNote that the [`dev`](./package.json#L6) script also starts a development server that automatically updates your schema every time you save a file. This way, the auto-generated [GraphQL schema](./src/generated/schema.graphql) updates whenever you make changes in to the `Query` or `Mutation` types inside your TypeScript code.\n\n\n## Next steps\n\n### Use Lift to persist the schema migration\n\nThe migrations that were generated throughout the development mode are _development migrations_ that are thrown away once the desired schema has been found. In that case, you need to persist the schema using the `lift` subcommands.\n\nTo persist your schema migration with Lift, run:\n\n```\nnpx prisma2 lift save --name 'init'\nnpx prisma2 lift up\n```\n\nThe first command, `lift save`, stores a number of migration files on the file sytem with details about the migration (such as the required migration steps and SQL operations), this doesn't yet affect the database. It also deletes the old development migrations. The second command, `lift up`, actually performs the schema migration against the database.\n\n### Generate Photon.js with the CLI\n\nSometimes, e.g. in CI/CD environments, it can be helpful to generate Photon.js with a CLI command. This can be done with the `prisma2 generate command`. If you want to run it in this project, you need to prepend `npx` again:\n\n```\nnpx prisma2 generate\n```\n\n### More things to explore\n\n- Read the holistic, step-by-step [Prisma Framework tutorial](https://github.com/prisma/prisma2/blob/master/docs/tutorial.md)\n- Check out the [Prisma Framework docs](https://github.com/prisma/prisma2) (e.g. for [data modeling](https://github.com/prisma/prisma2/blob/master/docs/data-modeling.md), [relations](https://github.com/prisma/prisma2/blob/master/docs/relations.md) or the [Photon.js API](https://github.com/prisma/prisma2/blob/master/docs/photon/api.md))\n- Share your feedback in the [`prisma2-preview`](https://prisma.slack.com/messages/CKQTGR6T0/) channel on the Prisma Slack\n- Create issues and ask questions on [GitHub](https://github.com/prisma/prisma2/)\n- Track the Prisma Framework's progress on [`isprisma2ready.com`](https://isprisma2ready.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnampdn%2Fekklisia-prisma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnampdn%2Fekklisia-prisma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnampdn%2Fekklisia-prisma/lists"}