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

add errors for response validation #5787

Open
wants to merge 32 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b2bddc3
add errors for response validation
Geal Aug 7, 2024
97a748d
Merge branch 'dev' into geal/response-validation-errors
Geal Aug 20, 2024
6d62d38
lint
Geal Aug 20, 2024
ffde309
lint
Geal Aug 20, 2024
6733583
align error messages with the gateway
Geal Aug 20, 2024
4747e4a
error messages for invalid typename values
Geal Aug 20, 2024
24d46b9
lint
Geal Aug 20, 2024
36231f5
update error messages
Geal Aug 20, 2024
9cf401e
Merge branch 'dev' into geal/response-validation-errors
Geal Aug 27, 2024
cecf18a
Update apollo-router/src/json_ext.rs
Geal Aug 27, 2024
965cfd2
revert __typename validation
Geal Aug 27, 2024
6f2fcaf
let null values go through
Geal Aug 27, 2024
99aef34
fix
Geal Aug 27, 2024
a59f15d
changeset
Geal Aug 27, 2024
b201d28
Merge branch 'dev' into geal/response-validation-errors
Geal Aug 30, 2024
cb6eda8
Merge branch 'dev' into geal/response-validation-errors
Geal Sep 16, 2024
d14767a
add a test
Geal Sep 16, 2024
8fe0b68
fix enum validation error message
Geal Sep 16, 2024
9d17497
check lists
Geal Sep 16, 2024
d23b782
Merge branch 'dev' into geal/response-validation-errors
Geal Oct 15, 2024
6881f9b
add an error code
Geal Oct 15, 2024
4006b2e
Add a test for out-of-range values for `Int`
andrewmcgivery Oct 11, 2024
468ae57
Update test from #6143 to match the implementation from #5787
goto-bus-stop Oct 17, 2024
e6020bb
Fix parent type when result-coercing non-null types
goto-bus-stop Oct 17, 2024
45c7e8a
Fix result coercion for ID fields
goto-bus-stop Oct 17, 2024
7c7ba29
Add more tests for response value coercion/validation
goto-bus-stop Oct 22, 2024
c34b7d1
Move the response validation tests together
goto-bus-stop Oct 22, 2024
536d9f6
Adjust test expectations to match current behaviour
goto-bus-stop Oct 22, 2024
877eb2c
Correct parent type used for top-level fields
goto-bus-stop Oct 22, 2024
4fa8353
lint
goto-bus-stop Oct 22, 2024
e206b6d
Fix snapshot
goto-bus-stop Oct 22, 2024
f0f7300
Revert ID validation fix--moving to separate PR
goto-bus-stop Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changesets/fix_geal_response_validation_errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### add errors for response validation ([Issue #5372](https://github.com/apollographql/router/issues/5372))

When formatting responses, the router is validating the data returned by subgraphs and replacing it with null values as appropriate. That validation phase is now adding errors when encountering the wrong type in a field requested by the client.

By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/5787
14 changes: 14 additions & 0 deletions apollo-router/src/json_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ pub(crate) trait ValueExt {
#[track_caller]
fn is_object_of_type(&self, schema: &Schema, maybe_type: &str) -> bool;

/// value type
fn json_type_name(&self) -> &'static str;

/// Convert this value to an instance of `apollo_compiler::ast::Value`
fn to_ast(&self) -> apollo_compiler::ast::Value;

Expand Down Expand Up @@ -475,6 +478,17 @@ impl ValueExt for Value {
})
}

fn json_type_name(&self) -> &'static str {
match self {
Value::Array(_) => "array",
Value::Null => "null",
Value::Bool(_) => "boolean",
Value::Number(_) => "number",
Value::String(_) => "string",
Value::Object(_) => "object",
}
}

fn to_ast(&self) -> apollo_compiler::ast::Value {
match self {
Value::Null => apollo_compiler::ast::Value::Null,
Expand Down
Loading
Loading