GithubHelp home page GithubHelp logo

charan1922 / basicgraphqlexample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gethyl/basicgraphqlexample

0.0 1.0 0.0 3.99 MB

This is a very basic repository to show how GraphQL server can be set up and tested.

JavaScript 85.12% HTML 14.88%

basicgraphqlexample's Introduction

Graph SQL Server Example

This is a short example to help setup a GraphQL server on Node using Express and connect to Mongo DB using Mongoose.

Refer package.json's dependencies and devDependencies to see the npm packages and versions used.

Important Files and Folders

File/Folder Description
index.html The main HTML file
server.js GraphQL Express Server
graphql Folder related to graphQL Schema.
mongoose Folder related to Mongoose(mongodb) Schema and Model

Pre-requisites for this example to work.

This example uses mongodb installed on the local machine.

  • Refer Installation for instructions to install mongodb locally on your machine.
  • MongoDb has only a CLI, so you can install any UI tools for mongodb so that its easier to work on the database. I have installed robomongo and find it perfect for my basic use cases.

Starting the GraphQL server

  • Before running the example we start the mongo db service using the below command.
sudo service mongod start
  • Once the service is up and running, then issue the below command to start your graph QL server. Note - babel-node is to be used in Dev environments only.
npm run dev3

Testing the server

  • In this example we have a mongodb collection called TodoList which has the below schema:
    itemId: Number,
    item: String,
    completed: Boolean

  • Once the server is up, go to browser and run http://localhost:3000/.
    • The first section is a simple form which you can use to insert a new task to the TodoList collection.

As this is a basic example, only the property item is taken from the html, while itemId and completed are hardcoded as 1 and false respectively.

  • The second section is where we can see how GraphQL is used to GET value from TodoList where itemId = 1(hardcoded), by clicking on the link.

basicgraphqlexample's People

Contributors

gethyl avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.