8000 Incorrect Optionality in Generated SDL for InputObject Fields With Defined Defaults · Issue #1321 · async-graphql/async-graphql · GitHub
[go: up one dir, main page]

Skip to content
Incorrect Optionality in Generated SDL for InputObject Fields With Defined Defaults #1321
Open
@Adam-Alj

Description

@Adam-Alj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0