Skip to content

mateusmaso/graphql-jay-hyperschema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-jay-hyperschema Build Status

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

Install

$ npm install --save graphql-jay-hyperschema

Usage

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.

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

linkRel

Use to relate to another LDO based on schema values.

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

License

MIT © Mateus Maso