Skip to content

FragmentStore's _Data type argument does not accomodate @loading fragment's data shape #1388

@gwennlbh

Description

@gwennlbh

Describe the bug

The current definition of FragmentStore enforces that _Data extends GraphQLObject:

export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType extends {}, _Input extends GraphQLVariables = GraphQLVariables> {

which is defined as follows:

export type GraphQLObject = {
    [key: string]: GraphQLValue;
};
export type GraphQLDefaultScalar = string | number | boolean;
export type GraphQLValue = GraphQLDefaultScalar | null | GraphQLObject | GraphQLValue[] | undefined;

however, @loading fragments' $data types are defined with a union to represent the loading state, that uses typeof PendingValue, but declare that they return FragmentStore instances.

This prevents library users from retrieveing the $data type given a FragmentStore instance type, somthing which is useufl to extend the library with generic utilities around loading states (i'm working on a Loading class that would allow .map-ing obejcts in potentially loading states for much better ergonomics, insteada of having to pass things to utility functions as I currently do)

See further discussion at https://discordapp.com/channels/1024421016405016718/1305501698244214794/1305501698244214794

Reproduction

https://stackblitz.com/edit/github-t4rqmk?file=src%2Flib%2Findex.ts&view=editor

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