graphprotocol / graphprotocol/hypergraph

optional/required fields behaviour

Offen
#84 6 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@nikgraf arbeitet bereits daran.

Seit 09.1.2025.

Schema SDK
Vorherrschende Sprache
TypeScript
Sterne
22
Forks
12
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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 …

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.