Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/bitxon/java-spring-graphql


https://github.com/bitxon/java-spring-graphql

graphql spring

Last synced: 1 day ago
JSON representation

Awesome Lists containing this project

README

        

# GraphQL with Spring Boot

## Run application

Run application with test context (auto start postgress)

```shell
./gradlew bootTestRun
```

Note: if you want to run the application from your IDE\
Use `RunLocalApplication`

## Test application

Open [GraphiQL UI](http://localhost:8080/graphiql)

Get Employee By Id

```graphql
query GetEmployeeById($id: ID!) {
employee(id: $id) {
id
name
email
organization {
name
}
}
}
```
```json
{"id": "1"}
```

Get All Employees

```graphql
query GetAllEmployees {
employees {
id
name
email
organization {
name
}
}
}
```

Get Organization By Id

```graphql
query GetOrganizationById($id: ID!) {
organization(id: $id) {
id
name
employees {
name
}
}
}
```
```json
{"id": "1"}
```

Get All Organizations With Pagination

```graphql
query GetAllOrganizations($first: Int, $after: String, $last: Int, $before: String) {
organizations(first: $first, after: $after, last: $last, before: $before) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
id
name
employees {
name
}
}
}
}
}
```
```json
{"first": 5}
```


Create Employee

```graphql
mutation CreateEmployee($name: String!, $email: String!, $organizationId: Int!) {
createEmployee(employee: { name: $name, email: $email, organizationId: $organizationId}) {
id
name
email
}
}
```
```json
{
"name": "John Doe",
"email": "[email protected]",
"organizationId": 3
}
```

Create Organization

```graphql
mutation CreateOrganization($name: String!) {
createOrganization(name: $name) {
id
name
}
}
```
```json
{"name": "Organization Test Name"}
```