Add GraphQL News Broadcasting use case example#227
Add GraphQL News Broadcasting use case example#227Sachindu-Nethmin wants to merge 5 commits intowso2:mainfrom
Conversation
WalkthroughAdds a new tutorial documenting a real-time GraphQL News Broadcasting Service: GraphQL schema, queries/mutations/subscriptions, a custom Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In
`@en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.md`:
- Around line 318-323: The snippet's field declaration should be changed to
match the guidance: in class NewsGenerator replace the mutable field declaration
`private News[] newsItems;` with `private final News[] newsItems;` so the field
is immutable after construction; ensure the existing isolated init(News[]
newsItems) still assigns the cloned array to this.newsItems (using
newsItems.clone()) and leave the init method and class name (NewsGenerator,
init, newsItems) unchanged aside from the modifier update.
- Around line 321-323: The subscription init function currently clones the
newsItems snapshot, causing subscribers to miss future publishes; update init
(and any subscription setup) to retain a reference to the shared newsStorage (or
store a cursor/index into newsStorage) instead of calling newsItems.clone(), and
remove the behavior that immediately closes the stream when the referenced array
is empty—instead open the stream and deliver new items as they are appended by
publishNews (or iterate from the stored cursor through newsStorage so new
entries become visible to the subscriber). Ensure references to init,
publishNews, newsStorage, and newsItems are updated consistently so
subscriptions observe subsequent publishes.
🧹 Nitpick comments (1)
en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.md (1)
219-226: Reduce repeated “In the …” sentence starts for readability.These sections have three consecutive sentences starting with “In the …”. Consider rephrasing one or two sentences to improve flow.
Also applies to: 345-350
...ation-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.md
Show resolved
Hide resolved
| isolated function init(News[] newsItems) { | ||
| self.newsItems = newsItems.clone(); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, find the file
find . -name "*graphql-news-broadcasting-service.md" -type fRepository: wso2/docs-bi
Length of output: 164
🏁 Script executed:
# Read the file and examine the relevant sections
wc -l ./en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.mdRepository: wso2/docs-bi
Length of output: 168
🏁 Script executed:
# Read the init function section (lines 321-323)
sed -n '315,330p' ./en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.mdRepository: wso2/docs-bi
Length of output: 521
🏁 Script executed:
# Read the next() implementation section (lines 349-359)
sed -n '340,370p' ./en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.mdRepository: wso2/docs-bi
Length of output: 1483
🏁 Script executed:
# Read Step 12 and the complete next() implementation (lines 370-395)
sed -n '365,410p' ./en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.mdRepository: wso2/docs-bi
Length of output: 2026
🏁 Script executed:
# Read Step 15 and the publishNews expectations (lines 455-498)
sed -n '450,498p' ./en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.mdRepository: wso2/docs-bi
Length of output: 1906
🏁 Script executed:
# Let me examine the actual implementation steps more carefully
# to understand the complete flow described in the tutorial
sed -n '380,450p' ./en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.mdRepository: wso2/docs-bi
Length of output: 3336
🏁 Script executed:
# Check for the publishNews mutation implementation
sed -n '200,320p' ./en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.mdRepository: wso2/docs-bi
Length of output: 5090
Subscription stream won't receive newly published items due to array cloning.
The init function clones the newsItems array (Step 10, Line 322), which creates an isolated snapshot for each subscription. However, publishNews mutation adds items to the shared global newsStorage (Step 8). As a result, new mutations published after a subscription starts will not be visible to that subscriber's cloned copy. Additionally, if the array is empty at subscribe time, the stream returns () immediately (Step 11), ending it before any items can arrive. This contradicts Step 15's expectation that active subscriptions automatically receive broadcast updates.
To fix this, avoid cloning the array; instead, pass a reference to the shared storage or use a cursor-based approach to track the subscriber's read position while allowing new items to be visible to all active subscriptions.
🤖 Prompt for AI Agents
In
`@en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.md`
around lines 321 - 323, The subscription init function currently clones the
newsItems snapshot, causing subscribers to miss future publishes; update init
(and any subscription setup) to retain a reference to the shared newsStorage (or
store a cursor/index into newsStorage) instead of calling newsItems.clone(), and
remove the behavior that immediately closes the stream when the referenced array
is empty—instead open the stream and deliver new items as they are appended by
publishNews (or iterate from the stored cursor through newsStorage so new
entries become visible to the subscriber). Ensure references to init,
publishNews, newsStorage, and newsItems are updated consistently so
subscriptions observe subsequent publishes.
…iable access modifier for data integrity
…he GraphQL News Broadcasting Service guide.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.md`:
- Line 331: Update the documentation instruction to require the newsItems field
inside the service class be declared as private final (not just private) to
enforce immutability; specifically, change the guidance referencing the
newsItems variable so readers are told to mark it as private final within the
service class.
🧹 Nitpick comments (3)
en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.md (3)
3-3: Remove the contraction from the heading.The heading uses a contraction. Microsoft Style Guide recommends avoiding contractions in formal documentation.
✏️ Suggested fix
-## What you'll build +## What you will buildAs per coding guidelines, follow the Microsoft Style Guide for all documentation changes.
28-28: Use a more formal tone for the heading.The heading "Let's get started!" uses a contraction and an exclamation mark, which creates an informal tone. Microsoft Style Guide recommends formal, straightforward language in technical documentation.
✏️ Suggested fix
-## Let's get started! +## Get startedAs per coding guidelines, follow the Microsoft Style Guide for all documentation changes.
221-221: Consider varying sentence starters for better readability.Multiple consecutive sentences begin with "In the" at Lines 221, 347, and 349. While grammatically correct, varying sentence structure improves readability and flow.
Example alternatives:
- Line 221: "Within the Declare Variable pane:" or "Configure the following in the Declare Variable pane:"
- Line 347: "Within the Resource Design view, click..." or "Click the + icon..."
- Line 349: "Click the Condition field within the If pane..." or "Configure the condition..."
As per coding guidelines, follow the Microsoft Style Guide for all documentation changes.
Also applies to: 347-347, 349-349
| } | ||
| ``` | ||
|
|
||
| 4. Ensure the `newsItems` variable is marked as `private` to maintain data integrity within the service class. |
There was a problem hiding this comment.
Update the instruction to mention the final modifier.
The instruction states "Ensure the newsItems variable is marked as private" but does not mention marking it as final. Based on the previous review comment and best practices for immutability, the instruction should explicitly direct readers to use private final.
✏️ Proposed fix
-4. Ensure the `newsItems` variable is marked as `private` to maintain data integrity within the service class.
+4. Ensure the `newsItems` variable is marked as `private final` to maintain data integrity and immutability within the service class.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 4. Ensure the `newsItems` variable is marked as `private` to maintain data integrity within the service class. | |
| 4. Ensure the `newsItems` variable is marked as `private final` to maintain data integrity and immutability within the service class. |
🤖 Prompt for AI Agents
In
`@en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.md`
at line 331, Update the documentation instruction to require the newsItems field
inside the service class be declared as private final (not just private) to
enforce immutability; specifically, change the guidance referencing the
newsItems variable so readers are told to mark it as private final within the
service class.
Purpose
The purpose of this PR is to add a new comprehensive use case to the documentation titled "GraphQL News Broadcasting Service".
Goals
This PR introduces a step-by-step guide to achieve the following:
NewsGeneratorclass to manage the stream iteration protocol required for subscriptions.Screencast.from.2026-02-12.08-35-10.webm
Summary by CodeRabbit