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

Incorrect Optionality in Generated SDL for InputObject Fields With Defined Defaults #1321

Open
Adam-Alj opened this issue Jul 20, 2023 · 0 comments · May be fixed by #1325
Open

Incorrect Optionality in Generated SDL for InputObject Fields With Defined Defaults #1321

Adam-Alj opened this issue Jul 20, 2023 · 0 comments · May be fixed by #1325
Labels
bug Something isn't working

Comments

@Adam-Alj
Copy link
Contributor

Adam-Alj commented Jul 20, 2023

Expected Behavior

When generating the SDL for an InputObject with defined defaults, the defaultable field should not be marked as required (no '!' type).

The following InputObject:

#[derive(InputObject)]
struct SampleInput {
    required_input: i32,

    #[graphql(default = 1)]
    optional_input: i32
}

Should generate the following SDL input definition:

input SampleInput {
	optionalInput: Int = 1
	requiredInput: Int!
}

Actual Behavior

The following SDL is generated with the optionalInput field marked as required:

input SampleInput {
	optionalInput: Int! = 1
	requiredInput: Int!
}

Steps to Reproduce the Problem

Use the following code to reproduce:

use async_graphql::{Schema, EmptyMutation, EmptySubscription, SDLExportOptions};
use async_graphql_derive::{InputObject, Object};

struct Query;

#[Object]
impl Query {
    async fn sample(&self, _input: SampleInput) -> i32 {
        1 
    } 
}

#[derive(InputObject)]
struct SampleInput {
    required_input: i32,

    #[graphql(default = 1)]
    optional_input: i32
}

fn main() {
    let schema = Schema::build(Query, EmptyMutation, EmptySubscription).finish();

    let sdl_opts = SDLExportOptions::new().sorted_arguments().sorted_fields();

    println!("{}", schema.sdl_with_options(sdl_opts));
}

Specifications

  • Version: 5.x, source
  • Platform: MacOS/Ubuntu
  • Subsystem: N/A
@Adam-Alj Adam-Alj added the bug Something isn't working label Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant