grapid-web-spring-boot-starter

GraphQL synchronous server Spring Boot starter

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

com.github.pukkaone
ArtifactId

ArtifactId

grapid-web-spring-boot-starter
Last Version

Last Version

0.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

grapid-web-spring-boot-starter
GraphQL synchronous server Spring Boot starter
Project URL

Project URL

https://github.com/pukkaone/grapid
Source Code Management

Source Code Management

https://github.com/pukkaone/grapid

Download grapid-web-spring-boot-starter

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.pukkaone/grapid-web-spring-boot-starter/ -->
<dependency>
    <groupId>com.github.pukkaone</groupId>
    <artifactId>grapid-web-spring-boot-starter</artifactId>
    <version>0.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.pukkaone/grapid-web-spring-boot-starter/
implementation 'com.github.pukkaone:grapid-web-spring-boot-starter:0.6.0'
// https://jarcasting.com/artifacts/com.github.pukkaone/grapid-web-spring-boot-starter/
implementation ("com.github.pukkaone:grapid-web-spring-boot-starter:0.6.0")
'com.github.pukkaone:grapid-web-spring-boot-starter:jar:0.6.0'
<dependency org="com.github.pukkaone" name="grapid-web-spring-boot-starter" rev="0.6.0">
  <artifact name="grapid-web-spring-boot-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.pukkaone', module='grapid-web-spring-boot-starter', version='0.6.0')
)
libraryDependencies += "com.github.pukkaone" % "grapid-web-spring-boot-starter" % "0.6.0"
[com.github.pukkaone/grapid-web-spring-boot-starter "0.6.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.github.pukkaone : grapid-core jar 0.6.0
org.springframework.boot : spring-boot-starter-web jar 2.3.9.RELEASE

Project Modules

There are no modules declared in this project.

Grapid  Maven Central

Grapid is an opinionated, schema-first framework for implementing GraphQL servers in Java. While the framework prescribes where you put GraphQL schema definition files and Java classes, you only need to implement the business logic for your API. The framework generates the code to wire GraphQL requests to your business logic.

GraphQL Server Quick Start Guide

Add this Spring Boot starter which auto-configures a GraphQL server accepting requests by HTTP. By default, the server URL path is /graphql relative to the context path.

<dependency>
  <groupId>com.github.pukkaone</groupId>
  <artifactId>grapid-web-spring-boot-starter</artifactId>
  <version>${grapid.version}</version>
</dependency>

Add this Maven plugin which compiles GraphQL schema definition files to Java source files.

<plugin>
  <groupId>com.github.pukkaone</groupId>
  <artifactId>grapid-maven-plugin</artifactId>
  <version>${grapid.version}</version>
  <configuration>
    <!-- The compiler generates Java classes under this Java package. -->
    <packagePrefix>com.example.graphql</packagePrefix>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>

An API version represents a set of types and operations defined by a GraphQL schema. A version identifier must be a valid Java identifier and not a Java keyword.

By convention, GraphQL schema definition files are located under a resources directory src/main/resources/graphql/version/ where version identifies an API version. Create the resources directory src/main/resources/graphql/v2018_12_31/. Add this GraphQL schema definition file in the directory. By convention, GraphQL schema definition file names end with the extension .graphql.

Author.graphql
type Author {
  id: ID!
  name: String!
}

type Query {
  author(id: ID!): Author
}

The GraphQL schema defines the root object type Query. The compiler appends the suffix Resolver to this root object type name to derive the Java class name QueryResolver. As an application developer, you must implement the QueryResolver class. By convention, this class is in the Java package named packagePrefix.resolver.

QueryResolver.java
package com.example.graphql.resolver;

import com.example.graphql.v2018_12_31.type.Author; // (1)
import org.springframework.stereotype.Component;

@Component
public class QueryResolver {

  public Author author(String id) { // (2)
    return Author.builder()
        .id(id)
        .name("NAME")
        .build();
  }
}
  1. The compiler generated the simple Java data class Author from the GraphQL object type Author.

  2. The compiler translated this Java method signature from the field author of the GraphQL root object type Query.

Run the application. In GraphQL Playground, connect to http://localhost:8080/graphql/v2018_12_31 to send a GraphQL query to the server.

For more details, see the Getting Started Guide.

Interface Stability

Major version zero (0.x.x) is for initial development. Anything may change at any time. The public API should not be considered stable.

Building

Prerequisites are:

  • Java 11

  • Gradle

To compile the project and run integration tests:

gradle publishToMavenLocal check

Versions

Version
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0