You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, let me say - this is a fantastic library which has really improved by graphql experience. One issue I often have... I'll have a query/subscription or mutation which returns child entities. Eg)
I'll then often have to use the type of the child somewhere, for example in a react component that just deals with rendering the child. I try and accomplish this by picking something from the subscription type, eg GetParentWithChildSubscription['parent_by_pk']['children'] or Requred<GetParentWithChildSubscription['parent_by_pk']>['children']. In some instances this works but in this particular case I get the following error:
Property 'children' does not exist on type '({ __typename?: "parents" | undefined; } & Pick<Parent, "id" | "name"> & { children: ({ __typename?: "child" | undefined; } & Pick<Child, "id" | "name">)[]; }) | null | undefined'.ts(2339)
Describe the solution you'd like
Would it make sense to export named types for these child properties. These would need to be namespaced by the query name and the path to the property. Eg)
Hi @MrBlenny !
This was discussed a long ago here, please read this for tips and solutions: #2735 (comment)
Basically, this works in your example, but in large projects, those types are getting duplicated, and you get non-readable types (User_Something_Something_Something_1) and so on, and far more complex to maintain.
First, let me say - this is a fantastic library which has really improved by graphql experience. One issue I often have... I'll have a query/subscription or mutation which returns child entities. Eg)
This will generate the following code:
I'll then often have to use the type of the child somewhere, for example in a react component that just deals with rendering the child. I try and accomplish this by picking something from the subscription type, eg
GetParentWithChildSubscription['parent_by_pk']['children']
orRequred<GetParentWithChildSubscription['parent_by_pk']>['children']
. In some instances this works but in this particular case I get the following error:Describe the solution you'd like
Would it make sense to export named types for these child properties. These would need to be namespaced by the query name and the path to the property. Eg)
The text was updated successfully, but these errors were encountered: