{"id":15556503,"url":"https://github.com/gforge/subscription_example","last_synced_at":"2025-04-23T20:46:48.084Z","repository":{"id":48558635,"uuid":"158612392","full_name":"gforge/subscription_example","owner":"gforge","description":null,"archived":false,"fork":false,"pushed_at":"2021-09-18T22:15:43.000Z","size":367,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-18T05:53:42.680Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/gforge.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":"2018-11-21T22:15:21.000Z","updated_at":"2021-09-18T22:15:46.000Z","dependencies_parsed_at":"2022-09-23T17:42:15.641Z","dependency_job_id":null,"html_url":"https://github.com/gforge/subscription_example","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/gforge%2Fsubscription_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gforge%2Fsubscription_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gforge%2Fsubscription_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gforge%2Fsubscription_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gforge","download_url":"https://codeload.github.com/gforge/subscription_example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250513405,"owners_count":21443201,"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":[],"created_at":"2024-10-02T15:14:02.317Z","updated_at":"2025-04-23T20:46:48.066Z","avatar_url":"https://github.com/gforge.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# An ApolloServer subscription example with passport\n\nA simple example to run a ApolloServer with subscriptions and authorization. The logic in this example contains:\n\n- login functionality using `graphql-passport`\n- message publication using subscriptions\n- filtering subscriptions\n- checking subscriptions for valid credentials\n\n## Direct run\n\nFor running in any NodeJS environment you have two options:\n\n- `npm run start` - runs `ts-node` and starts the application\n- `npm run dev` - runs `ts-node-dev` and allows you to do changes in the application with automated respawns\n\n## Docker\n\n### Using `docker-compose`\n\nThe simplest aproach is to just run:\n\n```bash\ndocker-compose up\n```\n\n### Using plain `docker`\n\nPackage also contains a Dockerfile that can be used to isolate the app. The\ncode is inspired by: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/\n\nBuild using (use sudo if you haven't added your user to the Docker group - not\nthat adding may be a security issue):\n\n```bash\ndocker build -t \u003cyour username\u003e/subscription-app .\n```\n\nTo run just write (the `--rm` makes it easier to clean up the container):\n\n```bash\ndocker run --name subapp --rm -p 49160:4000 -d \u003cyour username\u003e/subscription-app\n```\n\n### Extra stuff\n\nAdditional useful commands:\n\n```bash\n# Get container ID\n$ docker ps\n\n# Print app output\n$ docker logs \u003ccontainer id or name ('subapp' if used above run)\u003e\n\n# Enter the container\n$ docker exec -it \u003ccontainer id or name ('subapp' if used above run)\u003e /bin/bash\n```\n\n## Testing\n\nThen you can connect to it on [localhost:4000/graphql](http://localhost:4000/graphql) and run two simultaneous graphql queries in multiple tabs. **Note** Once you enter a subscription the context will never change, thus we need to first login:\n\n```gql\nmutation {\n  login(email: \"john@doe.com\", password: \"pwd123\") {\n    name\n  }\n}\n```\n\nThen in a new tab, start a subscription:\n\n```gql\nsubscription {\n  newMessage\n}\n```\n\nThe third tab should do a mutation for publishing to the subscription-tab:\n\n```gql\nmutation {\n  addMessage(message: \"Testing to send a subscription message\")\n}\n```\n\nAfter running the mutation you should see \"Testing to send a subscription message\" in the subscription tab:\n\n```json\n{\n  \"data\": {\n    \"newMessage\": \"Testing to send a subscription message\"\n  }\n}\n```\n\n### Tips\n\nTo test the user login functionality with multiple users you can start an _incognito_/_private_ window or an alternative browser, load up the playground and see how messages are sent between users.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgforge%2Fsubscription_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgforge%2Fsubscription_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgforge%2Fsubscription_example/lists"}