Skip to content
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

queries with defer must have the Accept: multipart/mixed header #1610

Merged
merged 11 commits into from
Aug 26, 2022

Conversation

Geal
Copy link
Contributor

@Geal Geal commented Aug 25, 2022

Fix #1618

Since deferred responses can come back as multipart responses, we must
check that the client supports that content type. This will allow older
clients to show a meaningful error message instead of a parsing error if
the @defer directive is used but they don't support it

Since deferred responses can come back as multipart responses, we must
check that the client supports that content type. This will allow older
clients to show a meaningful error message instead of a parsing error if
the `@defer` directive is used but they don't support it
@Geal Geal self-assigned this Aug 25, 2022
@Geal Geal changed the title queries with defer should have the Accept: multipart/mixed header queries with defer must have the Accept: multipart/mixed header Aug 25, 2022
@github-actions

This comment has been minimized.

@Geal
Copy link
Contributor Author

Geal commented Aug 25, 2022

it looks like rustfmt gives up on formatting supergraph_service.rs, so I'll throw in a small refactoring to simplify it

@@ -153,7 +154,26 @@ where
QueryPlannerContent::Plan { query, plan } => {
let can_be_deferred = plan.root.contains_defer();

if let Some(err) = query.validate_variables(body, &schema).err() {
if can_be_deferred && !req.originating_request.headers().get_all(ACCEPT).iter().filter_map(|value| value.to_str().ok()).flat_map(|value| value.split(',')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a fine starting point but I'd suggest at least an issue-and-a-comment noting that this isn't a full spec complaint accept parser. (most importantly it will get confused if you have any "parameters" in accept like accept: multipart/mixed; foo=bar, application/json; less importantly it can get even more confused if any parameters use quoted strings, like accept: application/json; someParam="foo, multipart/mixed, bar".)

(and yes, the way that parameters bind to types in Accept header involves semicolons that bind tighter than commas, unlike in English/French/etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, this is something I planned to fix too. I'm a bit disappointed that the http crate does not provide a spec compliant iterator over values for well known headers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm opening #1618 to track this

@Geal Geal mentioned this pull request Aug 25, 2022
@Geal Geal added this to the v1.0.0-alpha.0 milestone Aug 25, 2022
@Geal Geal requested review from garypen and abernix August 25, 2022 15:39
apollo-router/src/services/supergraph_service.rs Outdated Show resolved Hide resolved
@Geal Geal dismissed glasser’s stale review August 26, 2022 13:18

the mediatype crate is used now, dismissing the review to unblock the release

@Geal Geal enabled auto-merge (squash) August 26, 2022 13:18
Copy link
Contributor

@o0Ignition0o o0Ignition0o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's followup on the mime type dance though.

@Geal Geal merged commit cf40d8d into main Aug 26, 2022
@Geal Geal deleted the geal/accept-multipart branch August 26, 2022 13:42
@abernix abernix mentioned this pull request Aug 29, 2022
Geal added a commit that referenced this pull request Aug 29, 2022
Follow up on #1610 

rustfmt does not apply anymore on supergraph_service.rs, which is a hint
that the code is way too complex. This PR moves the `Service:call` body
to an async function, and splits part of the functionality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add a spec compliant parser for Accept HTTP header values
4 participants