grapid-compiler

Translates GraphQL schema to Java source code

Лицензия

Лицензия

Группа

Группа

com.github.pukkaone
Идентификатор

Идентификатор

grapid-compiler
Последняя версия

Последняя версия

0.6.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

grapid-compiler
Translates GraphQL schema to Java source code
Ссылка на сайт

Ссылка на сайт

https://github.com/pukkaone/grapid
Система контроля версий

Система контроля версий

https://github.com/pukkaone/grapid

Скачать grapid-compiler

Как подключить последнюю версию

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

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
com.github.pukkaone : grapid-core jar 0.6.0

runtime (1)

Идентификатор библиотеки Тип Версия
com.squareup : javapoet jar 1.11.1

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0