Skip to content

Problem with nonnull fields and @include directives #250

Open
@MikailBag

Description

@MikailBag

I have following request:

query ListRuns($detailed: Boolean!) {
    submissions {
        id,
        problem @include(if: $detailed),
        score @include(if: $detailed),
        status @include(if: $detailed) {
            kind,
            code
        },
        toolchainName @include(if: $detailed)
    }
}

When I execute this request with $detailed: true, my program receives required data successfully.
But when $detailed: false, instead of success I get error:

Error(Json(Error("missing field `problem`", line: 1, column: 32)))

Some my thoughts on why is it happening

related fragments from schema:

type Query {
    submissions(...): [Run!]!
}

type Run {
    id: Int!
    problem: String!
    score: Int
    status: InvokeStatusOut!
    toolchainName: String!
}

So, graphql-client sees, that almost all fields on Run are non-nullable, and emits following definiion (taken from cargo-expand output):

// (inside mod list_runs)
pub struct ListRunsSubmissions {
            pub id: Int,
            pub problem: String,
            pub score: Option<Int>,
            pub status: ListRunsSubmissionsStatus,
            #[serde(rename = "toolchainName")]
            pub toolchain_name: String,
}

To my mind, fields problem, status and toolchain_name should be marked as optional, because they are included in query conditionally.

However, I see that they are still non-nullable, and when they are missing in server reply because of detailed=false, deserialization fails.

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