-
Notifications
You must be signed in to change notification settings - Fork 214
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
feat: support for default values in InputFieldDefinition
#2117
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2117 +/- ##
==========================================
+ Coverage 84.12% 84.18% +0.05%
==========================================
Files 212 212
Lines 20054 20108 +54
==========================================
+ Hits 16870 16927 +57
+ Misses 3184 3181 -3 ☔ View full report in Codecov by Sentry. |
src/core/blueprint/blueprint.rs
Outdated
@@ -262,3 +263,73 @@ impl Blueprint { | |||
schema.finish().unwrap() | |||
} | |||
} | |||
|
|||
#[cfg(test)] | |||
mod tests { |
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 think proper .md test will be more descriptive and valuable here since with unit test we limited only to config/blueprint definitions
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.
do you mean, I should take snapshots of the blueprint that is generated from config defined in .md files?
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 tried adding blueprint as snapshot but I think since HashMap
is being used in the type, the order keeps changing and new snapshot gets created everytime
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.
no, no, my suggestion is to not focus on blueprint structure at all and focus on the fact that default values should work properly when they are defined. I.e. in test when making query without providing value verify that request hits the mock for default value, and if we do provide some value in query than another mock should be hit
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.
Apparently, the same issue that was encountered in #1939 for default value in field arguments, seems to also be affecting default values in input types. It will not be possible to test this change by running a query until that issue with async-graphql
is fixed
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.
ah, ok. Let's maybe wait for resolution of this
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.
Delete these tests perhaps. I think @meskill Is correct we should implement them as integration tests. We can mark them as skipped so that with our new GraphQL engine we should be able to execute it.
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.
@tusharmath @meskill added a test and marked it as skipped. The added test will pass once the support for default value is added for input types
src/core/blueprint/into_schema.rs
Outdated
@@ -123,6 +123,10 @@ fn to_type(def: &Definition) -> dynamic::Type { | |||
if let Some(description) = &field.description { | |||
input_field = input_field.description(description); | |||
} | |||
if let Some(default_value) = field.default_value.clone() { | |||
input_field = | |||
input_field.default_value(ConstValue::from_json(default_value).unwrap()) |
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.
Drop unwrap.
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.
use trace::warning
to show that transformation failed over 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.
done
} | ||
|
||
type Query { | ||
abc(input: Input!): Int @http(path: "/foo/{{.args.input.id}}") |
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.
abc(input: Input!): Int @http(path: "/foo/{{.args.input.id}}") | |
abc(input: Input!): Int @http(path: "/foo/{{.args.input.id}}") | |
pqr(input: Input! = {id: 2}): Int @http(path: "/foo/{{.args.input.id}}") |
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.
Add this test, and mark it as not-passing and point it to the PR which fixes this issues in Async GraphQL.
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.
added two separate tests, one for default value in argument and another for default value in input type
} | ||
|
||
input Input { | ||
id: Int |
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.
default value is missing in merged.
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.
fixed this
query { | ||
abc(input: {id:2}) | ||
} | ||
``` |
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.
Split this into two-tests.
- Where you don't make any requests. Mark this test as skipped.
- Where we only test for merged and client schemas.
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.
done
Action required: PR inactive for 2 days. |
Bencher
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
src/core/config/from_document.rs
Outdated
@@ -449,6 +458,7 @@ trait Fieldlike { | |||
fn type_of(&self) -> &Type; | |||
fn description(&self) -> &Option<Positioned<String>>; | |||
fn directives(&self) -> &[Positioned<ConstDirective>]; | |||
fn default_value(&self) -> Option<ConstValue>; |
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 need this to be implemented via FieldLike
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.
removed it
src/core/blueprint/into_schema.rs
Outdated
dynamic::InputValue::new(arg.name.clone(), to_type_ref(&arg.of_type)); | ||
let input_value = | ||
insert_serde_value_to_input_value(input_value, arg.default_value.clone()); | ||
dyn_schema_field = dyn_schema_field.argument(input_value); |
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.
for arg in field.args.iter() {
let iv = dynamic::InputValue::new(
arg.name.clone(),
to_type_ref(&arg.of_type),
);
let iv = iv.default_value(arg.default_value.as_ref().map(|v | ConstValue::from_json(v.clone()).ok()).flatten().unwrap()); // TODO: handle unwrap
dyn_schema_field = dyn_schema_field.argument(iv);
}
I think with v7.0.6 we can just pass the default value and everything else should work as is
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.
for arg in field.args.iter() { let iv = dynamic::InputValue::new( arg.name.clone(), to_type_ref(&arg.of_type), ); let iv = iv.default_value(arg.default_value.as_ref().map(|v | ConstValue::from_json(v.clone()).ok()).flatten().unwrap()); // TODO: handle unwrap dyn_schema_field = dyn_schema_field.argument(iv); }I think with v7.0.6 we can just pass the default value and everything else should work as is
I am doing this already inside the insert_serde_value_to_input_value
function but its not working for default value in input types
InputFieldDefinition
Summary:
Briefly describe the changes made in this PR.
Issue Reference(s):
Fixes #... (Replace "..." with the issue number)
Build & Testing:
cargo test
successfully../lint.sh --mode=fix
to fix all linting issues raised by./lint.sh --mode=check
.Checklist:
<type>(<optional scope>): <title>