New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@klevn/gql

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@klevn/gql

## Install ```npm i @klevn/gql```

4.0.0
latest
npm
Version published
Maintainers
1
Created
Source

GQL for dgraph

Install

npm i @klevn/gql

Example files

Test direcotry for working example ! Docker is needed to run npx dgraph-dedicated !

Server

import Client, { createServer } from "../gql"

const gql = new Client({
    url: "http://localhost:8080/graphql"
}, "./query.graphql")

// U can also use "gql.run" to run it without a server

createServer(gql, {
    socket: {
        server: 5499,
        options: {
            cors: {
                origin: "*"
            }
        }
    },

    routes: {
        "getUser": {
            global: false,
            queryOptions: {
                drill: ["getUser", "name"],
                resolve: ({data, variables}) => {
                    console.log(variables)
                    return data
                }
            }
        },

        "addUser": {
            global: false,
            queryOptions: {
                drill: ["addUser", "user", "name"]
            }
        }
    }
})

Client

import { io } from "https://cdn.socket.io/4.4.1/socket.io.esm.min.js";

const socket = io("http://10.0.0.9:5499")

socket.emit("getUser", {
    name: "hello",
    test: "world"
})

socket.on("getUser", (data) => {
    console.log(data)
})

schema.graphql

Use dgraph-dedicated to setup a database and schema

type User {
    name: String! @id
    age: Int!
}

query.graphql

query getUser($name: String!){
  getUser(name: $name) {
    name
  }
}

mutation addUser($name: String! $age: Int!){
  addUser(input: {
    name: $name
    age: $age
  }) {
    user {
      name
      age
    } 
  }
}

FAQs

Package last updated on 23 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts