Giter Site home page Giter Site logo

graphql-server-demo's Introduction

GraphQL-Server-Demo

中文文档

GraphQL-Server-Demo is a typical example of starting a GraphQL Server with node.js. It is an easy and readable project to learn and understand GraphQL.

Screenshots

Query

Mutation

Structure

GraphQL-Server-Demo
├── README.md
├── LICENSE
├── .babelrc
├── .gitignore
├── package.json
├── yarn.lock
├── dev.sqlite
├── app.js
├── schemas
│   └── index.js
├── resolvers
│   ├── userResolver.js
│   ├── messageResolver.js
│   └── ...
└── types
    ├── query.js
    ├── mutation.js
    ├── queries
    │    ├── userType.js
    │    ├── messageType.js
    │    └── ... 
    └── mutations
         ├── userInputType.js
         ├── messageInputType.js
         └── ... 
  • app.js -- server engine of this project
  • dev.sqlite -- test database
  • schemas -- basic schema to create the GraphQLSchema, contanins the basic queryType and mutationType
  • types -- all the GraphQLObjectType that user defined
  • resolvers -- all the resolvers to resolve the Type data

Quick Start

Excute the commands below:

git clone [email protected]:LanceGin/GraphQL-Server-Demo.git
cd GraphQL-Server-Demo
yarn && yarn start

Open the url http://localhost:4000/graphql, you will see the GraphiQL GUI in the window, and you can excute the example query and mution operations.

Query Operation

Request

query {
  user(id: 1) {
    name
    nickname
    message {
      id
      content
    }
  }
}

Response

{
  "data": {
    "user": [
      {
        "name": "gin",
        "nickname": "lancegin",
        "message": [
          {
            "id": "1",
            "content": "test message"
          },
          {
            "id": "2",
            "content": "hello"
          },
          {
            "id": "3",
            "content": "world"
          }
        ]
      }
    ]
  }
}

Mutation Operation

Request

mutation {
  createMessage(input: {user_id: "1", content: "hello world111"}) {
    id
    content
  }
}

Response

{
  "data": {
    "createMessage": {
      "id": "10",
      "content": "hello world111"
    }
  }
}

graphql-server-demo's People

Contributors

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