All Projects → xpepermint → graphql-example

xpepermint / graphql-example

Licence: other
Intuitive GraphQL Resolver Example - Application example using RawModel.js as GraphQL rootValue on steroids.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to graphql-example

Pup
The Ultimate Boilerplate for Products.
Stars: ✭ 563 (+2152%)
Mutual labels:  example, graphql-server
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (+11936%)
Mutual labels:  resolver, graphql-server
Graphql Go Example
Example use of https://github.com/graph-gophers/graphql-go
Stars: ✭ 222 (+788%)
Mutual labels:  example, graphql-server
neo4j-graphql-py
A GraphQL to Cypher query execution layer for Neo4j and Python GraphQL implementations.
Stars: ✭ 14 (-44%)
Mutual labels:  graphql-query, graphql-server
Tensorflow Cifar 10
Cifar-10 CNN implementation using TensorFlow library with 20% error.
Stars: ✭ 85 (+240%)
Mutual labels:  model, example
graphql-spotify
GraphQL Schema And Resolvers For Spotify Web API
Stars: ✭ 55 (+120%)
Mutual labels:  resolver, graphql-server
play-java-ebean-example
Example Play application showing Java with Ebean
Stars: ✭ 54 (+116%)
Mutual labels:  example
tyshemo
A javascript runtime data type checking system and morden reactive state management model.
Stars: ✭ 70 (+180%)
Mutual labels:  model
hugo-bare-min-theme
A bare minimum theme for Hugo (https://gohugo.io) to help develop and debug Hugo sites -- https://hugo-bare-min.netlify.com/,
Stars: ✭ 71 (+184%)
Mutual labels:  example
learning-python
notes and codes while learning python
Stars: ✭ 71 (+184%)
Mutual labels:  example
dotobj
.obj/.mtl loader, written in native GML, for GameMaker Studio 2.3
Stars: ✭ 27 (+8%)
Mutual labels:  model
code-tour-rs
Enhanced example-based learning, i.e. awesome example user experience
Stars: ✭ 20 (-20%)
Mutual labels:  example
reinforcement learning financial trading
MATLAB example on how to use Reinforcement Learning for developing a financial trading model
Stars: ✭ 94 (+276%)
Mutual labels:  example
now-course
Proyecto para el curso de Now.sh en Platzi
Stars: ✭ 19 (-24%)
Mutual labels:  graphql-server
gd-obj
Obj file parser for Godot
Stars: ✭ 32 (+28%)
Mutual labels:  model
haxe
Qt binding for Haxe | Showcase example for https://github.com/therecipe/qt
Stars: ✭ 21 (-16%)
Mutual labels:  example
relay-compiler-plus
Custom relay compiler which supports persisted queries
Stars: ✭ 68 (+172%)
Mutual labels:  graphql-server
iOS ARkit2 Multiusers
An example implemented multiplayer experience in ARKit2
Stars: ✭ 19 (-24%)
Mutual labels:  example
api-examples
Plesk API-RPC usage examples
Stars: ✭ 79 (+216%)
Mutual labels:  example
aita dataset
AITA dataset based on r/AmItheAsshole/
Stars: ✭ 27 (+8%)
Mutual labels:  example

graphql-example

Intuitive GraphQL Resolver Example - Application example using RawModel.js as GraphQL rootValue on steroids.

GraphQL is a modern replacement for the well known REST API server. This is a pure GraphQL server application - an example API server.

Features

This example uses Node.js v7 and MongoDB.

  • GraphQL rootValue using RawModel.js.
  • Nested schema.
  • Print GraphQL schema from command-line.
  • Execute GraphQL schema from command-line.
  • Input data validation.
  • Context-aware models.
  • Graphql HTTP server.
  • MongoDB connector (an example how to use a database connector).

Pre-requisites

  • Make sure you are using Node.js v7+.
  • Install and start MongoDB server.

Build Setup

# install dependencies
npm install

# start the server (GraphiQL is started at http://127.0.0.1:3000)
npm start

# use nodemon in development to automatically reload the server on changes
npm install -g nodemon
nodemon --exec npm start

# run GraphQL query from command-line
npm run exec '{getUsers {id name}}'

# run tests
npm test

Run

npm start

Starts GraphiQL server at http://127.0.0.1:3000/

Query Examples

mutation { # create new user
  createUser(name: "") {
    id
    name
    errors {
      path
      errors {
      	validator
      	message
      	code
      }
    }
  }
}
query { # get users
  getUsers(skip: 0, limit: 5) {
    id
    name
  }
}

Architecture

|- /config    - config files
|- /scripts   - scripts that can be executed from CLI (used by `package.json`)
|- /src
  |- /graph`    - GraphQL application
  |- /http      - HTTP server
  |- /lib       - general helpers (e.g. Mongo DB connector)
  |- index.js   - application main file
- /tests        - tests written in [ava](https://github.com/avajs/ava) framework

The application exports two main classes - Graph (GraphQL application - src/http) and HTTP (HTTP server - src/graph). Each class represents a stand-alone application. You could create two separated npm packages from this to further split your code to responsibilities.

The scripts in the ./src/scripts folder use these classes to print GraphQL schema, execute GraphQL query and start the HTTP server from the command-line. These scripts are used by the package.json file thus you can use the npm run {script-name} commands.

Graph application describes your data model and provides a communication layer. HTTP application exposes GraphQL application over HTTP thus users can use the GraphQL application as your API endpoint.

The HTTP server is based on express-graphql which is a bridge to communicate with a GraphQL application via Express HTTP server. You could substitute this with koa-graphql or koa-graphql-next. The express-graphql middleware includes a GraphiQL user interface which is a generic interface for running GraphQL queries and mutations (for use in development).

Graph application exposes the API over the GraphQL schema defined in ./src/graph/schema/index.graphql. It uses the RawModel.js for describing and validating input data. To keep the example simple, we only have two models here where the Root model represents a GraphQL resolver - the rootValue for GraphQL.

GraphQL Clients

Your front-end application will need a GraphQL client to communicate with a GraphQL server. You can also use a raw browser's fetch to post data to the GraphQL server.

Popular GraphQL clients (you can add your own):

Tutorials

Node.js tutorials: Node.js Cheatsheet

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].