All Projects → leangen → Graphql Spqr

leangen / Graphql Spqr

Licence: apache-2.0
Java 8+ API for rapid development of GraphQL services

Programming Languages

68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Graphql Spqr

Graphql Spqr Spring Boot Starter
Spring Boot 2 starter powered by GraphQL SPQR
Stars: ✭ 187 (-77.82%)
Mutual labels:  graphql, graphql-server, graphql-api
A Clojure & JVM library for developing GraphQL API instantly from Postgres and MySQL databases
Stars: ✭ 240 (-71.53%)
Mutual labels:  graphql, graphql-server, graphql-api
A Node.js framework for creating GraphQL API servers easily and without a lot of boilerplate.
Stars: ✭ 194 (-76.99%)
Mutual labels:  graphql, graphql-server, graphql-api
Graphql Engine
Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
Stars: ✭ 24,845 (+2847.21%)
Mutual labels:  graphql, graphql-server, graphql-api
Parse Server
API server module for Node/Express
Stars: ✭ 19,165 (+2173.43%)
Mutual labels:  graphql, graphql-server, graphql-api
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (-78.53%)
Mutual labels:  graphql, graphql-server, graphql-api
36 Graphql Concepts
📜 36 concepts every GraphQL developer should know.
Stars: ✭ 209 (-75.21%)
Mutual labels:  graphql, graphql-server, graphql-api
Graphql Stack
A visual explanation of how the various tools in the GraphQL ecosystem fit together.
Stars: ✭ 117 (-86.12%)
Mutual labels:  graphql, graphql-server, graphql-api
A GraphQL Framework for Node.js
Stars: ✭ 358 (-57.53%)
Mutual labels:  graphql, graphql-server, graphql-api
Morpheus Graphql
Haskell GraphQL Api, Client and Tools
Stars: ✭ 285 (-66.19%)
Mutual labels:  graphql, graphql-server, graphql-api
Storefront Api
Storefront GraphQL API Gateway. Modular architecture. ElasticSearch included. Works great with Magento1, Magento2, Spree, OpenCart, Pimcore and custom backends
Stars: ✭ 180 (-78.65%)
Mutual labels:  graphql, graphql-server, graphql-api
Api Platform
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Stars: ✭ 7,144 (+747.45%)
Mutual labels:  graphql, graphql-server, graphql-api
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder
Stars: ✭ 160 (-81.02%)
Mutual labels:  graphql, graphql-server, graphql-api
[NOT MAINTAINED]An API integration framework using GraphQL
Stars: ✭ 182 (-78.41%)
Mutual labels:  graphql, graphql-server, graphql-api
Hangzhou Graphql Party
杭州 GraphQLParty 往期记录(slide,照片,预告,视频等)
Stars: ✭ 142 (-83.16%)
Mutual labels:  graphql, graphql-server, graphql-api
Rails Devise Graphql
A Rails 6 boilerplate to create your next Saas product. Preloaded with graphQL, devise, JWT, CanCanCan, RailsAdmin, Rubocop, Rspec, i18n and more.
Stars: ✭ 199 (-76.39%)
Mutual labels:  graphql, graphql-server, graphql-api
Haskell GraphQL implementation
Stars: ✭ 36 (-95.73%)
Mutual labels:  graphql, graphql-server, graphql-api
Daptin - Backend As A Service - GraphQL/JSON-API Headless CMS
Stars: ✭ 1,195 (+41.76%)
Mutual labels:  graphql, graphql-server, graphql-api
Wp Graphql
🚀 GraphQL API for WordPress
Stars: ✭ 3,097 (+267.38%)
Mutual labels:  graphql, graphql-server, graphql-api
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (-50.77%)
Mutual labels:  graphql, graphql-server, graphql-api


GraphQL SPQR (GraphQL Schema Publisher & Query Resolver, pronounced like speaker) is a simple-to-use library for rapid development of GraphQL APIs in Java.

Join the chat at StackOverflow Maven Central Javadoc Build Status License


GraphQL SPQR aims to make it dead simple to add a GraphQL API to any Java project. It works by dynamically generating a GraphQL schema from Java code.

  • Requires minimal setup (~3 lines of code)
  • Deeply configurable and extensible (not opinionated)
  • Allows rapid prototyping and iteration (no boilerplate)
  • Easily used in legacy projects with no changes to the existing code base
  • Has very few dependencies

Code-first approach

When developing GraphQL-enabled applications it is common to define the schema first and hook up the business logic later. This is known as the schema-first style. While it has its advantages, in strongly and statically typed languages, like Java, it leads to a lot of duplication.

For example, a schema definition of a simple GraphQL type could like this:

type Link {
    id: ID!
    url: String!
    description: String

and, commonly, a corresponding Java type would exist in the system, similar to the following:

public class Link {
    private final String id;
    private final String url;
    private final String description;
    //constructors, getters and setters

Both of these blocks contain the exact same information. Worse yet, changing one requires an immediate change to the other. This makes refactoring risky and cumbersome, and the compiler can not help. On the other hand, if you’re trying to introduce a GraphQL API into an existing project, writing the schema practically means re-describing the entire existing model. This is both expensive and error-prone, and still suffers from duplication and lack of tooling.

Instead, GraphQL SPQR takes the code-first approach, by generating the schema from the existing model. This keeps the schema and the model in sync, easing refactoring. It also works well in projects where GraphQL is introduced on top of an existing codebase.

Still schema-first

Note that developing in the code-first style is still effectively schema-first, the difference is that you develop your schema not in yet another language, but in Java, with your IDE, the compiler and all your tools helping you. Breaking changes to the schema mean the compilation will fail. No need for linters or other fragile hacks.


GraphQL SPQR is deployed to Maven Central.




compile 'io.leangen.graphql:spqr:0.11.1'

Hello world

The example will use annotations provided by GraphQL SPQR itself, but these are optional and the mapping is completely configurable, enabling existing services to be exposed through GraphQL without modification.

Service class:

class UserService {

    @GraphQLQuery(name = "user")
    public User getById(@GraphQLArgument(name = "id") Integer id) {

If you want to skip adding @GraphQLArgument, compile with the -parameters option or the names will be lost.

Domain class:

public class User {

    private String name;
    private Integer id;
    private Date registrationDate;

    @GraphQLQuery(name = "name", description = "A person's name")
    public String getName() {
        return name;

    public Integer getId() {
        return id;

    @GraphQLQuery(name = "regDate", description = "Date of registration")
    public Date getRegistrationDate() {
        return registrationDate;

To attach additional fields to the User GraphQL type, without modifyning the User class, you simply add a query that has User as the context. The simplest way is using the @GraphQLContext annotation:

class UserService {

    ... //regular queries, as above

    // Attach a new field called twitterProfile to the User GraphQL type
    public TwitterProfile twitterProfile(@GraphQLContext User user) {

Exposing the service with graphql-spqr:

UserService userService = new UserService(); //instantiate the service (or inject by Spring or another framework)
GraphQLSchema schema = new GraphQLSchemaGenerator()
    .withBasePackages("io.leangen") //not mandatory but strongly recommended to set your "root" packages
    .withOperationsFromSingleton(userService) //register the service
    .generate(); //done ;)
GraphQL graphQL = new GraphQL.Builder(schema)

//keep the reference to GraphQL instance and execute queries against it.
//this operation selects a user by ID and requests name, regDate and twitterProfile fields only
ExecutionResult result = graphQL.execute(   
    "{ user (id: 123) {
         twitterProfile {

Spring Boot Starter

We're working on a SPQR-powered Spring Boot starter. The project is still very young, but already functional.

Full example

See more complete examples using Spring Boot at

Full tutorial

Coming soon

Known issues


For best compatibility, Kotlin 1.3.70 or later is needed with the compiler argument -Xemit-jvm-type-annotations. This instructs the Kotlin compiler to produce type-use annotations (introduced in JDK8) correctly. See KT-35843 and KT-13228 for details.


There's a bug in OpenJDK's annotation parser before version 16 b17 that causes annotations on generic type parameters to be duplicated. You may experience this in a form of a mysterious

AnnotationFormatError: Duplicate annotation for class: interface io.leangen.graphql.annotations.GraphQLNonNull

being thrown when using @GraphQLNonNull both on a type and on its generic parameters e.g. @GraphQLNonNull List<@GraphQLNonNull Item>.

Fortunately, very few users seem to experience this problem, even on affected JDKs. Do note it is only relevant which Java compiles the sources, not which Java runs the code. Also note that IntelliJ IDEA comes bundled with a JDK of its own, so building the project in IDEA may lead to this error. You should configure your IDE to use the system Java if it is different.

Asking questions

  • Issues Open an issue to report bugs, request features or ask questions
  • StackOverflow Use graphql-spqr tag
  • Gitter For questions/discussions you don't care to keep for posterity
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].