{"id":20906740,"url":"https://github.com/scorpionknifes/gqlmanage","last_synced_at":"2025-05-13T06:33:29.738Z","repository":{"id":57561806,"uuid":"281407365","full_name":"scorpionknifes/gqlmanage","owner":"scorpionknifes","description":"Fully working GraphQL API written in golang with MongoDB. Features include - resolvers, dataloaders, subscriptions, auth, middleware, filter, redis pub/sub etc.","archived":false,"fork":false,"pushed_at":"2020-08-03T15:10:38.000Z","size":346,"stargazers_count":14,"open_issues_count":0,"forks_count":4,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-11-15T14:24:34.497Z","etag":null,"topics":["dataloader","golang","gqlgen","graphql-server","mongodb"],"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/scorpionknifes.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":"2020-07-21T13:36:13.000Z","updated_at":"2024-01-20T09:18:50.000Z","dependencies_parsed_at":"2022-09-21T08:10:46.356Z","dependency_job_id":null,"html_url":"https://github.com/scorpionknifes/gqlmanage","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/scorpionknifes%2Fgqlmanage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorpionknifes%2Fgqlmanage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorpionknifes%2Fgqlmanage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorpionknifes%2Fgqlmanage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scorpionknifes","download_url":"https://codeload.github.com/scorpionknifes/gqlmanage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225184096,"owners_count":17434249,"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":["dataloader","golang","gqlgen","graphql-server","mongodb"],"created_at":"2024-11-18T13:34:55.460Z","updated_at":"2024-11-18T13:34:56.162Z","avatar_url":"https://github.com/scorpionknifes.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"GraphQL API Server with MongoDB\n=======\n\n### Introduction\n\nLearning [gqlgen](https://github.com/99designs/gqlgen) to build full GraphQL servers with MongoDB. The following project is built to manage multiple devices in multiple rooms. This GraphQL API is designed to be secure and requires the user to login to manage devices. A React Frontend is being built to use this API.\n\nThe following Golang Project uses:\n- [MongoDB](https://github.com/mongodb/mongo-go-driver)\n- [dataloaden](https://github.com/vektah/dataloaden)\n- [chi](https://github.com/go-chi/chi)\n- [jwt-go](https://github.com/dgrijalva/jwt-go)\n\n### Instructions\n\nRename [.env-example](.env-example) to .env and setup variables\n```\n# MongoDB server config\nMONGODB_URL=mongodb://localhost/\nMONGODB_DATABASE=gqlmanage\n\n# Server Port\nPORT=8000\nCORS=http://localhost:8000\n\n# JWT Token Settings\nJWT_SECRET=my_jwt_secret\nJWT_ISSUER=my_issuer\n```\n\nNeed to insert first user to access API (TODO)\n\n\n##### Run server\n\n- default port :8000\n- GraphQL Playground default url http://localhost:8080\n\n```bash\ngo run ./main.go\n# OR\ngo run github.com/scorpionknifes/gqlmanage\n```\n\n### Notes\n\n##### Resolvers\n\nCustom resolvers for devices and rooms are created to allow recursive and nested GraphQL calls.\n\nExample of a recursive query.\n\n```graphql\n{\n  rooms{\n    devices{\n      room{\n        devices{\n         ... \n        }\n      }\n    }\n  }\n}\n```\n\n##### Authentication\n\nLogin with username and password to get JWT Token to access other routes. JWT Token has an expire time of 7 days.\n\n```graphql\nmutation login{\n  login(input:{\n    username: \"username\"\n    password: \"password\"\n  }){\n    authToken{\n      accessToken\n    }\n  }\n}\n```\n\nExample result getting JWT token\n\n```graphql\n{\n  \"data\": {\n    \"login\": {\n      \"authToken\": {\n        \"accessToken\": \"JWT_TOKEN_HERE\"\n      }\n    }\n  }\n}\n```\n\nUse JWT token to authenticate. Add Authorization Bearer token in Http Header \n```json\n{\n  \"Authorization\": \"Bearer JWT_TOKEN_HERE\"\n}\n```\n\n##### Dataloader\n\n[Read Here](https://gqlgen.com/reference/dataloaders/) for more info about dataloader in gqlgen.\n\nDataloader solves repeated queries. The dataloader is used in custom resolver for devices.\n\nExample of repeated queries - room needs to be called multiple times for each device that exist\n\n```graphql\n{\n  devices{\n    room{\n      ...\n    } \n  }\n}\n```\n\n##### Subscriptions (with Redis)\n\n[Read Subscription with Redis](https://github.com/99designs/gqlgen/issues/846)\n\n[Read Passing token using Subscription](https://github.com/99designs/gqlgen/issues/691#issuecomment-503352009)\n\nWebsocket subscription is secured with jwt by passing the token through \"graphql-ws\" header. A different jwt extract method is used.\n\nRedis pub/sub for running multiple instances.\n\nExample of using a jwt token using Apollo Client in ReactJS\n```js\nconst subscriptionClient = new SubscriptionClient(\n    \"ws://localhost:8000/query\",\n    {\n        reconnect: true,\n    },\n    null,\n    [ \"graphql-ws\", 'JWT TOKEN' ])\n\nconst wsLink = new WebSocketLink(subscriptionClient);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscorpionknifes%2Fgqlmanage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscorpionknifes%2Fgqlmanage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscorpionknifes%2Fgqlmanage/lists"}