Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A demo of what an equivalent REST API and GraphQL API look like.

License

NotificationsYou must be signed in to change notification settings

GraphQLGuide/graphql-rest-api-demo

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:

ch1.graphql.guide/graphql

Installation

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.

Data Models

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.

REST API

The REST API is implemented usingNode Express and provides a couple endpoints for accessing user data.

You can run it using:

node rest-server.js

You can access the REST API by opening your browser and visiting either of the following URLs:

GraphQL Server

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.js

You 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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp