{"id":13798067,"url":"https://github.com/OscarYuen/go-graphql-starter","last_synced_at":"2025-05-13T05:31:34.948Z","repository":{"id":27487043,"uuid":"114106478","full_name":"OscarYuen/go-graphql-starter","owner":"OscarYuen","description":"This repository uses graph-gophers/graphql-go to build a starter web application","archived":false,"fork":false,"pushed_at":"2020-07-14T06:29:45.000Z","size":5655,"stargazers_count":213,"open_issues_count":2,"forks_count":52,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-18T08:02:29.145Z","etag":null,"topics":["backend","go","golang","graphql","sqlx","starter"],"latest_commit_sha":null,"homepage":"","language":"Go","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/OscarYuen.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}},"created_at":"2017-12-13T10:22:40.000Z","updated_at":"2024-10-14T01:01:29.000Z","dependencies_parsed_at":"2022-07-27T09:32:30.780Z","dependency_job_id":null,"html_url":"https://github.com/OscarYuen/go-graphql-starter","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/OscarYuen%2Fgo-graphql-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarYuen%2Fgo-graphql-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarYuen%2Fgo-graphql-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarYuen%2Fgo-graphql-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OscarYuen","download_url":"https://codeload.github.com/OscarYuen/go-graphql-starter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253883093,"owners_count":21978607,"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":["backend","go","golang","graphql","sqlx","starter"],"created_at":"2024-08-04T00:00:38.525Z","updated_at":"2025-05-13T05:31:34.581Z","avatar_url":"https://github.com/OscarYuen.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"## Go Graphql Starter\n[![GitHub license](https://img.shields.io/github/license/OscarYuen/go-graphql-starter.svg)](https://github.com/OscarYuen/go-graphql-starter/blob/master/LICENSE)\n\n\nThis project aims to use [graph-gophers/graphql-go](https://github.com/graph-gophers/graphql-go) to build a starter web application. This project has already been used as backend application in production. \n\nIn case you need to get called from another frontend side, CORS may needed to be enabled in this application as this project mainly focuses on backend logic at this stage. \n\n\nThis project would be continuously under development for enhancement. Pull request is welcome. \n\n\n#### RoadMap:\n- [x] Integrated with sqlx\n- [x] Integrated with graphql-go\n- [x] Use go-bindata to generate Go code from .graphql file\n- [x] Use psql\n- [x] Integrated with dataloader\n- [x] Add authentication \u0026 authorization\n- [ ] Add unit test cases\n- [ ] Support subscription\n- [ ] Support web-socket notification and messaging\n\n#### Structure\n    go-graphql-starer\n    │   README.md\n    │   server.go           --- the entry file\n    │   Config.toml         --- the configuration file for setting server parameter\n    │   Dockerfile\n    │   Gopkg.lock          --- generated file from dependency management tool, dep\n    │   Gopkg.toml          --- generated file from dependency management tool, dep\n    │   graphiql.html       --- the html for graphiql which is used for testing query \u0026 mutation\n    └───context             --- application context like db configuration\n    └───data                --- storing the sql data patch for different version\n    │   └───1.0             --- storing sql data patch for version 1.0\n    │      └───...          --- sql files\n    └───handler             --- the handler used for chaining http request like authentication, logging etc.\n    └───loader              --- implementation of dataloader for caching and batching the graphql query\n    └───model               --- the folder putting struct file\n    └───resolver            --- implementation of graphql resolvers\n    └───schema              --- definition of graphql schemas\n    │   │   schema.go       --- used for generate go code from static graphql files inside 'type' folder\n    │   │   schema.graphql  --- graphql root schema\n    │   └───type            --- folder for storing graphql schema in *.graphql format\n    │       └───...         --- graphql schema files in *.graphql format\n    └───service             --- services for users, authorization etc.\n    └───util                --- utilities\n    \n#### Requirement:\n\n1. Postgres database\n2. Golang\n\nRemark: If you want to use other databases, please feel free to change the driver in `context/db.go`\n\n#### Usage(Without docker):\n\n1. Run the sql scripts under `data/1.0` folder inside Postgres database console\n\n2. Install go-bindata\n    ```\n    go get -u github.com/jteeuwen/go-bindata/...\n    ```\n\n3. Setup GOPATH (Optional if already set)\n\n    For example: MacOS\n    ```\n    export GOPATH=/Users/${username}/go\n    export PATH=$PATH:$GOPATH/bin\n    ```\n\n4. Run the following command at root directory to generate Go code from .graphql file\n    ```\n    go-bindata -ignore=\\.go -pkg=schema -o=schema/bindata.go schema/...\n    ```\n\n    OR\n\n    ```\n    go generate ./schema\n    ```\n    There would be bindata.go generated under `schema` folder\n\n5. Start the server (Ensure your postgres database is live and its setting in Config.toml is correct)\n    ```\n    go build server.go\n    ```\n    \n#### Usage(With docker):\n\n1. Run the sql scripts under `data/1.0` folder inside Postgres database console\n\n2. Build docker image\n    ```\n    docker build -t go-graphql-starter .\n    ```\n\n3. Run docker image (Ensure your database setting in Config.toml is correct)\n    ```\n    docker run go-graphql-starter\n    ```\n\n#### Usage(With docker-compose):\n\n1. Create a folder `/psqldata` on your OS system and set it for file sharing in docker\n\n2. Create and starter services by docker-compose\n    ```\n    docker-compose up\n    ```\n    \n        \n#### Graphql Example:\n\nTest in graphiql by the following endpoint\n\n```\nlocalhost:3000\n```\n\nBasically there are two graphql queries and one mutation\n\n##### Query:\n1. Get a user by email\n2. Get user list by cursor pagination\n\n##### Mutation:\n\nTo query a list of users, you need to be authenticated.\nAuthentication is not required for other operations.\nIn order to authenticate, here are the steps to follow:\n\n1. Create a user\n\n```graphql\nmutation {\n  createUser (email: \"tester@tester.com\", password: \"123456\") {\n    id\n  }\n}\n```\n\n2. Log in by submitting your email and password through a Basic Authorization Header.\n\nHere's an example on how to achieve this:\n\n       a. Download [Insomnia](https://insomnia.rest/) OR Other RESTful endpoint testing tools e.g. Postman\n\n       b. Create a new POST request, paste `localhost:3000/login` in the URL bar and go to the Header tab\n\n       c. Generate your basic Authorization on [blitter.se](https://www.blitter.se/utils/basic-authentication-header-generator/)\n\n       d. In Insomnia, first column, type Authorization, second column enter the Basic you just copied `Basic dGVzdGVyQHRlc3Rlci5jb206a3Rta3Rt`\n\n       e. Click send, you should get a jwt token back.\n\nYou can change the Authorization of request header in `graphiql.html` and restart the server to see the effect of authentication using token\n\n#### Test:\n\n- Run Unit Tests\n    ```\n    go test\n    ```\n    \n#### Reference\n\n-[graph-gophers/graphql-go](https://github.com/graph-gophers/graphql-go)\n\n-[tonyghita/graphql-go-example](https://github.com/tonyghita/graphql-go-example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOscarYuen%2Fgo-graphql-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOscarYuen%2Fgo-graphql-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOscarYuen%2Fgo-graphql-starter/lists"}