Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/mateusmaso/graphql-jay-hyperschema

GraphQL Jay adapter for JSON Hyper-Schema (draft-04)
https://github.com/mateusmaso/graphql-jay-hyperschema

graphql-jay javascript json-hyper-schema

Last synced: 10 days ago
JSON representation

GraphQL Jay adapter for JSON Hyper-Schema (draft-04)

Awesome Lists containing this project

README

        

# graphql-jay-hyperschema [![Build Status](https://travis-ci.org/mateusmaso/graphql-jay-hyperschema.svg?branch=master)](https://travis-ci.org/mateusmaso/graphql-jay-hyperschema)

GraphQL Jay adapter for JSON Hyper-Schema (draft-04)

## Install

```
$ npm install --save graphql-jay-hyperschema
```

## Usage

```javascript
import {adapter} from "graphql-jay-hyperschema"

var url = "http://myservice.com/api/v1"

export default function service() {
var metadata = {
"$schema": "http://json-schema.org/draft-04/hyper-schema#",
"type": "object",
"definitions": {
"user": {
"type": "object",
"properties": {...},
"required": [...],
"links": [...]
}
},
"properties": {
"user": {
"$ref": "#/definitions/user"
}
},
"links": [{
"rel": "user",
"href": "/users/{id}",
"schema": {
"type": "object",
"properties": {
"id": {
"type": "number"
}
},
"required": ["id"]
},
"targetSchema": {
"$ref": "#/definitions/user"
}
}]
}

return {
url,
metadata,
adapter
}
}
```

## ```LDO``` extra properties

**each**

Use to resolve relations with an unique ```href``` for each item from a target field.

```json
{
"rel": "urls",
"href": "{+item}",
"each": "urls"
}
```

**linkRel**

Use to relate to another ```LDO``` based on ```schema``` values.

```json
{
"rel": "tatooine",
"linkRel": {
"id": "planetWithId",
"values": {
"id": "1"
}
}
}
```

## License

MIT © [Mateus Maso](http://www.mateusmaso.com)