All Projects → Jotschi → vertx-graphql-example

Jotschi / vertx-graphql-example

Licence: other
Vert.x Server which exposes a GraphQL API

Programming Languages

javascript
184084 projects - #8 most used programming language
java
68154 projects - #9 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to vertx-graphql-example

IntroduceToEclicpseVert.x
This repository contains the code of Vert.x examples contained in my articles published on platforms such as kodcu.com, medium, dzone. How to run each example is described in its readme file.
Stars: ✭ 27 (-6.9%)
Mutual labels:  vertx, vertx-web
grooveex
Extension module for vertx-groovy adding methods and syntaxic sugar
Stars: ✭ 14 (-51.72%)
Mutual labels:  vertx, vertx-web
throo
A Vert.x/Spring based HTTP reverse-proxy
Stars: ✭ 19 (-34.48%)
Mutual labels:  vertx, vertx-web
Blog
📚 Github static blog post, experience the fun of using Issues.Welcome star( 静态博客文章,体验一下使用 Issues 的乐趣,欢迎 star )个人博客地址:blog.hvkcoder.me/love
Stars: ✭ 230 (+693.1%)
Mutual labels:  vertx
coronamq
The simplest way to implement a task queue with Java, Vertx and PostgreSQL.
Stars: ✭ 23 (-20.69%)
Mutual labels:  vertx
Sqlfiddle3
New version based on vert.x and docker
Stars: ✭ 242 (+734.48%)
Mutual labels:  vertx
openapi4j
OpenAPI 3 parser, JSON schema and request validator.
Stars: ✭ 92 (+217.24%)
Mutual labels:  vertx
Cloudopt Next
A simple and modern Java and Kotlin vert.x web framework
Stars: ✭ 211 (+627.59%)
Mutual labels:  vertx
spring-webflux-research
spring webflux research
Stars: ✭ 42 (+44.83%)
Mutual labels:  vertx
ethereum-ingest
JavaFX and commandline application to import events from the Ethereum blockchain into ElasticSearch, MongoDB, Hazelcast, CQEngine and SQLite.
Stars: ✭ 34 (+17.24%)
Mutual labels:  vertx
spring-graphql-sample
Spring GraphQL examples using Netflix DGS, GraphQL Java and Spring GraphQL
Stars: ✭ 67 (+131.03%)
Mutual labels:  graphql-java
Quintessential-Tasklist-Zeebe
The quintessential Zeebe tasklist for BPMN Human tasks with Drag and Drop Form builder, client and server side validations, and drop in Form Rendering
Stars: ✭ 34 (+17.24%)
Mutual labels:  vertx
smallrye-mutiny-vertx-bindings
Smallrye Mutiny bindings for Eclipse Vert.x
Stars: ✭ 65 (+124.14%)
Mutual labels:  vertx
elasticsearch-client
This client exposes the Elasticsearch Java High Level REST Client for Eclipse Vert.x applications.
Stars: ✭ 40 (+37.93%)
Mutual labels:  vertx
vertx-start
简单地、快速地启动vert.x的手脚架,保留了vert.x原汁原味的开发方式
Stars: ✭ 102 (+251.72%)
Mutual labels:  vertx
Chime
Time scheduler for Vert.x
Stars: ✭ 28 (-3.45%)
Mutual labels:  vertx
Vertx Lang Kotlin
Vert.x for Kotlin
Stars: ✭ 215 (+641.38%)
Mutual labels:  vertx
vertx-ddns
基于 Vert.x 的 DDNS 解决方案。自动更新域名解析到本机IP, 支持的DNS服务商: Alidns(阿里云) 、 Dnspod(腾讯云) 、Cloudflare、华为云
Stars: ✭ 126 (+334.48%)
Mutual labels:  vertx
Zeko-SQL-Builder
Zeko SQL Builder is a high-performance lightweight SQL query library written for Kotlin language
Stars: ✭ 87 (+200%)
Mutual labels:  vertx
Websockets-Vertx-Flink-Kafka
A simple request response cycle using Websockets, Eclipse Vert-x server, Apache Kafka, Apache Flink.
Stars: ✭ 14 (-51.72%)
Mutual labels:  vertx

Vert.x GraphQL Example

This example shows how to build a basic GraphQL endpoint using Vert.x and OrientDB

Getting Started

  • Clone example project
git clone [email protected]:jotschi/vertx-graphql-example.git
cd vertx-graphql-example

Motivation

I recently added GraphQL support to Gentics Mesh and I thought it would be a good idea to boil down the essence of my implementation in example so that I could share it in a simpler form. This example will not cover all aspects that I have added to the Gentics Mesh API (e.g. paging, search and error handling) but it will give you a basic overview of the parts that I put together. GraphQL does not require a GraphDB even if the name might suggest it. Using a graphdb in combination with GraphQL does nevertheless provide you with some advantages which I will highlight later on.

Why StarWars?

Most graphql examples which I found make use of that domain model. I adoped the graphql-java demo schema and added some values.

Contents

GraphiQL browser

The GraphiQL browser is served via a StaticHandler. No further configuration is needed.

Data setup

The StarWarsData class contains the demo data. The demo data is structured in a very simple graph. A central root element is used to reference the aggregation vertices which list all the basic elements (humans, droids, planets, movies). Additional edges exist between those elements.

This example does not use SQL to interface with the GraphDB. Instead it uses makes use of the Object Graph Mapper library Ferma 3.x. This library allowed me to create basic Java classes which map to the vertices which I later use within my Graph. Ferma helps a lot if you plan to setup your graph domain model. Using a tinkerpop based native API is in most cases the fastest way to interact with the GraphDB. OrientDB nativly supports this API and thus the overall overhead is minimal compared to SQL.

GraphQL schema

The GraphQL schema defines which fields and objects can be resolved via a query. I use graphql-java to setup the schema and process the query.

The StarWarsSchema class contains all schema fields and object definitions. Any field may define a data fetcher which is used to access the graph database and load the needed data. Data fetchers can access the the graphql query context (in our case the StarWarsRoot vertex) and a source element. The context will not change if you access nested elements but the source element can change. This is very useful since you can just pass along a vertex. This vertex can be processed by another data fetcher and related vertices, edges or a single vertex can be returned. You can create a very fast and efficient API if you model your graph relationships in a way that it matches up closely to your graphql schema.

Executing queries

The GraphQLVerticle contains the whole query execution logic.

The query is wrapped in an JSON string and thus needs to unwrapped first.

The handleQuery method processes the query. It is important to note that the query has a starting point. In our case this is the root vertex.

ExecutionInput input = new ExecutionInput(query, null, queryJson, demoData.getRoot(), extractVariables(queryJson));
tx.complete(graphQL.execute(input));

All GraphQL schema data fetchers can access this root vertex and use it as a starting point for the graph traversals.

Testing GraphQL

There are many ways to test a GraphQL API. You could write unit tests which individually test each graphql type or just test the data fetchers. I often opt for tests which cover a big portion of application stack. Those tests have the advantage that they have the potential to uncover bugs which reside in the areas between application parts. The downside is that they often take much longer to execute.

The GraphQLTest which is part of the example loads a predefined GraphQL query and executes it by posting it to the graphql endpoint. The graphQL query also contains special comments which are parsed. These parsed comments are used to perform assertions against the response query.

{
    vader: human(id: 1001) {
		# [$.data.vader.name=Darth Vader]
		name
    }
}

The comment contains a basic json-path and expected value for that path.

Whats next? What did you not cover?

  • I have not covered mutation support. (GraphQL write operations).
  • I did not cover async graphql execution. It may be desireable to execute parts of the graphql query in-parallel to speedup processing.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].