GraphQL Assignment-5
Basic Questions
- Write a query to fetch user(id:1) with only id and name.
- Write a query to fetch allUsers and include only name and email.
- Write a query that fetches a user’s posts with title only.
- Write a query that requests a field that does not exist and see the error.
- Write a query for getProduct(id:5) but request 15 nested fields (test over-fetching).
- Write a query that misses required fields in mutation createUser.
- Write a query for getOrders but limit results to 2.
- Write a query with variables to fetch a dynamic userId.
- Write a query alias to fetch user1: user(id:1) and user2: user(id:2) in the same request.
- Write a query fragment for User that fetches id, name, email.
- Write a query that tries to fetch deeply nested data (depth > 5) to test query depth limit.
- Write a query that retrieves allPosts but restricts fields to only title.
- Write a mutation createUser with wrong type for age (string instead of int).
- Write a query to fetch cached data from getTopProducts.
- Write a mutation that updates a post but misses required field title.
- Write a query for persisted query hash lookup (test persisted query).
- Write a query to fetch user(id:1) but request an unauthorized field (e.g., password).
- Write a query to test introspection (__schema { types { name } }).
- Write a query with invalid JSON input and observe the error.
- Write a query requesting same field twice with different aliases.
Intermediate Questions
- Write a query with fragment spreads across multiple types.
- Write a mutation with input type to create multiple users at once.
- Write a query with enum filter (e.g., getOrders(status: SHIPPED)).
- Write a query with nested filter (e.g., users with posts > 5).
- Write a query for allPosts with pagination (first:5, skip:5).
- Write a mutation updateUser and return only updated fields.
- Write a query using directives (@include(if:true) and @skip(if:false)).
- Write a query with variables for filtering products by price range.
- Write a query with fragment for Post type reused across multiple queries.
- Write a mutation createOrder with nested items array.
- Write a query using union type (e.g., search(query:”book”) returning User | Post).
- Write a query for interface type (node(id:”123″)).
- Write a query that fetches both users and their related orders in one request.
- Write a query with batching logic using DataLoader (usersByIds(ids:[1,2,3])).
- Write a query that intentionally exceeds allowed query cost.
- Write a query to simulate rate limiting (getUsers 10 times in a loop).
- Write a mutation deletePost(id:3) and return success flag.
- Write a query for subscriptions: newMessage with content and sender.
- Write a query to test role-based access (fetch salary field restricted to Admin).
- Write a query with invalid directive usage (e.g., @include on mutation).
Advanced Questions
- Write a query across federated services (user(id:1) from Users service and related orders from Orders service).
- Write a stitched schema query combining two endpoints (products + reviews).
- Write a subscription query for orderStatusUpdated(orderId:1).
- Write a persisted query with hash and execute without sending query string.
- Write a query that requests thousands of nested fields (to test DoS protection).
- Write a query for caching test: fetch getUser(id:1) twice and compare speed.
- Write a mutation createTransaction with nested payment and invoice.
- Write a query with custom directive @rateLimit(max:3) to test throttling.
- Write a query using multiple fragments + variables + aliases together.
- Write a full subscription-based query for chat (onNewMessage { id, content, sender }).