TBD

Outline

THis works

type Foo = {
  bars: Array<Bar>;
};
type Bar = {
  baz: String;
};

const x: Foo["bars"][0]["baz"] = "123";

but it's pretty ugly & won't be reusable

Sequoia McDowell 7:38 PM I am still mulling over the “how to use types for queries that only query some fields” question…

❓ WHY NOT JUST ACCESS THE PROPERTY? Like TrackingStatusFragment[‘courier’] —> This works for single properties but not for arrays 7:38 PM for example, this is my fragment for the TrackingOrderStatus (which I use in the Order query to get the stuff for that component) export type TrackingOrderStatusStuffFragment = ( { typename?: 'Job' } & { courier: Maybe<( { typename?: 'Courier' } & Pick & { img: Maybe<( { typename?: 'Image' } & Pick )>, vehicle: Maybe<( { typename?: 'Vehicle' } & Pick )> } )>, pickupInfo: ( { typename?: 'LocationInfo' } & Pick & { img: Maybe<( { typename?: 'Image' } & Pick )> } ), trackingDisplayInfo: Maybe & { tooltip: Maybe<( { **typename?: 'Tooltip' } & Pick )> } )>> } );

7:40 PM now when I have a function that looks through the trackingDisplayInfo array to pick out the active one (we get all statuses or something, and just find the active one), the type I’m passing to that function getActiveTrackingDisplayInfo is TrackingOrderStatusStuffFragment['trackingDisplayInfo'] (I think)

7:40 PM but the one status item that gets returned is an item in this array: trackingDisplayInfo: Maybe & { tooltip: Maybe<( { **typename?: 'Tooltip' } & Pick )> } )>>

7:40 PM and if it’s possible to reference this type directly, I don’t know how

7:42 PM SentryAPP 7:42 PM

TypeError SyntaxError: Unexpected token '<'  BUYER-WEB-PROD-1MH7 via Will Sabransky | Jan 10th Resolve... Ignore

7:42 PM Sequoia McDowell 7:42 PM some options:

7:47 PM some opinions:

7:48 PM option 4 is of course “always query all required fields for a type” which would screw up one of the main benefits we’re getting from graphQL now which is tailoring queries to reduce bandwidth usage (I think)

7:49 PM I’m currently doing 2 but I don’t like it. I feel like this is sort of fundamental aspect of using types generated from graphql & I/we are going to run into issues like this a lot as we use the generated types, and that’s why I’m giving it more thought & attention. (if it were just a 1 off I wouldn’t worry about it).

7:49 PM I plan to try 3

7:58 PM Sequoia McDowell 7:58 PM OK that worked 

7:58 PM fragment TrackingOrderStatusStuff on Job { courier { displayName # avatar img { templatedUrl # avatar } # for line 2 vehicle { make model color } } pickupInfo { displayName # avatar title img { templatedUrl # avatar } } trackingDisplayInfo { ...orderStatusInfo } }

fragment orderStatusInfo on TrackingInfo { active state # to find "terminal" states for progress bar title subtitle tooltip { title # for line 2 subtitle # for modal } }

7:59 PM export type OrderStatusInfoFragment = ( { typename?: 'TrackingInfo' } & Pick & { tooltip: Maybe<( { typename?: 'Tooltip' } & Pick )> } );

const getActiveStatus = (statuses: Array): OrderStatusInfoFragment|undefined => { return statuses.find(status => status && status.active); }

Leave a Comment