1
0
Fork 0
mirror of synced 2024-10-05 20:44:47 +13:00

Update order of schema enrichment in data fetch

This commit is contained in:
Andrew Kingston 2022-05-24 10:29:58 +01:00
parent d84150d26f
commit 416baf556c

View file

@ -259,6 +259,24 @@ export default class DataFetch {
return null
}
// Check for any JSON fields so we can add any top level properties
let jsonAdditions = {}
Object.keys(schema).forEach(fieldKey => {
const fieldSchema = schema[fieldKey]
if (fieldSchema?.type === "json") {
const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, {
squashObjects: true,
})
Object.keys(jsonSchema).forEach(jsonKey => {
jsonAdditions[`${fieldKey}.${jsonKey}`] = {
type: jsonSchema[jsonKey].type,
nestedJSON: true,
}
})
}
})
schema = { ...schema, ...jsonAdditions }
// Ensure schema is in the correct structure
let enrichedSchema = {}
Object.entries(schema).forEach(([fieldName, fieldSchema]) => {
@ -275,24 +293,6 @@ export default class DataFetch {
}
})
// Check for any JSON fields so we can add any top level properties
let jsonAdditions = {}
Object.keys(enrichedSchema).forEach(fieldKey => {
const fieldSchema = enrichedSchema[fieldKey]
if (fieldSchema?.type === "json") {
const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, {
squashObjects: true,
})
Object.keys(jsonSchema).forEach(jsonKey => {
jsonAdditions[`${fieldKey}.${jsonKey}`] = {
type: jsonSchema[jsonKey].type,
nestedJSON: true,
}
})
}
})
enrichedSchema = { ...enrichedSchema, ...jsonAdditions }
return enrichedSchema
}