-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve query registration and schema validation #243
Conversation
8b4be91
to
55bf542
Compare
LoggerManager::instance()->error( 'Failed to get query for Airtable block' ); | ||
return; | ||
} | ||
public static function register_block_for_airtable_data_source( AirtableDataSource $data_source, array $block_overrides = [] ): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we follow the {type}_block
naming here and make this something like register_item_block_...
or register_single_item_block_...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with whatever naming scheme. I think we might even want to centralize the entrypoints for registering official integrations, like Integration::register_block( [ /* options */ ] )
LoggerManager::instance()->error( 'Failed to get query for Airtable block' ); | ||
return; | ||
} | ||
public static function register_block_for_airtable_data_source( AirtableDataSource $data_source, array $block_overrides = [] ): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we follow the {type}_block
naming here and make this something like register_item_block_...
or register_single_item_block_...
?
] ); | ||
|
||
$block_options = [ | ||
'pages' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary for page registration to be part of the block registration? I mainly ask because we might want to have overrides for multiple blocks on a page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed you can do this now. The page is only created once if you use the same page slug for multiple blocks.
We really need some deeper product exploration around pages, though, because I don't really know what use cases we are solving.
ea8c354
to
b2016ca
Compare
Thanks @brookewp!
This is intentional when the registered pattern has a
I believe I've "fixed" this type mismatch issue by selecting the first item in the array. Could you confirm? |
b2016ca
to
310297c
Compare
Thanks @shekharnwagh, fixed in 912831c |
0f1c17b
to
c3d6720
Compare
|
||
By default, the `get_endpoint` method proxies to the `get_endpoint` method of query's data source. Override this method to set a custom endpoint for the query—for example, to construct the endpoints using an input variable. The input variables for the current request are provided as an associative array (`[ $var_name => $value ]`). | ||
- `format` (optional): A callable function that formats the output variable value. | ||
- `generate` (optional): A callable function that generates or extracts the output variable value from the response, as an alternative to `path`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this is an alternative to path
, but path
below is listed as (required). A bit confusing, clarification here would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 5060870
docs/workflows/index.md
Outdated
- [Create an Airtable integration](airtable.md) | ||
- [Create a Google Sheets integration](google-sheets.md) | ||
- [Create a REST API integration](rest-api.md) | ||
- [Create a REST API integration with code](rest-api-with-code.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the top three bullet points be under the "UI-based workflows" header? It's a bit confusing to see "Create a REST API integration" and "Create a REST API integration with code" together here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also "with code" / "Code-based" might be the wrong nomenclature since they both utilize code, it's more about the starting point. Maybe "UI-configured sources" versus "Code-generated sources" or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 5060870
register_remote_data_loop_block( 'Conference Event List', $airtable_list_events_query ); | ||
register_remote_data_page( $block_name, 'conference-event' ); | ||
AirtableIntegration::register_block_for_airtable_data_source( $airtable_data_source, $block_options ); | ||
AirtableIntegration::register_loop_block_for_airtable_data_source( $airtable_data_source, $block_options ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chriszarate I'm curious why we use these new integration-specific wrappers. Why is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because they automatically provide the queries that are specific to the integration. Definitely open to different naming or organization.
} | ||
|
||
return static::from_array( $config ); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* @psalm-suppress ParamNameMismatch reason: we want the clarity provided by the rename here | ||
* | ||
* TODO: Do we need to sanitize this to prevent leaking sensitive data? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be misunderstanding the security concern here, but I don't think so. We don't currently expose this in the UI (I think), we just slurp it into ConfigStore
or use values in code. If a user can run arbitrary code to dump ::to_array()
, they'd also have the ability to read define
s or env keys or WP config values anyhow. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't currently expose this in the UI (I think)
@alecgeatches Not visually, but anyone that can access the REST endpoint that supports the plugin settings screen (GET remote-data-blocks/data-sources
) can view the full service config, including credentials. Currently this is limited to manage_options
but I imagine there will be a push to lower that substantially.
This is currently intentional-by-design, because there is front-end code that needs those credentials in order to call the APIs to do schema discovery. However, we probably need to redact sensitive credentials and conduct these requests via the REST API, so that we don't expose them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They even make their way into the DOM, since they are used to populate password fields when a user edits an existing data source.
Co-authored-by: Alec Geatches <[email protected]>
Co-authored-by: Alec Geatches <[email protected]>
Co-authored-by: Alec Geatches <[email protected]>
Co-authored-by: Alec Geatches <[email protected]>
a1dcf79
to
2fb45d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the direction this moves us. I'm sure there will be some tweaks still, but lets get it merged before we have more conflicts! 🚢
Known issues
Registered generic HTTP data sources is broken.Psalm validation is broken because ofNumberFormatter
Github markdown source seems to be broken.