Hello all - very thankful for this incredible framework! I’ve used it to build an internal app for my company over the past couple months, and the company loves it and is now putting resources into expanding it. It wouldn’t have been possible without RedwoodJS! Big fan.
I have two components to which I am passing an object that is queried/obtained by a parent cell. Rather than passing all of the various parameters that are needed (there are several). I prefer to pass the object itself. The problem I’m running into is that the GQL query used by the cell does not retrieve all of the objects - I don’t need them in the cell or any of the dependent components. But I get a TS2739 warning that some of the properties are missing on the object being passed to the component. The fields it’s complaining about are either arrays or objects. The arrays returned by Prisma may be empty - which is fine. But I don’t want to be querying additional relations/tables if unnecessary.
I can open the definition in graphql.d.ts and mark the fields as optional by adding a ‘?’ but that’s not really the point.
Is there a proper TypeScript way to do this, rather than just ignoring the warning? I don’t want to add the related objects to the cell query because they are unnecessary and I worry they’d waste bandwidth and computation power.
Definition in graphql.d.ts:
export type VideoClip = {
__typename?: 'VideoClip';
id: Scalars['Int'];
path: Scalars['String'];
eventRecord: EventRecord;
eventRecordId: Scalars['Int'];
dataValues: Array<Maybe<DataValue>>;
sequence: Scalars['Int'];
thumbnail: Scalars['String'];
relatedNotes: Array<Maybe<RelatedNote>>;
};
Specifically the fields it complains about are dataValues
, eventRecord
, and relatedNotes
.
The query in the cell:
export const QUERY = gql`
query FindVideoClipQuery($id: Int!) {
videoClip: videoClip(id: $id) {
id
sequence
path
thumbnail
eventRecordId
}
}
`
The exact warning:
TS2739: Type '{ __typename?: "VideoClip"; id: number; sequence: number; path: string; thumbnail: string; dispname: string; eventRecordId: number; }' is missing the following properties from type 'VideoClip': eventRecord, dataValues, relatedNotes
And I’m trying to pass it as follows:
<VideoClipThumbnail videoClip={videoClip} />
With the component interface defined as such:
import type { VideoClip } from 'types/graphql'
interface Props {
videoClip: VideoClip
}
export const VideoClipThumbnail = ({ videoClip }: Props) => {