Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(typescript): Request for adding different types(interfaces) for the query data from useQuery and subscribeToMore data #9946

Closed
arkajyotiMukherjee opened this issue Aug 25, 2020 · 2 comments · Fixed by #10066
Assignees

Comments

@arkajyotiMukherjee
Copy link

arkajyotiMukherjee commented Aug 25, 2020

const { subscribeToMore, data, loading, error } = useQuery<MyQueryInterface>(
   MY_QUERY_DOCUMENT
  );

The MyQueryInterface defines the variable data's type.
Now I have a use-case where the data from the Query is an array and the subscribeToMore subscription returns me any new array element that are created.
For example, the interface for query might be

interface MyQueryInterface {
  someArray: number[];
}

but my subscription data returns

interface MySubscriptionInterface {
  singleArrayElement: number;
}

Now in the subscribeToMore function I have to combine these two and it works fine if I do not type my query but if I do type them the subscription data doesn't have a someArray and it throws a type error.

If I could provide types for my subscription in subscribeToMore like I can give types to my query data and query variables...that would be nice.
Like:

const { subscribeToMore, data, loading, error } = useQuery<
    MyQueryInterface, MySubsriptionInterface, QueryVriableInterface
  >(
   MY_QUERY_DOCUMENT
  );

Do let me know if this feature is a duplicate or is not valid...I'll provide some more context.

EDIT:
This is not in the docs but I found this is possible and I solved the problem but don't know if this is the proper method.
I put an interface just before calling subscribeToMore like this:

subscribeToMore<MySubscriptionInterface>({
  document: SUBS_DOC,
  updateQuery: (prev, {subscriptionData}) => {
    ...
  }
})

If you think this solution is expected we can close this issue or take some steps to add it to the docs.
Thanks in advance.

@mahieyin-rahmun
Copy link

I agree that this should be in the docs. I was struggling with this until I found this issue. Thanks for sharing the solution/workaround!

@jpvajda
Copy link
Contributor

jpvajda commented Jul 26, 2022

@arkajyotiMukherjee thanks for reporting this, I'll move this over to the Apollo Client project and determine if we can make a documentation improvement on this topic.

@jpvajda jpvajda transferred this issue from apollographql/apollo-feature-requests Jul 26, 2022
@jpvajda jpvajda self-assigned this Jul 26, 2022
@bignimbus bignimbus assigned bignimbus and unassigned jpvajda Sep 2, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants