Use JSON Schema for model definition
See original GitHub issueFeature Request
When defining models developers can declare both data requirements but also validation.
export const user = {
version: 0,
type: 'object',
properties: {
id: {
type: 'string',
primary: true
},
name: {
type: 'string'
},
color: {
type: 'string'
},
updatedAt: {
type: 'number'
}
},
indexes: ['name', 'color', 'updatedAt'],
required: ['color']
};
Since we will need to generate those from GraphQL schema we will have limited information available (only type, required and relations)
The generated source should be editable as users might add more info into those files.
Approach 1
We generate API from GraphQL schema to JSONSchema
Pros:
- Easy to do (multiple libraries available) Cons:
- Lack of typing supports
Approach 2
Generate typescript objects from GraphQL Schema and then transform them Example: https://github.com/YousefED/typescript-json-schema/blob/master/test/programs/comments/
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Getting Started Step-By-Step - JSON Schema
To start a schema definition, let's begin with a basic JSON schema. We start with four properties called keywords which are expressed as...
Read more >JSON Schema Examples Tutorial - MongoDB
JSON Schema is a model that represents the format and structure of a common group of JSON documents.
Read more >Definitions & References - JSON Schema
Definitions & References. The JSON Schema specification also allows us to define auxiliary schema in order to be reused and combined later on....
Read more >JSON - Schema - Tutorialspoint
JSON - Schema, JSON Schema is a specification for JSON based format for defining the structure of JSON data. It was written under...
Read more >How to Use JSON Schema to Validate JSON Documents in ...
A JSON schema itself is a valid JSON document with key/value pairs. Each key has a special meaning and is used to define...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Once again, why an array? Why not mark properties like this
@wtrocki @Eunovo I think the benefits of using an array to hold some of this information is that we don’t have to iterate through each field in the schema to gather the information. It’s only a slight benefit. Although it might be easier to generate the schema and add these as properties to each of the fields.