{"id":15910579,"url":"https://github.com/davidnguyen11/typescript-graphql-postgres-boilerplate","last_synced_at":"2025-03-22T08:30:47.470Z","repository":{"id":105842856,"uuid":"190360730","full_name":"davidnguyen11/typescript-graphql-postgres-boilerplate","owner":"davidnguyen11","description":"Simple boilerplate integrated typescript, graphql, postgres and apollo server","archived":false,"fork":false,"pushed_at":"2019-06-30T12:45:32.000Z","size":21,"stargazers_count":23,"open_issues_count":0,"forks_count":6,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-18T09:51:34.942Z","etag":null,"topics":["apollo","apollo-graphql","apollo-server","apollo-server-express","graphql","postgres","typescript"],"latest_commit_sha":null,"homepage":"","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/davidnguyen11.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-06-05T08:54:54.000Z","updated_at":"2024-03-28T12:11:36.000Z","dependencies_parsed_at":"2023-06-14T10:30:33.549Z","dependency_job_id":null,"html_url":"https://github.com/davidnguyen11/typescript-graphql-postgres-boilerplate","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"f3f727db720056ebe5b59be01a6072e50cddef6d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidnguyen11%2Ftypescript-graphql-postgres-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidnguyen11%2Ftypescript-graphql-postgres-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidnguyen11%2Ftypescript-graphql-postgres-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidnguyen11%2Ftypescript-graphql-postgres-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidnguyen11","download_url":"https://codeload.github.com/davidnguyen11/typescript-graphql-postgres-boilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244931356,"owners_count":20534005,"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","apollo-graphql","apollo-server","apollo-server-express","graphql","postgres","typescript"],"created_at":"2024-10-06T15:09:39.516Z","updated_at":"2025-03-22T08:30:47.464Z","avatar_url":"https://github.com/davidnguyen11.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graphql Todo API\n\n- [Getting started](#getting-started)\n  - [.env file](#env-file)\n  - [Database](#database)\n  - [Seeding data](#seeding-data)\n- [Development](#development)\n- [Production](#production)\n- [How to write GraphQL](#how-to-write-graphql)\n  - [1. Define the schema \u0026 type](#1-define-the-schema--type)\n  - [2. Register \\*.graphql in schema.graphql](#2-register-graphql-in-schemagraphql)\n  - [3. Define models for data](#3-define-models-for-data)\n  - [4. Implement the resolvers](#4-implement-the-resolvers)\n- [Playground](#playground)\n- [Usage](#usage)\n- [References](#references)\n\n## Getting started\n\n- Make sure you have [Docker](https://www.docker.com/) installed on your machine.\n- Make sure you have [NodeJS](https://nodejs.org/en/) installed on your machine.\n\nThen run\n\n**npm**\n\n```bash\nnpm i\n```\n\n**yarn**\n\n```bash\nyarn install\n```\n\n### .env file\n\n**.env file**\n\n1. Create the `.env` file\n2. Copy and parse the database connection information below:\n\n```bash\nPOSTGRES_USER=docker\nPOSTGRES_PASSWORD=docker\nPOSTGRES_HOST=localhost\nPOSTGRES_DB=todo\nPOSTGRES_PORT=54320\n```\n\n### Database\n\nTo create database, run:\n\n```bash\ndocker-compose up -d\n```\n\n### Seeding data\n\n**dump data**\n\nTo initialize the dump data for a database, run:\n\n```bash\nnpm run seed\n```\n\n## Development\n\nTo run on development environment\n\n```bash\nnpm run dev\n```\n\n## Production\n\nTo run on production environment\n\n```bash\nnpm start\n```\n\n## How to write GraphQL\n\n### 1. Define the schema \u0026 type\n\nFor more information: [https://graphql.org/learn/schema/](https://graphql.org/learn/schema/)\n\n**graphql/types/todo-list.graphql**\n\n```bash\ntype ResponseTodoList {\n  status: String!\n  message: String!\n  data: [TodoListItem]\n}\n\ntype TodoListItem {\n  id: ID!\n  content: String!\n}\n\ninput InputTodoListItem {\n  content: String!\n}\n\ntype Query {\n  todoListItems(keyword: String): ResponseTodoList!\n}\n\ntype Mutation {\n  createTodoItem(item: InputTodoListItem): ResponseTodoList!\n}\n```\n\n### 2. Register \\*.graphql in schema.graphql\n\n**graphql/types/schema.graphql**\n\n```bash\n# import Query.*, Mutation.* from \"todo-list.graphql\"\n```\n\n### 3. Define models for data\n\nThe model actually the type of data mapped to fields of table in database.\n\n**models/todo-list.ts**\n\n```ts\nexport interface TodoListItem {\n  id: number;\n  content: string;\n  created_at: Date;\n  updated_at: Date;\n}\n\nexport interface InputTodoListItem {\n  content: string;\n}\n```\n\n### 4. Implement the resolvers\n\n**graphql/resolvers/queries/todoListItems.ts**\n\n```ts\nimport { DB } from '../../../types';\n\nexport async function todoListItems(db: DB, args: any) {\n  const res = await db.query('SELECT * FROM todo_list');\n  ...\n}\n```\n\n**graphql/resolvers/mutations/createTodoItem.ts**\n\n```ts\nimport { DB } from '../../../types';\n\nexport async function createTodoItem(db: DB, args: any) {\n  const query = 'INSERT INTO todo_list(content) VALUES($1) RETURNING *';\n  const values = ['Call Your Dad'];\n  const res = await db.query(query, values);\n  ...\n}\n```\n\n## Playground\n\nThis sandbox can only run in development mode by command `yarn dev` or `npm run dev`. After starting the development environment, open:\n\n- [http://localhost:4000/graphql](http://localhost:4000/graphql)\n\n**query - without param**\n\n```bash\nquery{\n  todoListItems{\n    status\n    data{\n      content\n    }\n  }\n}\n```\n\n**query - with param**\n\n```bash\nquery{\n  todoListItems(keyword: \"Call your Mom\"){\n    status\n    data{\n      content\n    }\n  }\n}\n```\n\n**mutation - createTodoItem**\n\n```bash\nmutation{\n  createTodoItem(item:{\n    content: \"Just relax, dude!\"\n  }){\n    status\n    data{\n      content\n    }\n  }\n}\n```\n\n# Usage\n\nWith `express-graphql`, you can just send an HTTP **POST** request to the endpoint you mounted your GraphQL server on, passing the GraphQL query as the query field in a JSON payload.\n\n**POST cURL**\n\n```bash\ncurl -X POST \\\n  http://localhost:4000/graphql \\\n  -H 'Content-Type: application/json' \\\n  -H 'Postman-Token: c011dc94-6f67-483a-84cb-2bd4ed442a95' \\\n  -H 'cache-control: no-cache' \\\n  -d '{\n\t\"query\": \"{ todoListItems{ data { content } } }\"\n}'\n```\n\n**GET cURL**\n\n```bash\ncurl -X GET \\\n  'http://localhost:4000/graphql?query=query+todoListItems%28$keyword:String%29{todoListItems%28keyword:$keyword%29{status}}\u0026variables={%22keyword%22:%22Call%20your%20Mom%22}' \\\n  -H 'Postman-Token: f92396a4-4f51-47f0-ac20-3c900289358f' \\\n  -H 'cache-control: no-cache'\n```\n\n**POST fetch**\n\n```js\nconst keyword = 'Call your Mom';\nconst query = `{ todoListItems(keyword: \"${keyword}\"){ data { content } } }`;\n\nfetch('/graphql', {\n  method: 'POST',\n  headers: {\n    'Content-Type': 'application/json',\n    Accept: 'application/json',\n  },\n  body: JSON.stringify({ query }),\n})\n  .then(res =\u003e res.json())\n  .then(data =\u003e console.log('data returned:', data));\n```\n\n**GET fetch**\n\n```js\nconst query = `\n  todoListItems($keyword:String){\n    todoListItems(keyword:$keyword){\n      status\n      data{\n        content\n      }\n    }\n  }\n`;\n\nconst variables = `{\"keyword\":\"Call your Mom\"}`;\n\nfetch(`/graphql?query=query+${query}\u0026variables=${variables}`)\n  .then(res =\u003e res.json())\n  .then(data =\u003e console.log('data returned:', data));\n```\n\n_For more information check:_\n\n- [https://graphql.org/graphql-js/graphql-clients/](https://graphql.org/graphql-js/graphql-clients/)\n- [https://blog.apollographql.com/4-simple-ways-to-call-a-graphql-api-a6807bcdb355](https://blog.apollographql.com/4-simple-ways-to-call-a-graphql-api-a6807bcdb355)\n\n# References\n\n- [node-postgres](https://node-postgres.com/)\n- [graphql](https://graphql.org/)\n- [Apollo server](https://www.apollographql.com/docs/apollo-server/)\n- [Docker](https://www.docker.com/)\n- [Docker compose](https://docs.docker.com/compose/)\n- [https://graphql.org/graphql-js/graphql-clients/](https://graphql.org/graphql-js/graphql-clients/)\n- [https://blog.apollographql.com/4-simple-ways-to-call-a-graphql-api-a6807bcdb355](https://blog.apollographql.com/4-simple-ways-to-call-a-graphql-api-a6807bcdb355)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidnguyen11%2Ftypescript-graphql-postgres-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidnguyen11%2Ftypescript-graphql-postgres-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidnguyen11%2Ftypescript-graphql-postgres-boilerplate/lists"}