Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/util/references.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,11 @@ const extractObjectProperties = (
results.push({ path: currentPath, type });
}

// Recursively traverse into object properties
if (isRealObjectType(type)) {
const properties = type.getProperties();
// Recursively traverse into object properties. Traversal also runs on the
// non-nullable type: a nullable object in the chain (e.g. `{bla?: TEXT} | null`)
// is a union whose getProperties() is empty, which would cut off all nested paths.
if (isRealObjectType(nonNullableType)) {
const properties = nonNullableType.getProperties();
if (properties && properties.length > 0) {
properties.forEach((property) => {
const propType = checker.getTypeOfSymbolAtLocation(property, property.valueDeclaration!);
Expand Down
74 changes: 74 additions & 0 deletions test/schema/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,4 +825,78 @@ describe("Schema", () => {
).toBe(true);
});

it('offers a nested nullable object property as a ReferenceValue path suggestion for a plain TEXT parameter', () => {
// Node 1: custom::text::nested_nullable_object(): {test?: {bla?: TEXT | null} | null}
// — no parameters, returns an object whose `test` property is an optional,
// nullable object which itself holds an optional, nullable `bla` property.
// Node 2: std::text::split(value: TEXT, delimiter: TEXT): LIST<TEXT>
//
// The `value` parameter is declared as plain TEXT (string). Node 1's `test.bla`
// property has type string | null | undefined behind a nullable `test` object.
// Strict assignability would reject it, but the editor must still offer node 1's
// `test.bla` property as a ReferenceValue suggestion with referencePath
// [{path: "test"}, {path: "bla"}]: the nullish parts along the reference chain
// should be ignored for suggestion scoping.
const NESTED_NULLABLE_OBJECT_FN: FunctionDefinition = {
id: "gid://sagittarius/FunctionDefinition/9003",
identifier: "custom::text::nested_nullable_object",
signature: "(): {test?: {bla?: TEXT | null} | null}",
};

const flow: Flow = {
id: "gid://sagittarius/Flow/1",
startingNodeId: "gid://sagittarius/NodeFunction/1",
signature: "(): void",
nodes: {
nodes: [
{
id: "gid://sagittarius/NodeFunction/1",
functionDefinition: {identifier: "custom::text::nested_nullable_object"},
nextNodeId: "gid://sagittarius/NodeFunction/2",
parameters: {
nodes: [],
},
},
{
id: "gid://sagittarius/NodeFunction/2",
functionDefinition: {identifier: "std::text::split"},
parameters: {
nodes: [
{value: null},
{value: {__typename: "LiteralValue", value: ","}},
],
},
},
],
},
};

const [valueSchema] = getSignatureSchema(
flow,
DATA_TYPES,
[...FUNCTION_SIGNATURES, NESTED_NULLABLE_OBJECT_FN],
"gid://sagittarius/NodeFunction/2",
);

// value: TEXT → free-form text input.
expect(valueSchema.schema.input).toBe("text");

// Node 1's `test.bla` property is TEXT | null | undefined nested inside the
// nullable `test` object; stripping the nullish parts leaves TEXT, which is
// assignable to the TEXT parameter → node 1 must be offered with
// referencePath [{path: "test"}, {path: "bla"}].
const suggestions = (valueSchema.schema.suggestions ?? []) as any[];
expect(
suggestions.some(
(s) =>
s.__typename === "ReferenceValue" &&
s.nodeFunctionId === "gid://sagittarius/NodeFunction/1" &&
Array.isArray(s.referencePath) &&
s.referencePath.length === 2 &&
s.referencePath[0].path === "test" &&
s.referencePath[1].path === "bla",
),
).toBe(true);
});

})