Skip to content

Not possible to mark parent as @required if parent is nullable due to child being a nullable fragment #1410

@joleeee

Description

@joleeee

Describe the bug

TLDR; if a query has a fragment with a @required in a top level field, it bubbles up to the query, but it's not possible to mark the parent of the fragment spread @required.

Example:

I have a fragment

fragment AirportParts on airports @required {
    id
    location @required {
        city
    }
}

And i use it in a query

query MyQuery {
    flights {
        to {
            ...AirportParts @mask_disable
        }
    }
}

Naturally, it leads to a nullable to:

export type MyQuery$result = {
    /**
     * An array relationship
    */
    readonly flights: ({
        /**
         * An object relationship
        */
        readonly to: { // <----- to IS NULLABLE
            readonly id: number;
            readonly iata: string | null;
            /**
             * An object relationship
            */
            readonly location: {
                readonly city: string;
                readonly name: string;
            };
            readonly " $fragments": {
                AirportParts: {};
            };
        } | null; // <----- to IS NULLABLE
    })[];
};

However, it is not possible to mark the to as required:

If you try:

query MyQuery {
    flights {
-        to {
+        to @required {
            ...AirportParts @mask_disable
        }
    }
}
❌ Encountered error in src/routes/.../query.gql
@required may only be used on nullable fields

Reproduction

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions