Skip to content

Commit

Permalink
Merge pull request #118 from cybozu-go/improve-graphql
Browse files Browse the repository at this point in the history
Improve GraphQL implementation
  • Loading branch information
dulltz authored Nov 27, 2018
2 parents c54a164 + bf91d56 commit 14c4f6f
Show file tree
Hide file tree
Showing 14 changed files with 402 additions and 286 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- GraphQL API and playground (#117)
- `spec.register-date` and `spec.retire-date` fields to `Machine` (#116).
- REST API to edit `retire-date` (#116).
- `status.duration` field to `Machine` (#116).

### Changed
- Update etcdutil to 1.3.1.

## [0.24] - 2018-10-25

### Changed
Expand Down
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
REST API
========

For GraphQL API, see [graphql.md](graphql.md).

* [PUT /api/v1/config/ipam](#putipam)
* [GET /api/v1/config/ipam](#getipam)
* [PUT /api/v1/config/dhcp](#putdhcp)
Expand Down
95 changes: 94 additions & 1 deletion docs/graphql.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,102 @@
GraphQL API
===========

Sabakan provides GraphQL API at `/graphql` HTTP endpoint.
Sabakan provides [GraphQL][] API at `/graphql` HTTP endpoint.

Schema
------

See [gql/schema.graphql](../gql/schema.graphql).

Playground
----------

If [sabakan](sabakan.md) starts with `-enable-playground` command-line flag,
it serves a web-based playground for GraphQL API at `/playground` HTTP endpoint.

Example
-------

Searching machines matching the these conditions:

* the machine has a label whose key is "datacenter" and value is "dc1".
* the machine's current state is _healthy_.
* the machine is not in rack 1.

can be done with a GraphQL query and variables as follows:

### Query

```
query search($having: MachineParams = null, $notHaving: MachineParams = null) {
searchMachines(having: $having, notHaving: $notHaving) {
spec {
serial
labels {
name
value
}
ipv4
rack
}
status {
state
timestamp
duration
}
}
}
```

### Variables

```json
{
"having": {
"labels": [
{"name": "datacenter", "value": "dc1"}
],
"states": ["HEALTHY"]
},
"notHaving": {
"racks": [1]
}
}
```

### Result

```json
{
"data": {
"searchMachines": [
{
"spec": {
"serial": "00000004",
"labels": [
{
"name": "datacenter",
"value": "dc1"
},
{
"name": "product",
"value": "vm"
}
],
"ipv4": [
"10.0.0.104"
],
"rack": 0
},
"status": {
"state": "HEALTHY",
"timestamp": "2018-11-26T09:17:20Z",
"duration": 21678.990289
}
}
]
}
}
```

[GraphQL]: https://graphql.org/
47 changes: 14 additions & 33 deletions docs/sabakan.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sabakan
Usage
-----

See [specification of etcdutil](https://github.com/cybozu-go/etcdutil/blob/master/README.md#specifications) for etcd connection flags and parameters.

```console
$ sabakan -h
Usage of sabakan:
Expand All @@ -17,22 +19,8 @@ Usage of sabakan:
directory to store files (default "/var/lib/sabakan")
-dhcp-bind string
bound ip addresses and port for dhcp server (default "0.0.0.0:10067")
-etcd-endpoints string
comma-separated URLs of the backend etcd endpoints (default "http://localhost:2379")
-etcd-password string
password for etcd authentication
-etcd-prefix string
etcd prefix (default "/sabakan/")
-etcd-timeout string
dial timeout to etcd (default "2s")
-etcd-tls-ca string
path to CA bundle used to verify certificates of etcd servers
-etcd-tls-cert string
path to my certificate used to identify myself to etcd servers
-etcd-tls-key string
path to my key used to identify myself to etcd servers
-etcd-username string
username for etcd authentication
-enable-playground
enable GraphQL playground
-http string
<Listen IP>:<Port number> (default "0.0.0.0:10080")
-ipxe-efi-path string
Expand All @@ -45,23 +33,16 @@ Usage of sabakan:
Log level [critical,error,warning,info,debug]
```

Option | Default value | Description
------ | ------------- | -----------
`advertise-url` | "" | Public URL to access this server. Required.
`allow-ips` | `127.0.0.1,::1` | comma-separated IPs allowed to change resources
`config-file` | "" | If given, configurations are read from the file.
`data-dir` | `/var/lib/sabakan` | Directory to store files.
`dhcp-bind` | `0.0.0.0:10067` | bound ip addresses and port dhcp server
`etcd-endpoints` | `http://127.0.0.1:2379, http://127.0.0.1:4001` | comma-separated URLs of the backend etcd
`etcd-password` | "" | password for etcd authentication
`etcd-prefix` | `/sabakan` | etcd prefix
`etcd-timeout` | `2s` | dial timeout to etcd
`etcd-tls-ca` | "" | Path to CA bundle used to verify certificates of etcd endpoints.
`etcd-tls-cert` | "" | Path to my certificate used to identify myself to etcd servers.
`etcd-tls-key` | "" | Path to my key used to identify myself to etcd servers.
`etcd-username` | "" | username for etcd authentication
`http` | `0.0.0.0:10080` | Listen IP:Port number
`ipxe-efi-path` | `/usr/lib/ipxe/ipxe.efi` | path to ipxe.efi
Option | Default value | Description
------------------- | ------------------------ | -----------
`advertise-url` | "" | Public URL to access this server. Required.
`allow-ips` | `127.0.0.1,::1` | Comma-separated IPs allowed to change resources.
`config-file` | "" | If given, configurations are read from the file.
`data-dir` | `/var/lib/sabakan` | Directory to store files.
`dhcp-bind` | `0.0.0.0:10067` | IP address and port number of DHCP server.
`enable-playground` | false | Enable GraphQL playground service.
`http` | `0.0.0.0:10080` | IP address and port number of HTTP server.
`ipxe-efi-path` | `/usr/lib/ipxe/ipxe.efi` | Path to ipxe.efi .

Config file
-----------
Expand Down
Loading

0 comments on commit 14c4f6f

Please sign in to comment.