- Notifications
You must be signed in to change notification settings - Fork14
A demo of what an equivalent REST API and GraphQL API look like.
License
GraphQLGuide/graphql-rest-api-demo
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A demo of what an equivalent REST API and GraphQL API look like. This code is used in the first chapter ofThe GraphQL Guide byJohn Resig andLoren Sands-Ramshaw. Here's the GraphQL server's GraphiQL:
To install you'll want to runnpm install oryarn to install all of the Node modules.
Additionally, you'll need to have a copy ofMongoDB running. If you're on OSX you can useHomebrew 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 runbrew services start mongodb to start it.
You'll also want to populate the database with some data to test your queries. You can do this by running themongo testdb command on the command-line and executing the following commands to create a new database, some collections, and the data inside of them:
db.users.insert({_id: "123", username: "jeresig", groupId: "dev"})db.users.insert({_id: "456", username: "lorensr", groupId: "author"})db.groups.insert({_id: "dev", name: "Developers"})db.groups.insert({_id: "author", name: "Authors"})By 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 inmodels.js.
Our data models representing the MongoDB database are inmodels.js. We useMongoose to do the object modeling and provide a convenient way of accessing and mutating the data in the MongoDB collections.
The REST API is implemented usingNode Express and provides a couple endpoints for accessing user data.
You can run it using:
node rest-server.jsYou can access the REST API by opening your browser and visiting either of the following URLs:
- localhost:3000/users - All users.
- localhost:3000/users/123 - An individual user record.
The GraphQL server is implemented usingNode Express,GraphQL.js, andGraphQL Express. It provides access to both the User and Group type.
You can run it using:
node graphql-server.jsYou can access the GraphQL data by opening your browser and visiting theGraphiQL view at:
You 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.
About
A demo of what an equivalent REST API and GraphQL API look like.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.