{"id":16528840,"url":"https://github.com/georgekrax/simple-graphql-postgres-api","last_synced_at":"2026-04-10T17:05:09.324Z","repository":{"id":40719621,"uuid":"259559627","full_name":"georgekrax/simple-graphql-postgres-api","owner":"georgekrax","description":"A simple GraphQL API built with Node.js and the Express.js framework. For the database PostgreSQL is used, with the pg-promise library.","archived":false,"fork":false,"pushed_at":"2022-12-12T15:11:34.000Z","size":3897,"stargazers_count":3,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-02-10T05:13:18.852Z","etag":null,"topics":["apollo-server","express","graphql","nodejs","postgresql","sequelize"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/georgekrax.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-04-28T07:09:40.000Z","updated_at":"2025-01-14T10:22:36.000Z","dependencies_parsed_at":"2023-01-27T21:16:14.404Z","dependency_job_id":null,"html_url":"https://github.com/georgekrax/simple-graphql-postgres-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgekrax%2Fsimple-graphql-postgres-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgekrax%2Fsimple-graphql-postgres-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgekrax%2Fsimple-graphql-postgres-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgekrax%2Fsimple-graphql-postgres-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/georgekrax","download_url":"https://codeload.github.com/georgekrax/simple-graphql-postgres-api/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247245812,"owners_count":20907693,"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","express","graphql","nodejs","postgresql","sequelize"],"created_at":"2024-10-11T17:41:58.600Z","updated_at":"2025-12-30T23:07:56.021Z","avatar_url":"https://github.com/georgekrax.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple GraphQL API with PostgreSQL\n\nThis is a simple project for beginners to get their hands dirty and develop a `GraphQL` API with the help Apollo Server, using the `apollo-server-express` library. Also, with this project you can explore how to implement a simple connection between a `PostgreSQL` database and a GraphQL server, with the `pg-promise` library.\n\n- [Node.js](https://nodejs.org/en/)\n- [Express.js](https://expressjs.com/)\n- Apollo server ([apollo-server-express](https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-express))\n- PostgreSQL ([pg-promise](https://github.com/vitaly-t/pg-promise))\n- [nodemon](https://www.npmjs.com/package/nodemon) (v2.0.3)\n\n\u003e **_Note_**: This project does not use any particular style guides, and you are free to make a **pull request** and improve the code as you like.\n\n## Getting started\n\n#### Prerequisites\n\n- [Node.js](https://nodejs.org/en/) (v14.0.0)\n- [express](https://www.npmjs.com/package/express) (v4.17.1)\n- [PostgreSQL](https://www.postgresql.org/) (v12)\n- [pg-promise](https://www.npmjs.com/package/pg-promise) (v10.5.2)\n\nYou can follow the links of the above list, to see explicit instructions on how to install the correnponding package into your operating system. However, you only need [Node.js](https://nodejs.org/en/) \u0026 [PostgreSQL](https://www.postgresql.org/) before proceeding.\n\n#### Installation \u0026 Local development\n\nAfter **cloning** the GitHub repository to your system, please follow below the instructions:\n\n1. Make sure you `cd` into the correct folder, where all of the app files are located, before proceeding with the following steps. Also, you will need the latest version of [Node.js](https://nodejs.org/en/) \u0026 [PostgreSQL](https://www.postgresql.org/), as noticed above.\n\n2. Install the dependencies:\n\n```bash\n$  npm install\n```\n\n3. Run the `db.psql` file, to create the tables, domains and enums in your PostgreSQL server.\n\n```\n$  sudo -u postgres\n$  cd ../\u003cback again to code directory\u003e\n$  psql -f db.psql\n```\n\n4. _(optional):_ You can also seed the tables with some sample data, using the `sample_data.psql` file:\n\n```bash\n$  psql -f sample_data.psql\n```\n\n5. Go ahead and config accordingl the `.env`, which is going to be responsible for storing valuable and sensitive data for accessing the database. Please complete the file like this:\n\n```shell\nDB_USERNAME=\u003cyour_database_username\u003e\nDB_PASSWORD=\u003cyour_database_password\u003e\nDB_NAME=\u003cyour_database_name\u003e\nDB_HOST=\"127.0.0.1\" // or \"localhost\"\nDB_PORT=5432\n```\n\n6. Run the GraphQL API server, by one of the following ways:\n\n```bash\n$  nodemon server.js\n```\n\n**or**\n\n```bash\n$  npm start\n```\n\n**or**\n\n```bash\n$  npm run start\n```\n\n7. Now you have the API setted up and running.\n\n## API Documentation\n\n### Getting Started\n\n- **Base URL**: At present this app can only be run locally and is not hosted as a base URL somewhere live on the web. The GraphQL API is currently hosted at the default port of your computer, http://127.0.0.1:5000/, or http://localhost:5000/, which is set as a proxy in the `package.json` configuration file.\n- **Authentication**: This version of the application does not require and does not use authentication or API keys, to have access on its data.\n\n### Queries\n\n#### Retrive all available hotels\n\n---\n\n```graphql\nquery {\n  hotels {\n    id\n    name\n    category\n    price\n    avg_rating\n    updated_at\n    timestamp\n  }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"hotels\": [\n      {\n        \"id\": 1,\n        \"name\": \"Cassandra Hotel\",\n        \"category\": \"Hotel\",\n        \"price\": 12,\n        \"avg_rating\": 3.2,\n        \"updated_at\": \"2020-04-28T10:30:22.267Z\",\n        \"timestamp\": \"2020-04-28T10:30:17.603Z\"\n      }\n    ]\n  }\n}\n```\n\n#### \u0026 the owner information\n\n```graphql\nquery {\n    hotels {\n        ...\n        owner {\n            id\n            first_name\n            last_name\n        }\n    }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"hotels\": [\n      {\n        \"owner\": [\n          {\n            \"id\": 1,\n            \"first_name\": \"George\",\n            \"last_name\": \"Krachtopoulos\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n#### \u0026 their location details\n\n```graphql\nquery {\n    hotels {\n        ...\n        location {\n            id\n            address\n            city\n            area\n        }\n    }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"hotels\": [\n      {\n        \"location\": [\n          {\n            \"id\": 1,\n            \"address\": \"Kryopigi 25\",\n            \"city\": \"Chalkidiki\",\n            \"area\": null\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n#### \u0026 all their reviews and ratings\n\n```graphql\nquery {\n    hotels {\n        ...\n        reviews {\n            id\n            rating\n            body\n        }\n    }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"hotels\": [\n      {\n        \"reviews\": [\n          {\n            \"id\": 1,\n            \"rating\": 4,\n            \"body\": null\n          },\n          {\n            \"id\": 2,\n            \"rating\": 5,\n            \"body\": null\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n#### Retrieve a single hotel\n\n---\n\nReuqest arguments:\n* **id:** Int!\n\n```graphql\nquery {\n  hotel(id: 1) {\n    id\n    name\n    category\n    price\n    avg_rating\n    updated_at\n    timestamp\n  }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"hotel\": [\n      {\n        \"id\": 1,\n        \"name\": \"Cassandra Hotel\",\n        \"category\": \"Hotel\",\n        \"price\": 12,\n        \"avg_rating\": 3.2,\n        \"updated_at\": \"2020-04-28T10:30:22.267Z\",\n        \"timestamp\": \"2020-04-28T10:30:17.603Z\"\n      }\n    ]\n  }\n}\n```\n\n#### Retrive all hotel reviews\n\n---\n\n```graphql\nquery {\n  reviews {\n    id\n    rating\n    body\n  }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"reviews\": [\n      {\n        \"id\": 1,\n        \"rating\": 4,\n        \"body\": null\n      },\n      {\n        \"id\": 2,\n        \"rating\": 5,\n        \"body\": null\n      }\n    ]\n  }\n}\n```\n\n#### \u0026 with the hotel information for a specific review\n\n```graphql\nquery {\n  reviews {\n    id\n    rating\n    body\n    hotel {\n      id\n      name\n      category\n      price\n      avg_rating\n      updated_at\n      timestamp\n    }\n  }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"reviews\": [\n      {\n        \"id\": 1,\n        \"rating\": 4,\n        \"body\": null,\n        \"hotel\": [\n          {\n            \"id\": 1,\n            \"name\": \"Cassandra Hotel\",\n            \"category\": \"Hotel\",\n            \"price\": 12,\n            \"avg_rating\": 3.2,\n            \"updated_at\": \"2020-04-28T10:30:22.267Z\",\n            \"timestamp\": \"2020-04-28T10:30:17.603Z\"\n          }\n        ]\n      },\n      {\n        \"id\": 2,\n        \"rating\": 5,\n        \"body\": null,\n        \"hotel\": [\n          {\n            \"id\": 1,\n            \"name\": \"Cassandra Hotel\",\n            \"category\": \"Hotel\",\n            \"price\": 12,\n            \"avg_rating\": 3.2,\n            \"updated_at\": \"2020-04-28T10:30:22.267Z\",\n            \"timestamp\": \"2020-04-28T10:30:17.603Z\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n#### Retrieve all hotel locations\n\n---\n\n```graphql\nquery {\n  locations {\n    id\n    address\n    city\n    area\n  }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"locations\": [\n      {\n        \"id\": 1,\n        \"address\": \"Kryopigi 25\",\n        \"city\": \"Chalkidiki\",\n        \"area\": null\n      }\n    ]\n  }\n}\n```\n\n#### Retrieve all hotel owners\n\n---\n\n```graphql\nquery {\n  owners {\n    id\n    first_name\n    last_name\n  }\n}\n```\n\nResponse:\n\n```json\n{\n  \"data\": {\n    \"owners\": [\n      {\n        \"id\": 1,\n        \"first_name\": \"George\",\n        \"last_name\": \"Krachtopoulos\"\n      }\n    ]\n  }\n}\n```\n\n## Authors\n\nThis project is initally created by [me](https://github.com/georgekrax), George Krachtopoulos. Please feel free to contact me if you need any help, and make sure to follow me for more updates.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgekrax%2Fsimple-graphql-postgres-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeorgekrax%2Fsimple-graphql-postgres-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgekrax%2Fsimple-graphql-postgres-api/lists"}