graphprotocol / graphprotocol/hypergraph

optional/required fields behaviour

オープン
#84 コメント 6 件 リアクション 0 件 担当者 1 名 GitHub で見る

@nikgraf がすでに取り組んでいます。

2025年1月9日 から。

Schema SDK
主要言語
TypeScript
スター
22
フォーク
12
PR マージ指標
30日以内にマージされた PR はありません

説明

We should decide how the schema in the framework should behave. In GRC-20 every field except for id, Created at, Updated At, Created by, Versions are optional.

Here our options. For simplicity I would focus on createEntity and useQuery. With this example schema:

{
  Todo: {
    name: type.Text,
    completed: type.Checkbox,
  },
}
createEntity({ name: "Setup call", completed: true }); // valid call with all attributes

const result = useQuery({ types: ['Todo']});
/*
[
  { id: "abc", name: "Setup call", completed: true },
  { id: "abc", name: "Draft post", completed: false }
]
*/

Everything always optional

// would be valid and `completed` would just not be set
createEntity({ name: "Setup call" });

const result = useQuery({ types: ['Todo']});
/* returns all entities with the types regardless if they comply to the schema
[
  { id: "abc", name: "Setup call" },
  { id: "abc", completed: false }
]
*/

Everything always required

// valid
createEntity({ name: "Setup call", completed: true });
// would NOT be valid and fail to create the todo
createEntity({ name: "Draft post" });

const result = useQuery({ types: ['Todo']});
/* returns only entities where the entry complies to the schema. Entires like `{ id: "abc", completed: false }` are filtered out
[
  { id: "abc", name: "Setup call", completed: true },
]
*/

Developers can decided

Schema:

{
  Todo: {
    name: type.Text,
    completed: type.Checkbox,
    dueUntil: type.Date({ required: false }),
  },
}
createEntity({ name: "Setup call", completed: false }); // valid
createEntity({ name: "Draft post", completed: false, dueUntil: "2025-02-10" }); // valid
createEntity({ name: "Do laundry" }); // would NOT be valid and fail to create the todo

const result = useQuery({ types: ['Todo']});
/* returns only entities where the entry complies to the schema. Entires like `{ id: "abc", completed: false }` are filtered out
[
  { id: "abc", name: "Setup call", completed: false },
  { id: "abc", name: "Draft post", completed: false, dueUntil: "2025-02-10" },
]
*/

Other suggestions

Feel free to add your options here …

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。