Implement implicit object references and capability query foundations
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
visit,
|
||||
type GraphQLInputType,
|
||||
type GraphQLOutputType,
|
||||
type GraphQLInputFieldConfigMap,
|
||||
@@ -54,6 +55,16 @@ export interface RelationalSchemaEnvironment {
|
||||
}
|
||||
|
||||
export function relationalSchema(env: RelationalSchemaEnvironment, document?: DocumentNode) {
|
||||
const requestedInterfaces = new Set<string>();
|
||||
if (document)
|
||||
visit(document, {
|
||||
ObjectField(node) {
|
||||
if (node.name.value !== "_camino" || node.value.kind !== "ObjectValue") return;
|
||||
const qualified = node.value.fields.find((field) => field.name.value === "as");
|
||||
if (qualified?.value.kind === "ObjectValue")
|
||||
for (const field of qualified.value.fields) requestedInterfaces.add(field.name.value);
|
||||
},
|
||||
});
|
||||
const outputCache = new Map<string, GraphQLObjectType>();
|
||||
const inputCache = new Map<string, GraphQLInputObjectType>();
|
||||
const referenceCache = new Map<string, GraphQLScalarType>();
|
||||
@@ -303,14 +314,40 @@ export function relationalSchema(env: RelationalSchemaEnvironment, document?: Do
|
||||
not: { type: where(row) },
|
||||
};
|
||||
for (const [name, field] of fields(row)) {
|
||||
if (row.kind === "object" && field.kind === "row") continue;
|
||||
if (name in result) throw new QueryCompileError("QUERY_SCHEMA_NAME", `Reserved predicate name ${name}`);
|
||||
if (row.kind === "object" && field.kind === "row") {
|
||||
result[name] = {
|
||||
type: compare(
|
||||
valueType.interfaceRef(
|
||||
field.row.kind === "object"
|
||||
? field.row.interfaceRevisionId
|
||||
: (() => {
|
||||
throw new Error("Expected relationship object");
|
||||
})(),
|
||||
),
|
||||
),
|
||||
};
|
||||
continue;
|
||||
}
|
||||
if (field.kind === "leaf" && !comparableValue(field.type)) continue;
|
||||
result[name] = { type: field.kind === "row" ? where(field.row) : compare(field.type) };
|
||||
}
|
||||
result._camino = {
|
||||
type: inp("WhereMeta", row, () => {
|
||||
const meta: GraphQLInputFieldConfigMap = {};
|
||||
if (row.kind === "object" && requestedInterfaces.size)
|
||||
meta.as = {
|
||||
type: inp("Interfaces", row, () =>
|
||||
Object.fromEntries(
|
||||
[...env.contracts.values()]
|
||||
.filter((contract) => !contract.template && requestedInterfaces.has(env.name(contract.revisionId)))
|
||||
.map((contract) => [
|
||||
env.name(contract.revisionId),
|
||||
{ type: where(objectRow(contract.revisionId)) },
|
||||
]),
|
||||
),
|
||||
),
|
||||
};
|
||||
for (const [name, type] of leafFields(row)) meta[name] = { type: compare(type) };
|
||||
const edges = relations(row);
|
||||
if (edges.length)
|
||||
|
||||
Reference in New Issue
Block a user