{"id":26915163,"url":"https://github.com/graphqlguide/graphql-rest-api-demo","last_synced_at":"2025-04-01T17:51:43.134Z","repository":{"id":52157988,"uuid":"112928060","full_name":"GraphQLGuide/graphql-rest-api-demo","owner":"GraphQLGuide","description":"A demo of what an equivalent REST API and GraphQL API look like.","archived":false,"fork":false,"pushed_at":"2022-12-07T23:21:22.000Z","size":59,"stargazers_count":55,"open_issues_count":4,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T03:43:55.475Z","etag":null,"topics":["demo","graphql","graphql-server","mongodb","mongoose","rest-api"],"latest_commit_sha":null,"homepage":"https://ch1.graphql.guide/graphql","language":"JavaScript","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/GraphQLGuide.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-03T12:58:30.000Z","updated_at":"2024-12-31T05:53:25.000Z","dependencies_parsed_at":"2023-01-24T23:46:00.058Z","dependency_job_id":null,"html_url":"https://github.com/GraphQLGuide/graphql-rest-api-demo","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/GraphQLGuide%2Fgraphql-rest-api-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQLGuide%2Fgraphql-rest-api-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQLGuide%2Fgraphql-rest-api-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQLGuide%2Fgraphql-rest-api-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GraphQLGuide","download_url":"https://codeload.github.com/GraphQLGuide/graphql-rest-api-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246686414,"owners_count":20817788,"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":["demo","graphql","graphql-server","mongodb","mongoose","rest-api"],"created_at":"2025-04-01T17:51:42.704Z","updated_at":"2025-04-01T17:51:43.132Z","avatar_url":"https://github.com/GraphQLGuide.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL/REST API Demo\n\nA demo of what an equivalent REST API and GraphQL API look like. This code is used in the first chapter of [The GraphQL Guide](https://graphql.guide/) by [John Resig](https://johnresig.com/) and [Loren Sands-Ramshaw](http://lorensr.me/). Here's the GraphQL server's GraphiQL:\n\n[ch1.graphql.guide/graphql](https://ch1.graphql.guide/graphql)\n\n## Installation\n\nTo install you'll want to run `npm install` or `yarn` to install all of the Node modules.\n\nAdditionally, you'll need to have a copy of [MongoDB](https://www.mongodb.com/) running. If you're on OSX you can use [Homebrew](https://brew.sh/) to install MongoDB by running: `brew install mongodb`. That should also start the database server in the background, as well. If it's not running you can run `brew services start mongodb` to start it.\n\nYou'll also want to populate the database with some data to test your queries. You can do this by running the `mongo testdb` command on the command-line and executing the following commands to create a new database, some collections, and the data inside of them:\n\n```\ndb.users.insert({_id: \"123\", username: \"jeresig\", groupId: \"dev\"})\ndb.users.insert({_id: \"456\", username: \"lorensr\", groupId: \"author\"})\ndb.groups.insert({_id: \"dev\", name: \"Developers\"})\ndb.groups.insert({_id: \"author\", name: \"Authors\"})\n```\n\nBy default the servers are expecting to find data on your local computer in a database named \"testdb\". You can configure this by changing the settings in `models.js`.\n\n## Data Models\n\nOur data models representing the MongoDB database are in `models.js`. We use [Mongoose](http://mongoosejs.com/) to do the object modeling and provide a convenient way of accessing and mutating the data in the MongoDB collections.\n\n## REST API\n\nThe REST API is implemented using [Node Express](https://expressjs.com/) and provides a couple endpoints for accessing user data.\n\nYou can run it using:\n\n```\nnode rest-server.js\n```\n\nYou can access the REST API by opening your browser and visiting either of the following URLs:\n\n* [localhost:3000/users](http://localhost:3000/users) - All users.\n* [localhost:3000/users/123](http://localhost:3000/users/123) - An individual user record.\n\n## GraphQL Server\n\nThe GraphQL server is implemented using [Node Express](https://expressjs.com/), [GraphQL.js](https://github.com/graphql/graphql-js), and [GraphQL Express](https://github.com/graphql/express-graphql). It provides access to both the User and Group type.\n\nYou can run it using:\n\n```\nnode graphql-server.js\n```\n\nYou can access the GraphQL data by opening your browser and visiting the [GraphiQL](https://github.com/graphql/graphiql) view at:\n\n* [localhost:3000/graphql](http://localhost:3000/graphql)\n\nYou should see a console interface into which you can run GraphQL queries and see their results. You should also be able to browse the full schema and see all of the types that are available to you and what data they provide.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphqlguide%2Fgraphql-rest-api-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphqlguide%2Fgraphql-rest-api-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphqlguide%2Fgraphql-rest-api-demo/lists"}