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

chore: RedwoodJS GraphQL subscription templates now use Dynamic Topic IDs #8766

Merged
merged 7 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const liveQueryStore = new InMemoryLiveQueryStore()
// Note: If you did not setup examples, please replace with your current subscriptions
import type { NewMessageChannel } from 'src/subscriptions/newMessage/newMessage'

// then use merge the types by intersecting each like: `NewMessageChannel<string> & OtherChannel`
export type PubSubChannels = NewMessageChannel<string>
// then use merge the types by intersecting each like: `NewMessageChannel & OtherChannel`
export type PubSubChannels = NewMessageChannel

export const pubSub = createPubSub<PubSubChannels>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ${subscriptionServiceResolver} = async (

const { id, from, body } = input

context.pubSub.publish(`${typeName}:<%= '$' %>{id}`, { from, body })
context.pubSub.publish('${typeName}', id, { from, body })

return input
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const schema = gql`
}
`
// Be sure to import this type and then in `api/src/lib/realtime.ts` extend PubSubChannels:
// export type PubSubChannels = ExistingChannel<string> & Publish${typeName}Channel<string>
export type Publish${typeName}Channel<T extends string> = {
[Key in `${typeName}:<%= '$' %>{T}`]: [payload: { from: string; body: string }]
// export type PubSubChannels = ExistingChannel<string> & Publish${typeName}Channel
export type Publish${typeName}Channel = {
${typeName}: [id: string, payload: { from: string; body: string }]
}

/**
Expand Down Expand Up @@ -38,7 +38,7 @@ const ${subscriptionName}Subscription = {
subscribe: (_, { id }, { pubSub }) => {
logger.debug({ id }, '${name} subscription')

return pubSub.subscribe(`${typeName}:<%= '$' %>{id}`)
return pubSub.subscribe('${typeName}', id)
},
resolve: (payload) => {
logger.debug({ payload }, '${name} subscription resolve')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const schema = gql`
newMessage(roomId: ID!): Message!
}
`
export type NewMessageChannel<T extends string> = {
[Key in `newMessage:${T}`]: [payload: { from: string; body: string }]
export type NewMessageChannel = {
newMessage: [roomId: string, payload: { from: string; body: string }]
}

/**
Expand Down Expand Up @@ -36,7 +36,7 @@ const newMessage = {
subscribe: (_, { roomId }, { pubSub }) => {
logger.debug({ roomId }, 'newMessage subscription')

return pubSub.subscribe(`newMessage:${roomId}`)
return pubSub.subscribe('newMessage', roomId)
},
resolve: (payload) => {
logger.debug({ payload }, 'newMessage subscription resolve')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const sendMessage = async (

const { roomId, from, body } = input

context.pubSub.publish(`newMessage:${roomId}`, { from, body })
context.pubSub.publish('newMessage', roomId, { from, body })

return input
}