Fix for cyclic relationships, getQueryableFields allowed relationships from other tables, which can't work.

This commit is contained in:
mike12345567 2024-08-20 12:13:37 +01:00
parent 760be9d6af
commit 5435028e7d
1 changed files with 6 additions and 3 deletions

View File

@ -59,14 +59,15 @@ export const getQueryableFields = async (
const extractTableFields = async ( const extractTableFields = async (
table: Table, table: Table,
allowedFields: string[], allowedFields: string[],
fromTables: string[] fromTables: string[],
opts: { allowRelationships?: boolean } = { allowRelationships: true }
): Promise<string[]> => { ): Promise<string[]> => {
const result = [] const result = []
for (const field of Object.keys(table.schema).filter( for (const field of Object.keys(table.schema).filter(
f => allowedFields.includes(f) && table.schema[f].visible !== false f => allowedFields.includes(f) && table.schema[f].visible !== false
)) { )) {
const subSchema = table.schema[field] const subSchema = table.schema[field]
if (subSchema.type === FieldType.LINK) { if (opts.allowRelationships && subSchema.type === FieldType.LINK) {
if (fromTables.includes(subSchema.tableId)) { if (fromTables.includes(subSchema.tableId)) {
// avoid circular loops // avoid circular loops
continue continue
@ -76,7 +77,9 @@ export const getQueryableFields = async (
const relatedFields = await extractTableFields( const relatedFields = await extractTableFields(
relatedTable, relatedTable,
Object.keys(relatedTable.schema), Object.keys(relatedTable.schema),
[...fromTables, subSchema.tableId] [...fromTables, subSchema.tableId],
// don't let it recurse back and forth between relationships
{ allowRelationships: false }
) )
result.push( result.push(