GraphQL Assignment-5

Basic Questions

  1. Write a query to fetch user(id:1) with only id and name.
  2. Write a query to fetch allUsers and include only name and email.
  3. Write a query that fetches a user’s posts with title only.
  4. Write a query that requests a field that does not exist and see the error.
  5. Write a query for getProduct(id:5) but request 15 nested fields (test over-fetching).
  6. Write a query that misses required fields in mutation createUser.
  7. Write a query for getOrders but limit results to 2.
  8. Write a query with variables to fetch a dynamic userId.
  9. Write a query alias to fetch user1: user(id:1) and user2: user(id:2) in the same request.
  10. Write a query fragment for User that fetches id, name, email.
  11. Write a query that tries to fetch deeply nested data (depth > 5) to test query depth limit.
  12. Write a query that retrieves allPosts but restricts fields to only title.
  13. Write a mutation createUser with wrong type for age (string instead of int).
  14. Write a query to fetch cached data from getTopProducts.
  15. Write a mutation that updates a post but misses required field title.
  16. Write a query for persisted query hash lookup (test persisted query).
  17. Write a query to fetch user(id:1) but request an unauthorized field (e.g., password).
  18. Write a query to test introspection (__schema { types { name } }).
  19. Write a query with invalid JSON input and observe the error.
  20. Write a query requesting same field twice with different aliases.

 Intermediate Questions

  1. Write a query with fragment spreads across multiple types.
  2. Write a mutation with input type to create multiple users at once.
  3. Write a query with enum filter (e.g., getOrders(status: SHIPPED)).
  4. Write a query with nested filter (e.g., users with posts > 5).
  5. Write a query for allPosts with pagination (first:5, skip:5).
  6. Write a mutation updateUser and return only updated fields.
  7. Write a query using directives (@include(if:true) and @skip(if:false)).
  8. Write a query with variables for filtering products by price range.
  9. Write a query with fragment for Post type reused across multiple queries.
  10. Write a mutation createOrder with nested items array.
  11. Write a query using union type (e.g., search(query:”book”) returning User | Post).
  12. Write a query for interface type (node(id:”123″)).
  13. Write a query that fetches both users and their related orders in one request.
  14. Write a query with batching logic using DataLoader (usersByIds(ids:[1,2,3])).
  15. Write a query that intentionally exceeds allowed query cost.
  16. Write a query to simulate rate limiting (getUsers 10 times in a loop).
  17. Write a mutation deletePost(id:3) and return success flag.
  18. Write a query for subscriptions: newMessage with content and sender.
  19. Write a query to test role-based access (fetch salary field restricted to Admin).
  20. Write a query with invalid directive usage (e.g., @include on mutation).

 Advanced Questions

  1. Write a query across federated services (user(id:1) from Users service and related orders from Orders service).
  2. Write a stitched schema query combining two endpoints (products + reviews).
  3. Write a subscription query for orderStatusUpdated(orderId:1).
  4. Write a persisted query with hash and execute without sending query string.
  5. Write a query that requests thousands of nested fields (to test DoS protection).
  6. Write a query for caching test: fetch getUser(id:1) twice and compare speed.
  7. Write a mutation createTransaction with nested payment and invoice.
  8. Write a query with custom directive @rateLimit(max:3) to test throttling.
  9. Write a query using multiple fragments + variables + aliases together.
  10. Write a full subscription-based query for chat (onNewMessage { id, content, sender }).