An open API service indexing awesome lists of open source software.

https://github.com/aooppo/graphql

graphql tool for java spring framework
https://github.com/aooppo/graphql

graphql graphql-ui java spring-framework-graphql tool

Last synced: about 1 month ago
JSON representation

graphql tool for java spring framework

Awesome Lists containing this project

README

          

![Travis (.org)](https://travis-ci.org/aooppo/graphql.svg?branch=master)


# Install
- add dependencies into pom.xml
``` xml

cc.voox
graphql
0.9.3

```

- add config into java bean
```java
import cc.voox.graphql.GraphqlProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(value = {"cc.voox.graphql"})
public class GraphQLConfig {
@Bean()
public GraphqlProperties graphqlProperties() {
GraphqlProperties graphqlProperties = new GraphqlProperties();
graphqlProperties.setScanPath("com.xxx");
return graphqlProperties;
}

}

```

# Usage
- define schema in classpath or custom schema path value (default value: schema.graphql)
```graphql
type Query {
test: String
}
type Book {
id: ID
name: String
pageCount: Int
}
```
#### define resolvers
- use @Query in entity class or method
- use @QueryMethod in method
- use @QueryField in parameter of method
```java
@Query
@Component
public class TestService {
@QueryMethod("bookById")
Map getBookById(@QueryField("id") String id) {
return books
.stream()
.filter(book -> book.get("id").equals(id))
.findFirst()
.orElse(null);
}
}
```

### define scalars
```java
class Currency implements IScalar {
}
```
### define directive
```java
class Lower implements IDirective {
}
```
### define dataloader
```java
class BookDatalodaer implements IDataloader {
}
```