question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use JSON Schema for model definition

See original GitHub issue

Feature 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:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Eunovocommented, Jul 23, 2020
  • Relationship (Array etc.)

Once again, why an array? Why not mark properties like this

...
       name: {
            type: 'string',
            index: true, // if 'name' is an index
        },
        postId: {
            type: 'string',
            relationship: 'many-to-one' // many comments to one post
        },
...
0reactions
kingsleyzissoucommented, Jul 23, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found