Skip to content

Comments

Add GraphQL News Broadcasting use case example#227

Open
Sachindu-Nethmin wants to merge 5 commits intowso2:mainfrom
Sachindu-Nethmin:graphql-news-broadcasting-service
Open

Add GraphQL News Broadcasting use case example#227
Sachindu-Nethmin wants to merge 5 commits intowso2:mainfrom
Sachindu-Nethmin:graphql-news-broadcasting-service

Conversation

@Sachindu-Nethmin
Copy link
Contributor

@Sachindu-Nethmin Sachindu-Nethmin commented Jan 20, 2026

Purpose

The purpose of this PR is to add a new comprehensive use case to the documentation titled "GraphQL News Broadcasting Service".

  • Defining custom data types (Records) visually.
  • Implementing GraphQL Mutations to handle data input.
  • Configuring GraphQL Subscriptions using Service Classes to broadcast real-time updates.

Goals

This PR introduces a step-by-step guide to achieve the following:

  • Service Creation: Set up a GraphQL service with a dedicated base path and listener.
  • Logic Implementation: Use the Resource Design view to implement in-memory storage and shifting logic for news items.
  • Real-time Streaming: Implement a NewsGenerator class to manage the stream iteration protocol required for subscriptions.
  • Integrated Testing: Provide a clear workflow for testing Queries, Mutations, and Subscriptions using the built-in GraphiQL tool.
Screencast.from.2026-02-12.08-35-10.webm

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive tutorial for a real-time GraphQL News Broadcasting Service, covering end-to-end setup, API operations (queries, mutations, subscriptions), streaming behavior, and interactive run/test scenarios with examples.
    • Updated site navigation to include the new GraphQL integration use-case guide for easier discovery.

@Sachindu-Nethmin Sachindu-Nethmin changed the title Graphql news broadcasting service Add GraphQL News Broadcasting use case example Jan 20, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

Walkthrough

Adds a new tutorial documenting a real-time GraphQL News Broadcasting Service: GraphQL schema, queries/mutations/subscriptions, a custom NewsGenerator service with in-memory persistence and streaming subscription workflow, plus workspace, run, and test instructions.

Changes

Cohort / File(s) Summary
Documentation
en/docs/integration-guides/usecases/graphql-news-broadcasting-service/graphql-news-broadcasting-service.md
New comprehensive tutorial describing GraphQL service setup at /news, schema and operation definitions (allNews, publishNews, generateNews), in-memory news storage, NewsGenerator service class implementation and streaming iteration, subscription wiring, and end-to-end run/test steps.
Navigation
en/mkdocs.yml
Added a navigation entry under Data Mapper -> Use Cases linking to the new GraphQL News Broadcasting Service tutorial.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble docs and plant a seed,
Headlines hop forth at lightning speed,
Queries call and subscribers cheer,
I stream fresh news from ear to ear,
Hooray — the rabbit broadcast's here! 🎉📡

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a GraphQL News Broadcasting use case example, which aligns with the documentation file and navigation update in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description covers the main required sections with clear purpose, goals, and approach details including a screencast reference.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +321 to +323
isolated function init(News[] newsItems) {
self.newsItems = newsItems.clone();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, find the file
find . -name "*graphql-news-broadcasting-service.md" -type f

Repository: 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.md

Repository: 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.md

Repository: 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.md

Repository: 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.md

Repository: 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.md

Repository: 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.md

Repository: 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.md

Repository: 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.

@Sachindu-Nethmin Sachindu-Nethmin marked this pull request as draft January 22, 2026 06:34
@Sachindu-Nethmin Sachindu-Nethmin marked this pull request as ready for review February 11, 2026 17:23
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 build

As 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 started

As 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant