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

Is there a defaultOptions for Subscription? #11411

Closed
iblislin opened this issue Dec 5, 2023 · 6 comments
Closed

Is there a defaultOptions for Subscription? #11411

iblislin opened this issue Dec 5, 2023 · 6 comments

Comments

@iblislin
Copy link

iblislin commented Dec 5, 2023

Hi,

I want to set the default errorPolicy for Subscription, but there aren't one for Subscript in the DefaultOptions. Are there any ways to set the default globally?

@phryneas
Copy link
Member

phryneas commented Dec 5, 2023

I'm sorry, but at this point we have no such option.

You could create your custom useSubscription hook for this:

const useSubscriptionWithDefaults: typeof useSubscription = (
  subscription,
  options
) => useSubscription(subscription, { errorPolicy: "myNewDefault", ...options });

@jerelmiller jerelmiller added the 🏓 awaiting-contributor-response requires input from a contributor label Dec 6, 2023
@iblislin
Copy link
Author

iblislin commented Dec 7, 2023

ah, thanks.

Any plans for support it in DefaultOptions?
I really need that cool option supported, since I'm using apollo-angular + codegen, and using a custom hook seems not applicable for codegen I guess.

I can try to make a PR and I'm wondering to know the concerns of adding it?

@github-actions github-actions bot removed the 🏓 awaiting-contributor-response requires input from a contributor label Dec 7, 2023
@bignimbus
Copy link
Contributor

Hi @iblislin 👋🏻 is it fair to say that you're looking for something like what's described here? apollographql/apollo-feature-requests#169

If so, the team would be happy to review a PR 🙏🏻

@alessbell
Copy link
Contributor

Hi @iblislin 👋 Circling back here. Since you're using apollo-angular, you could use a similar approach suggested by @phryneas but in Angular it would look something like:

const COMMENTS_SUBSCRIPTION = gql`
  subscription onCommentAdded($repoFullName: String!){
    commentAdded(repoFullName: $repoFullName){
      id
      content
    }
  }
`;

function subscribeWithDefaultOptions(options) {
  return apollo.subscribe({
    errorPolicy: "myNewDefault",
    ...options
  });
}

 
@Component({ ... })
class CommentsComponent {
  constructor(apollo: Apollo) {
    subscribeWithDefaultOptions({
      query: COMMENTS_SUBSCRIPTION,
      variables: {
        repoName: `kamilkisiela/apollo-angular`
      }
    }).subscribe((result) => {
      if (result.data?.commentAdded) {
        console.log('New comment:', result.data.commentAdded);
      }
    });
  }
}

Since we have a tracking issue for the feature request, I'll go ahead and close this issue out. If you have any other questions, feel free to drop by our Discord, too. Thanks!

@apollographql apollographql deleted a comment from github-actions bot Jan 31, 2024
@alessbell alessbell closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

github-actions bot commented Mar 2, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants