-
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
Field Arguments RFC/Spec #139
Conversation
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.
Looks great so far, thanks. Couple of notes:
- I think we could come up with a better example than truncating the title: what about adding a
where
orlimit
argument to the nested arrays withininstitution
? That would mirror a real use case. - You'll also need to update the test cases for the reference agent to exercise these new code branches. I suspect tests are passing right now because the lack of an argument is ignored by the reference agent, but that should fail with a
BadRequest
error. ndc-test
will have to be changed to omit any fields which take arguments, since we don't generate argument values in general.
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 need to make the ndc-test
change to omit fields with arguments, before this can merged, or else we'll start generating invalid requests.
The specification should also be updated please.
@paf31 there's a recursive case when if the only field in a query is omitted due to arguments, then the parent should also be omitted, etc. |
@paf31 I think I've got everything updated:
I'm not sure how to use the ok_or pattern you recommended since we don't actually want to throw errors in the case of Nones in the reference agent unless I'm missing something. Let me know if you've got a sec to go over this. |
Yes I agree with this, but it feels like "limit" specifically is being required if any arguments are required. In the current state of the test suite this is the same thing, but if any other arguments are added this no longer makes sense. |
For example, it seems that if I added |
@codedmart The issue is that we're not checking if all arguments are supplied, we're just checking if "limit" is supplied. |
The [schema response](../schema/object-types.md) will specify which fields take arguments via its respective `arguments` key. | ||
|
||
- If a field has any arguments specified, then all arguments must be provided when that field is queried | ||
- A literal argument `null` value may be used for optional arguments |
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.
Let's not use the word optional because it'll be confusing (required/optional vs nullable/non-nullable). We could say all arguments are required, including nullable arguments.
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.
- If a field has any arguments specified, then all arguments must be provided when that field is queried
- Literal argument `null` values may be used for nullable arguments
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 this ok?
…lable arguments`
I spotted a couple of bugs and I think I've fixed them, but I need to review. The new code also needs some tidying:
Also, I noticed (and documented) that we can't support field arguments in column mappings for relationships, or to define relationship arguments, or in nested field path selectors. I think that'll be fine for now but I want to make sure that's ok @codedmart. |
I think this incorrectly always requires a limit arg: // ANCHOR_END: eval_comparison_target
// ANCHOR: eval_column
fn eval_column(
variables: &BTreeMap<String, serde_json::Value>,
row: &Row,
column_name: &str,
arguments: &BTreeMap<String, models::Argument>,
) -> Result<serde_json::Value> {
let column = row.get(column_name).cloned().ok_or((
StatusCode::BAD_REQUEST,
Json(models::ErrorResponse {
message: "invalid column name".into(),
details: serde_json::Value::Null,
}),
))?;
if let Some(array) = column.as_array() {
let limit_argument = arguments.get("limit").ok_or((
StatusCode::BAD_REQUEST,
Json(models::ErrorResponse {
message: "Expected argument 'limit'".into(),
details: serde_json::Value::Null,
}),
))?;
|
which makes having backwards compatibility impossible? |
This PR updates the NDC-Spec to allow arguments to fields.
See the rendered RFC here.
The motivation for this change is to generalise the API surface to allow more expressive queries - This should be very similar to collection arguments in practice but can apply to any field, not just top-level collections.
Some examples of why this might be useful:
Changes
The following changes are present in this PR:
ObjectField
inndc-models/src/lib.rs
CollectionInfo
ofBTreeMap<String, ArgumentInfo>
Field
extended witharguments: BTreeMap<String, Argument>
QueryRequest
for collectionsinstitutions
.staff
array field.Follow Up Work
Notes