{"id":13667052,"url":"https://github.com/theogravity/graphql-pothos-server-example","last_synced_at":"2025-04-10T05:23:38.877Z","repository":{"id":72004998,"uuid":"403490864","full_name":"theogravity/graphql-pothos-server-example","owner":"theogravity","description":"Example implementation of the Pothos (formerly GiraphQL) library to create a GraphQL server with queries, mutations, and subscriptions along with unit and integration tests.","archived":false,"fork":false,"pushed_at":"2023-04-24T22:06:12.000Z","size":1001,"stargazers_count":43,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-24T06:45:24.471Z","etag":null,"topics":["apollo-server","dataloader","datasource","giraphql","gql","graphql","jest","pothos","sequelize","sqlite","subscriptions","testing","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theogravity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-09-06T05:00:54.000Z","updated_at":"2025-01-20T13:36:48.000Z","dependencies_parsed_at":"2023-06-14T11:15:35.082Z","dependency_job_id":null,"html_url":"https://github.com/theogravity/graphql-pothos-server-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theogravity%2Fgraphql-pothos-server-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theogravity%2Fgraphql-pothos-server-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theogravity%2Fgraphql-pothos-server-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theogravity%2Fgraphql-pothos-server-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theogravity","download_url":"https://codeload.github.com/theogravity/graphql-pothos-server-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161731,"owners_count":21057643,"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":["apollo-server","dataloader","datasource","giraphql","gql","graphql","jest","pothos","sequelize","sqlite","subscriptions","testing","typescript"],"created_at":"2024-08-02T07:00:27.795Z","updated_at":"2025-04-10T05:23:38.838Z","avatar_url":"https://github.com/theogravity.png","language":"TypeScript","readme":"# Pothos GraphQL Server Example\n\nThis repo demonstrates how to use the graphQL code-based \n[pothos](https://pothos-graphql.dev) (formerly named `giraphql`) library to build queries,\nmutations, subscriptions, and add directives. \n\nIt also includes sample `jest` tests.\n\nIt is written using Typescript.\n\nComponents: \n\n- [pothos](https://pothos-graphql.dev)\n- [Apollo Server](https://www.apollographql.com/docs/apollo-server/)\n- [Apollo Server Express](https://www.npmjs.com/package/apollo-server-express)\n- [graphql-ws](https://github.com/enisdenjo/graphql-ws) for subscriptions and as a testing client for subscriptions\n- [Sequelize ORM w/ sqlite](https://sequelize.org/master/)\n- [sequelize-typescript](https://www.npmjs.com/package/sequelize-typescript) for defining `sequelize` models\n- [dataloader-sequelize](https://github.com/mickhansen/dataloader-sequelize) as a [dataloader](https://www.apollographql.com/docs/apollo-server/data/data-sources/#using-with-dataloader) provider for `sequelize`\n- [graphql-playground](https://github.com/graphql/graphql-playground)\n- [graphql-codegen](https://www.graphql-code-generator.com/) to generate the schema file and typescript definitions for frontend consumption, along with a fully-typed GQL client\n\n## Installing\n\nnode.js v14 is the baseline requirement.\n\n`$ yarn`\n\n## Running\n\n`$ yarn dev`\n\nThe server will start on port `3000`.\n\n- GQL API: `http://localhost:3000/graphql`\n- Playground: [http://localhost:3000/playground](http://localhost:3000/playground)\n\n## Tests\n\nRun unit tests with:\n\n`$ yarn test:unit`\n\nIntegration tests:\n\n`$ yarn test:integration`\n\n## Schema + Typescript definition generation\n\nYou can use the [`graphql-codegen`](https://www.graphql-code-generator.com/) generated files with your frontend for type information when calling the server.\n\n`$ yarn generate`\n\nGenerated files are located in the `gql-schema` directory.\n\nThe following plugins are used:\n\n- [typescript](https://www.graphql-code-generator.com/docs/plugins/typescript)\n- [typescript-apollo-client-helpers](https://www.graphql-code-generator.com/docs/plugins/typescript-apollo-client-helpers)\n\n## Directory structure\n\nIn the `src/` folder:\n\n- `datasources/`: Apollo datasources for making db calls\n- `db/`: Sequelize models\n- `gql/`: `pothos` definitions\n\nThe `gql/` folder is organized by domain. The reason I've done this vs organizing\nby queries or mutations is the following:\n\n- `pothos` is a code-based gql definition library. Because it's code-based, you have a lot of control\non how to define your graphQL items. The trade-off is that it's more verbose. If you were to\nshove everything under a single query or mutation file, it would be extremely difficult to navigate and read.\n- Types themselves can have multiple resolvers that are independent of a query or mutation and can alone be quite verbose / complex.\n- It's easier to find files that are specific to the function in an IDE. For example, the post creation mutation can be easily discovered in file search.\n- All the code for that specific function lives in a single file makes it easier to bounce back and forth from vs jumping between files.\n\n## Sample queries\n\nHere's some queries to try out in the playground:\n\nCreate a user and post:\n\n```gql\nmutation {\n  createUser(input: {\n    name:\"Theo Gravity\"\n  }) {\n    user {\n      id\n    }\n  }\n  createPost(input:{\n    authorId: 1\n    title:\"Test title\",\n    content:\"Test post\"\n  }) {\n    id\n  }\n}\n```\n\nQuery for user posts:\n\n```gql\nquery {\n  user(id: 1) {\n    id\n    name\n    posts {\n      id\n      title\n      content\n      created\n    }\n  }\n}\n```\n\nGet users:\n\n```gql\nquery {\n  users {\n    id\n    name\n  }\n}\n```\n\nGet posts:\n\n```gql\nquery {\n  posts {\n    id\n    title\n    content\n    created\n    author {\n      name\n    }\n  }\n}\n```\n","funding_links":[],"categories":["Examples"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheogravity%2Fgraphql-pothos-server-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheogravity%2Fgraphql-pothos-server-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheogravity%2Fgraphql-pothos-server-example/lists"}