DEV Community

lucasnscr
lucasnscr

Posted on

Implementing GraphQL with Quarkus

Project description

🚀 This project aims to create an application with Quarkus and GraphQL.

Here is the complete code of the project

Technologies

The following technologies were used to carry out the project and it is necessary to install some items:

  • Java
  • Docker
  • Maven
  • Quarkus
  • GraphQL

Quarkus

Quarkus is a native Java framework in Kubernetes, it was developed for Java virtual machines (JVMs) and native compilation. It optimizes this language specifically for containers, making this technology an effective platform for serverless, cloud, and Kubernetes environments.

Features of Quarkus

  • Container first(Fast startup, low memory consumption and work with small images or containers)
  • Low memory consumption
  • Fast Startup

For Containers

Whether the application resides in the public cloud or on an internally hosted Kubernetes cluster, features such as fast startup and low memory consumption are important to keep overall hosting costs down.
Quarkus was built on the philosophy of container prioritization. This means it is optimized for reduced memory usage and faster boot times in the following ways:

  • Advanced Graal/SubstrateVM Compatibility
  • Compile-time metadata processing
  • Reduction in the use of reflection
  • Preboot native images

GraphQL

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

GraphQL can be divided into some parts which are: Schema, Query and Mutations.

Schema

A Schema is the heart of the protocol. It represents the functionality available, it represents a contract where objects, composition of objects and data type are represented. Below is an example definition of Schema.

type Movie {
    id:ID
    name: String
    year: Int
}
Enter fullscreen mode Exit fullscreen mode

Query

Query is used to define the data query contract. Its functionality is comparable to the GET verb of REST APIs. Below you can see an example of the type Query.

type Query {
    getMovie(id: ID!): Movie
}
Enter fullscreen mode Exit fullscreen mode

Mutations

Mutation is used to define the data manipulation contract. Its functionality is comparable to that of the POST, PUT, PATCH and DELETE verbs of REST APIs. Below you can see an example of the type Mutation:

type Mutation {
    addMovie(movie: StudyInput!): Study
}
Enter fullscreen mode Exit fullscreen mode

Details this project

To run GraphQL in the project follow the information below

Endpoint: http://localhost:8080/q/graphql-ui/

UI for GraphQL Api

You will use below Json to run command to create data:

mutation CREATE {
      createBank(bank:
        {
        name: "GraphQL Bank", country:"USA"}) {
        id
        name
        country
        }
    }
Enter fullscreen mode Exit fullscreen mode

Now you will use the json to query the data entered in the previous json

{
  banks{
   id
   name
   country
  }
}
Enter fullscreen mode Exit fullscreen mode

Here we finish a Project implementing GraphQL with Quarkus.

Top comments (0)