@gsox/schema
v0.3.0
Published
decorators, types, and builders for describing data
Downloads
5
Readme
gsox-schema
decorators, types, and builders for describing data
installation
npm i @gsox/schema
Decorators
import { Type, Field } from "@gsox/schema"
@Type()
class Alert {
@Field('Int')
id:number;
@Field()
data: string;
}
@Type()
class MessageType { ... }
TypeScript Decorators
JavaScript Decorators
AST Builders (wip)
import { TypeNode, FieldNode } from "@gsox/schema"
const alertTypeNode = new TypeNode('Alert', [
new FieldNode('id', 'Int'),
new FieldNode('data', 'String')
])
GraphQL (wip)
const typeDef = `
type Alert {
id: Int
data: String
}
`
Schema Injection
inject shared client and server types or graphql type definitions
const inject: {new ()}[] //constructor functions
| {}[] //objects
| string[] =
[
Notification, // class with
Message, // schema
new Alert(), // decorators
//or typedef
`message {
type: String
}`
]
// client.js
import { createClient } from "@gsox/client"
const client = createClient(options)
client.subscribe([...inject], observer)
// server.js
import { applyMiddleware } from "@gsox/server"
const app = express()
const server = applyMiddleware(app, [...inject])