google cloud platform – How to import and use javascript constants in config block of sqlx, when js file not in includes folder

The google docs outline how to define field definitions globaly in the includes folder.
e.g. you could have includes/docs.js

This might look like:

const myField = 'A definition for myField';

module.exports = {
 myField
};

Then in a definitions subfolder, say definitions/myData/source/mySourceData.sqlx you could have a config block like:

config {
  type: "view",
  schema: "mySchema",
  columns: {
    myField: docs.myField
  }

...some SQL

However, my dataform repo is large with numerous modules. For ease of organization, I want to have my docs.js file in the appropriate module (really folder) for the specified integration.

e.g. I want to include my docs.js file in definitions/myData/shared/myDataDocs.js

I attempted this. The myDataDocs.js file is the same as docs.js example specified above, just located at definitions/myData/shared/myDataDocs.js

In the mySourceData.sqlx I adjusted the file to include this:

js {
  const myDataDocs = require('definitions/myData/shared/myDataDocs.js');

}
config {
  type: "view",
  schema: "mySchema",
  columns: {
    myField: myDataDocs.myField
  }

...some SQL

I am getting ‘myDataDocs’ is not defined. How do I reference a JS file and use it in the config block for column definitions, when the JS file is not located in the includes folder?

Read more here: Source link