{"id":14968845,"url":"https://github.com/supabase-community/supabase-graphql-example","last_synced_at":"2025-04-12T21:24:28.948Z","repository":{"id":41473327,"uuid":"470665296","full_name":"supabase-community/supabase-graphql-example","owner":"supabase-community","description":"A HackerNews-like clone built with Supabase and pg_graphql","archived":false,"fork":false,"pushed_at":"2025-04-12T07:43:11.000Z","size":1550,"stargazers_count":227,"open_issues_count":30,"forks_count":27,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-12T08:35:20.302Z","etag":null,"topics":["graphql-code-generator","graphql-schema","pg-graphql","supabase","supabase-auth","supabase-db"],"latest_commit_sha":null,"homepage":"https://supabase-graphql-example.vercel.app/","language":"PLpgSQL","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/supabase-community.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,"zenodo":null}},"created_at":"2022-03-16T16:29:52.000Z","updated_at":"2025-04-04T04:42:30.000Z","dependencies_parsed_at":"2024-04-15T05:57:35.510Z","dependency_job_id":"7680e2c1-7689-482a-a4a4-656d7bdb813d","html_url":"https://github.com/supabase-community/supabase-graphql-example","commit_stats":{"total_commits":117,"total_committers":9,"mean_commits":13.0,"dds":0.4700854700854701,"last_synced_commit":"504560d3124a76e36100a310e0d7f714df52d1bc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fsupabase-graphql-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fsupabase-graphql-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fsupabase-graphql-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fsupabase-graphql-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supabase-community","download_url":"https://codeload.github.com/supabase-community/supabase-graphql-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248633032,"owners_count":21136792,"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":["graphql-code-generator","graphql-schema","pg-graphql","supabase","supabase-auth","supabase-db"],"created_at":"2024-09-24T13:40:41.463Z","updated_at":"2025-04-12T21:24:28.916Z","avatar_url":"https://github.com/supabase-community.png","language":"PLpgSQL","funding_links":[],"categories":["PLpgSQL"],"sub_categories":[],"readme":"# Supabase GraphQL Example\n\nA basic HackerNews-like clone where posts can be submitted with url links and then up and down voted.\n\n\u003cimg width=\"1000\" alt=\"graphql-hn\" src=\"https://user-images.githubusercontent.com/10214025/160611420-29705df8-3e0a-471e-baef-04a3e2ac5618.png\"\u003e\n\n- Example: [supabase-graphql-example.vercel.app](https://supabase-graphql-example.vercel.app/)\n- Features: [supabase-graphql-example.vercel.app/about](https://supabase-graphql-example.vercel.app/about)\n\n## Showcase\n\n### Backend\n\n- CRUD (Query + Mutation Operations)\n- Cursor Based Pagination\n- Authorization / Postgres Row Level Security\n- [Supabase](https://supabase.com) - Create a backend in less than 2 minutes. Start your project with a Postgres Database, Authentication, instant APIs, Realtime subscriptions and Storage.\n- [pg_graphql](https://supabase.com/blog/2021/12/03/pg-graphql) - A native [PostgreSQL extension](https://supabase.github.io/pg_graphql/) adding [GraphQL support](https://graphql.org). The extension keeps schema generation, query parsing, and resolvers all neatly contained on your database server requiring no external services.\n- [Postgres Triggers](https://supabase.com/blog/2021/07/30/supabase-functions-updates) and [Postgres Functions](https://supabase.com/docs/guides/database/functions) - When votes are in, use triggers to invoke a Postgres function that calculates a post score to rank the feed\n- [Postgres Enumerated Types](https://www.postgresql.org/docs/14/datatype-enum.html) - Enums help defined the direction of a vote: UP or DOWN.\n\n### Frontend\n\n- [Next.js](https://nextjs.org) - React Framework\n- [TypeScript](https://www.typescriptlang.org) - TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.\n- [graphql-code-generator](https://www.graphql-code-generator.com) - Generate code from your GraphQL schema and operations with a simple CLI\n- [gql-tag-operations-preset](https://www.graphql-code-generator.com/plugins/gql-tag-operations-preset) - This code gen preset generates typings for your inline gql function usages, without having to manually specify import statements for the documents\n- [urql](https://formidable.com/open-source/urql/) - A highly customizable and versatile GraphQL client\n- [Gravatar](https://en.gravatar.com) - Default avatar profile images from Gravatar\n\n### Functionality\n\n- Registration\n- Get a ranked feed of posts\n- Create Post\n- Delete Post\n- Create Comment\n- Delete Comment\n- Upvote/Downvote Post\n- View Profile (Account)\n- View Profile (Public)\n- Pagination (Posts, Comments)\n\n## QuickStart\n\n### Setup env vars\n\n- `cp app/.env.example app/.env`\n- Fill in your url and anon key from the Supabase Dashboard: https://app.supabase.io/project/_/settings/api\n\n### Install dependencies, GraphQL codegen, run app\n\n```bash\nyarn\nyarn codegen\nyarn workspace app dev\n```\n\n### Deploy to Vercel\n\nProvide the following settings to deploy a production build to Vercel:\n\n- BUILD COMMAND: `yarn codegen \u0026\u0026 yarn workspace app build`\n- OUTPUT DIRECTORY: `./app/.next`\n- INSTALL COMMAND: `yarn`\n- DEVELOPMENT COMMAND: `yarn codegen \u0026\u0026 yarn workspace app dev --port $PORT`\n\n## Development\n\n1. Fetch latest GraphQL Schema\n\n```bash\nyarn codegen:fetch\n```\n\n2. Generate Types and Watch for Changes\n\n```bash\nyarn codegen:watch\n```\n\n3. Run server\n\n```bash\nyarn workspace app dev\n```\n\n### Synchronize the GraphQL schema\n\nNote: You need to call `select graphql.rebuild_schema()` manually to synchronize the GraphQL schema with the SQL schema after altering the SQL schema.\n\n#### Manage Schema with dbmate\n\n1. `brew install dbmate`\n2. Setup `.env` with `DATABASE_URL`\n3. Dump Schema\n\n```\ncd data\ndbmate dump\n```\n\n\u003e Note: If `pgdump` fails due to row locks, a workaround is to grant the `postgres` role superuser permissions with `ALTER USER postgres WITH SUPERUSER`. After dumping the schema, you should reset the permissions using `ALTER USER postgres WITH NOSUPERUSER`. You can run these statements in the Superbase Dashboard SQL Editors.\n\n## Schema (Public)\n\n- Profile belongs to auth.users\n- Post\n- Comment belongs to Post and Profile\n- Vote belongs to Post (can have a direction of UP/DOWN)\n\n- direction enum is \"UP\" or \"DOWN\"\n\n### Constraints\n\n- Post `url` is unique\n- Vote is unique per Profile, Post (ie, you cannot vote more than once -- up or down)\n\nSee: [`./data/db/schema.sql`](./data/db/schema.sql)\n\n\u003e Note: The schema includes the entire Supabase schema with auth, storage, functions, etc.\n\n## Seed Data\n\nA data file for all Supabase Blog posts from the RSS feed can be found in `./data/seed/blog_posts.csv` and can be loaded. Another file for `comments` is available as well.\n\nNote: Assumes a known `profileId` currently.\n\n## GraphQL Schema\n\nSee: [`./graphql/schema/schema.graphql`](./graphql/schema/schema.graphql)\n\n## Example Query\n\nSee: [`./graphql/queries/`](./graphql/queries/)\n\nUse: `https://mvrfvzcivgabojxddwtk.supabase.co/graphql/v1`\n\n\u003e Note: Needs headers\n\n```\n\nContent-Type: application/json\napiKey: \u003csupabase_anon_key\u003e\n\n```\n\n## GraphiQL\n\nGraphiQL is an in-browser IDE for writing, validating, and testing GraphQL queries.\n\nVisit `http://localhost:3000/api/graphiql` for the [Yoga GraphiQL Playground](https://www.graphql-yoga.com/docs/features/graphiql) where you can experiment with queries and mutations.\n\n\u003e Note: Needs headers\n\n```\n\nContent-Type: application/json\napiKey: \u003csupabase_anon_key\u003e\n\n```\n\n\u003e Note: In order for the RLS policies authenticate you, you have to pass an authorization header ([see example](https://github.com/supabase-community/supabase-graphql-example/blob/main/app/lib/urql.tsx#L15)):\n\n```\nauthorization: Bearer \u003caccess_token\u003e\n\n```\n\n### Ranked Feed\n\n```gql\nquery {\n  rankedFeed: postCollection(orderBy: [{ voteRank: AscNullsFirst }]) {\n    edges {\n      post: node {\n        id\n        title\n        url\n        upVoteTotal\n        downVoteTotal\n        voteTotal\n        voteDelta\n        score\n        voteRank\n        comments: commentCollection {\n          edges {\n            node {\n              id\n              message\n              profile {\n                id\n                username\n                avatarUrl\n              }\n            }\n          }\n          commentCount: totalCount\n        }\n      }\n    }\n  }\n}\n```\n\n# Row Level Security Matrix (RLS)\n\nYou can query all policies via: `select * from pg_policies`.\n\nSee: [Row Level Security Matrix (RLS)](./data/supabase/rls-policies.md)\n\n## Read More\n\n- [pg_graphql](https://supabase.github.io/pg_graphql)\n- [pg_graphql Configuration](https://supabase.github.io/pg_graphql/configuration)\n\n## Troubleshooting\n\n1. `dbmate` can create `schema_migrations` tables in schemas. To make sure they are not included in your GraphQL Schema:\n\n```sql\nrevoke select on table public.schema_migrations from anon, authenticated;\n```\n\n2. To [enable inflection](https://supabase.github.io/pg_graphql/configuration/#inflection)\n\n```sql\ncomment on schema public is e'@graphql({\"inflect_names\": true})';\n```\n\n3. Try the heartbeat to see if pg_graphql can access requests\n\n```\nselect graphql_public.graphql(\n\tnull,\n\t$$ { heartbeat }$$\n)\n```\n\nReturns:\n\n```json\n{ \"data\": { \"heartbeat\": \"2022-07-28T17:07:07.90513\" } }\n```\n\n4. Is the `public_graphql` schema not exposed properly?\n\nGetting an 406 status or error message like:\n\n```\n{\n    \"message\": \"The schema must be one of the following: public, storage\"\n}\n```\n\nThen be sure to expose the `graphql_public` in `Settings` \u003e `Project settings` \u003e `API`.\n\n\u003e The schema to expose in your API. Tables, views and stored procedures in this schema will get API endpoints.\n\n![image](https://user-images.githubusercontent.com/1051633/181597157-f9a47a5b-bc6a-49d4-b41e-9c1324b5e2a7.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase-community%2Fsupabase-graphql-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupabase-community%2Fsupabase-graphql-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase-community%2Fsupabase-graphql-example/lists"}