@@ -4,7 +4,8 @@ import type { Consumer, Subscription } from "@rails/actioncable"
4
4
5
5
type ActionCableFetcherOptions = {
6
6
consumer : Consumer ,
7
- url : String ,
7
+ url : string ,
8
+ channelName ?: string ,
8
9
fetch ?: typeof fetch ,
9
10
fetchOptions ?: any ,
10
11
}
@@ -17,6 +18,8 @@ type SubscriptionIteratorPayload = {
17
18
export default function createActionCableFetcher ( options : ActionCableFetcherOptions ) {
18
19
let currentChannel : Subscription | null = null
19
20
const consumer = options . consumer
21
+ const url = options . url || "/graphql"
22
+ const channelName = options . channelName || "GraphqlChannel"
20
23
21
24
const subscriptionFetcher = async function * ( graphqlParams : any , fetcherOpts : any ) {
22
25
let isSubscription = false ;
@@ -32,7 +35,7 @@ export default function createActionCableFetcher(options: ActionCableFetcherOpti
32
35
33
36
if ( isSubscription ) {
34
37
currentChannel ?. unsubscribe ( )
35
- currentChannel = consumer . subscriptions . create ( "GraphqlChannel" ,
38
+ currentChannel = consumer . subscriptions . create ( channelName ,
36
39
{
37
40
connected : function ( ) {
38
41
currentChannel ?. perform ( "execute" , {
@@ -75,7 +78,7 @@ export default function createActionCableFetcher(options: ActionCableFetcherOpti
75
78
} else {
76
79
const fetchFn = options . fetch || window . fetch
77
80
// Not a subscription fetcher, post to the given URL
78
- yield fetchFn ( "/graphql" , {
81
+ yield fetchFn ( url , {
79
82
method : "POST" ,
80
83
body : JSON . stringify ( {
81
84
query : graphqlParams . query ,
0 commit comments