0
0
GraphQLquery~30 mins

Subscription lifecycle in GraphQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Subscription Lifecycle Management with GraphQL
📖 Scenario: You are building a simple subscription management system for a magazine service. Customers can subscribe to different magazines, and you want to track their subscription status and details using GraphQL.
🎯 Goal: Create a GraphQL schema and queries to manage and retrieve subscription lifecycle data, including subscriber information, subscription plans, and status.
📋 What You'll Learn
Define a GraphQL type Subscriber with fields id, name, and email.
Define a GraphQL type Subscription with fields id, subscriberId, plan, and status.
Create a query subscriptions to retrieve all subscriptions.
Create a query activeSubscriptions to retrieve subscriptions with status ACTIVE.
💡 Why This Matters
🌍 Real World
Subscription lifecycle management is common in services like magazines, streaming platforms, and SaaS products to track user subscriptions and their status.
💼 Career
Understanding GraphQL schema design and queries is essential for backend developers working with modern APIs and subscription-based services.
Progress0 / 4 steps
1
Define Subscriber and Subscription Types
Define a GraphQL type called Subscriber with fields id of type ID!, name of type String!, and email of type String!. Also define a GraphQL type called Subscription with fields id of type ID!, subscriberId of type ID!, plan of type String!, and status of type String!.
GraphQL
Hint

Use type keyword to define GraphQL types. Use ! to mark fields as required.

2
Add Query Type with subscriptions Field
Add a GraphQL Query type with a field called subscriptions that returns a list of Subscription objects. Use [Subscription!]! as the return type to indicate a non-null list of non-null subscriptions.
GraphQL
Hint

Define a Query type with a field returning a list of subscriptions.

3
Add activeSubscriptions Query with Status Filter
Add a field called activeSubscriptions to the Query type that returns a list of Subscription objects with status ACTIVE. Use the same return type [Subscription!]!.
GraphQL
Hint

Add the activeSubscriptions field to the Query type with the correct return type.

4
Complete Schema with Subscription Status Enum
Add an enum type called SubscriptionStatus with values ACTIVE, CANCELLED, and PAUSED. Update the status field in Subscription type to use SubscriptionStatus! instead of String!.
GraphQL
Hint

Use enum to define fixed status values and update the status field type accordingly.