Coder Social home page Coder Social logo

clickhouse-graphql-go's Introduction

clickhouse-graphql-go

Run Tests Go Reference Go Report Card

GraphQL implementation for clickhouse in Go. This package stores real time streaming websocket data in clickhouse and uses GraphQL to consume the same.

Installation

go get github.com/ranjanrak/clickhouse-graphql-go/v4

Usage

import (
    clickhousegraphqlgo "github.com/ranjanrak/clickhouse-graphql-go/v4"
)

// Create new graphql instance
client := clickhousegraphqlgo.New(clickhousegraphqlgo.ClientParam{
		DBSource:    "tcp://127.0.0.1:9000?debug=true",
		ApiKey:      "your_api_key",
		AccessToken: "your_access_token",
}))

// Dump tick websocket data to clickhouse
// Pass list of instrument token for subscription to websocket feeds
// Nothing will run after this
client.ClickhouseDump([]uint32{779521, 256265, 1893123, 13209858})

// Query
reqQuery := `query {
		Tick(instrument_token:779521) {
		  instrument_token
		  timestamp
		  lastprice
		  volumetraded
		  oi
		}
	}`

// Make single object schema graphql Query
singleQueryStruct, err := client.GraphqlQuery(reqQuery)
if err != nil {
  log.Fatalf("failed to execute single object graphql query, errors: %+v", err)
}
fmt.Printf("%+v\n", singleQueryStruct)

// Make list of object schema graphqlQuery
listQueryStruct, err := client.GraphqlQueryList(reqQuery)
if err != nil {
  log.Fatalf("failed to execute object list graphql query, errors: %+v", err)
}
fmt.Printf("%+v\n", listQueryStruct)

// Run graphql server on clickhouse with single schema
client.GraphqlServer("")

// Run graphql server to fetch list of object schema GraphQL
client.GraphqlServer("List")

GraphQL request query

1> GraphqlQuery(reqQuery)

reqQuery := `query {
		Tick(instrument_token:779521) {
		  instrument_token
		  timestamp
		  lastprice
		  volumetraded
		  oi
		}
	}`

2> GraphqlQueryList(reqQuery)

reqQuery := `query {
		Tick(instrument_token:779521) {
		  instrument_token
		  timestamp
		  lastprice
		  volumetraded
		  oi
		}
	}`

3> GraphqlServer("")


query {
  Tick(instrument_token:779521) {
    instrument_token
    timestamp
    lastprice
    volumetraded
    oi
  }
}

4> GraphqlServer("List")


query {
  Tick(instrument_token:779521) {
    instrument_token
    timestamp
    lastprice
    volumetraded
    oi
  }
}

Response

1> GraphqlQuery(reqQuery)

{Output:{InstrumentToken:779521 LastPrice:463.4 OI:0 Timestamp:2022-06-07 17:12:48 +0530 IST
VolumeTraded:7672515}}

2> GraphqlQueryList(reqQuery)

{Output:[{InstrumentToken:779521 LastPrice:463.4 OI:0 Timestamp:2022-06-07 17:12:48 +0530 IST
VolumeTraded:7672515}
{InstrumentToken:779521 LastPrice:463.4 OI:0 Timestamp:2022-06-07 17:12:48 +0530 IST
VolumeTraded:7672515}
{InstrumentToken:779521 LastPrice:463.4 OI:0 Timestamp:2022-06-07 17:12:48 +0530 IST
VolumeTraded:7672515}
....

3> GraphqlServer("")


{
  "data": {
    "Tick": {
    "instrument_token": 1893123,
    "lastprice": 74.245,
    "oi": 1990638,
    "timestamp": "2021-08-24T16:38:39+05:30",
    "volumetraded": 1099802
    }
  }
}

4> GraphqlServer("List")

{
  "data": {
    "Tick": [
    {
    "instrument_token": 779521,
    "lastprice": 412.65,
    "oi": 0,
    "timestamp": "2021-08-26T12:19:09+05:30",
    "volumetraded": 7619425
    },
    {
    "instrument_token": 779521,
    "lastprice": 412.65,
    "oi": 0,
    "timestamp": "2021-08-26T12:19:09+05:30",
    "volumetraded": 7619425
    },
    ......]
  }
}

Sample query on graphiQL UI

1> GraphqlServer("")

graphQL_dash

2> GraphqlServer("List")

graphQL_dash_list

clickhouse-graphql-go's People

Contributors

ranjanrak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

rahulmr

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.