davin2020 / graphql_core_questions_example

Example using Node and GraphQL to retrieve data from a MySQL database. Data is currently stored within an Array

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An example GraphQL API

Built with Node.JS, Express and the express-graphql package.

Install steps

  1. Firstly clone this repo locally
  2. Run npm install to install the project dependencies
  3. Run node index.js or nodemon index.js to start the application

You should then be able to access the GraphiQL UI by visting http://localhost:4004/graphql

Example Usage

Full documentation is generated by the GraphiQL UI which can be accessed by visting http://localhost:4000/graphql

Fetch all CoreQuestions

Query

query {
  questions {
    q_id
    question
    points_type
    possibleAnswers{
      scale_id
      label
      points
    }
  }
}

Response

{
  "data": {
    "questions": [
      {
        "q_id": 1,
        "question": "I have felt tense, anxious or nervous",
        "points_type": 123,
        "possibleAnswers": [
          {
            "scale_id": 10,
            "label": "Not all all",
            "points": 0
          },
          {
            "scale_id": 20,
            "label": "Only occasionally",
            "points": 1
          },
          {
            "scale_id": 30,
            "label": "Sometimes",
            "points": 2
          }
        ]
      },
      {
        "q_id": 2,
        "question": " I have felt I have someone to turn to for support when needed",
        "points_type": 321,
        "possibleAnswers": [
          {
            "scale_id": 10,
            "label": "Not all all",
            "points": 4
          },
          {
            "scale_id": 20,
            "label": "Only occasionally",
            "points": 3
          },
          {
            "scale_id": 30,
            "label": "Sometimes",
            "points": 2
          }
        ]
      }
    ]
  }
}

Available types/resources

Course

type CoreQuestion {
    q_id: Int
    question: String
    gp_order: Int
    points_type: Int
    points_id: Int
    possibleAnswers: [AnswerLabel]
}

AnswerLabel

type AnswerLabel {
    scale_id: Int
    label: String
    points: Int
}

About

Example using Node and GraphQL to retrieve data from a MySQL database. Data is currently stored within an Array


Languages

Language:JavaScript 100.0%