@@ -4,7 +4,8 @@ import type { Consumer, Subscription } from "@rails/actioncable"
44
55type ActionCableFetcherOptions = {
66 consumer : Consumer ,
7- url : String ,
7+ url : string ,
8+ channelName ?: string ,
89 fetch ?: typeof fetch ,
910 fetchOptions ?: any ,
1011}
@@ -17,6 +18,8 @@ type SubscriptionIteratorPayload = {
1718export default function createActionCableFetcher ( options : ActionCableFetcherOptions ) {
1819 let currentChannel : Subscription | null = null
1920 const consumer = options . consumer
21+ const url = options . url || "/graphql"
22+ const channelName = options . channelName || "GraphqlChannel"
2023
2124 const subscriptionFetcher = async function * ( graphqlParams : any , fetcherOpts : any ) {
2225 let isSubscription = false ;
@@ -32,7 +35,7 @@ export default function createActionCableFetcher(options: ActionCableFetcherOpti
3235
3336 if ( isSubscription ) {
3437 currentChannel ?. unsubscribe ( )
35- currentChannel = consumer . subscriptions . create ( "GraphqlChannel" ,
38+ currentChannel = consumer . subscriptions . create ( channelName ,
3639 {
3740 connected : function ( ) {
3841 currentChannel ?. perform ( "execute" , {
@@ -75,7 +78,7 @@ export default function createActionCableFetcher(options: ActionCableFetcherOpti
7578 } else {
7679 const fetchFn = options . fetch || window . fetch
7780 // Not a subscription fetcher, post to the given URL
78- yield fetchFn ( "/graphql" , {
81+ yield fetchFn ( url , {
7982 method : "POST" ,
8083 body : JSON . stringify ( {
8184 query : graphqlParams . query ,
0 commit comments