GithubHelp home page GithubHelp logo

karic-kenan / hadesql Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 81 KB

HadesQL is backend written in Kotlin using Ktor and GraphQL. Main purpose is to demonstrate simple CRUD operations using GraphQL

License: Apache License 2.0

Kotlin 100.00%
kotlin coroutines ktor backend koin postgresql hikaricp h2-database graphql exposed gson kgraphql

hadesql's Introduction

HadesQL

HadesQL is backend written using Ktor and GraphQL. It's purpose is to demonstrate basic usages of CRUD operations on InMemory database / H2 database while using GraphQL. It can be used as standalone, or in conjunction with Hades backend which provides more functionality.

Install

Clone the project and run it. Simple as that.

By default it uses H2 database while working with Exposed to store data, but if you prefer to use InMemory one then in framework package, under di, use single<MainRepository> { InMemoryRepository() } instead of single<MainRepository> { DefaultMainRepository() } in RepositoriesModule.

Built with

  • Kotlin - Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference.
  • Ktor - Ktor is an asynchronous framework for creating microservices, web applications, etc.
  • Coroutines - For asynchronous and more..
  • Dependency Injection -
    • Koin - A pragmatic lightweight dependency injection framework for Kotlin developers.
  • Exposed - Exposed is a lightweight SQL library on top of JDBC driver for Kotlin language.
  • Gson - Content negotiation which provides Gson converter for handling JSON data.
  • KGraphQL - KGraphQL is a Kotlin implementation of GraphQL.

Playground

Once HadesQL is running you can work with it using Playground (default port is 8080, change it according to yours).

HadesQL provides basic CRUD operations and we'll go over their usage bellow (Playground will by itself provide autocomplete for methods and fields).

Get thougts

In playground, to get all thoughts, write your query like so:

query {
  getThoughts {
    id, title, content, date
  }
}

This will query for all thoughts and each thought will have 4 items. If you only want, lets say title, then just keep title instead of id, title, content, date.

Get thought

In playground, to get single thought, write your query like so:

query {
  getThought(id: "your_thought_id") {
    content
  }
}

This query will fetch thought based on its ID, but will only fetch content for that thought. If you need more fields, such as title, expand the query to contain title and content

Create thought

In playground, to create new thought, write your mutation like so:

mutation createThought($draft: ThoughtDraft!) {
  create(draft: $draft) {
    title, content
  }
}

and on the bottom of the screen, click on Query Variables and in it add following:

{
  "draft": {
    "title": "thought_title",
    "content": "thought_content"
  }
}

In this case, to create thought we need two items: title and content. ID and date will be automatically created. That's why we store Thought (which has all 4 items) but to create thought we use ThoughtDraft (which has two items).

Mutation will will accept draft of type ThoughtDraft and it'll be passed into create method. Since our mutation has return value (in this case we return Thought), we return it but also only fetch title and content of newly created thought.

Draft in Query Variables is thought data, defining the values for the draft of thought we're creating, and that draft will be injected into createThought mutation (names must match)

Update thought

In playground, to update single thought, write your mutation like so:

mutation {
  updateThought(
    id: "your_thought_id"
    title: "thought_title"
    content: "thought_content"
  )
}

Our mutation has slighly different approach here (for learning purposes). Here we directly pass in variables we need in order to update single thought. In this case we use ID to find thought if one exists, and then update it's title and content. This is to show that we can pass in data classes, but also individual fields.

Delete thought

In playground, to delete single thought, write your mutation like so:

mutation {
  removeThought(id: "your_thought_id")
}

Simple mutation which calls corresponding method (playground will have autocomplete for such things) and we pass in ID of thought we want to delete.

Contribute

If you want to contribute to this repository, you're always welcome!

Contact

If you need any help, feel free to contact me: [email protected].

License

License

hadesql's People

Contributors

karic-kenan avatar

Watchers

 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.