GraphQL Assignment-3
Basic Questions
- Create a MySQL database graphql_db with table users(id, name, email).
- Connect GraphQL server to MySQL using mysql2 package.
- Write resolver getUsers to fetch all users from MySQL.
- Write resolver getUser(id:ID!) to fetch one user.
- Add mutation addUser(name:String!, email:String!): User with MySQL insert.
- Implement resolver updateUserEmail(id:ID!, email:String!): User.
- Write query builder with Knex.js to fetch all users.
- Use Knex.js to insert new user via mutation.
- Connect Sequelize ORM and define User model.
- Use Sequelize to fetch all users inside GraphQL resolver.
- Create posts(id, title, user_id) table in MySQL.
- Define GraphQL schema type Post { id, title, user: User }.
- Write resolver to fetch posts with their user (one-to-many).
- Add mutation addPost(userId:ID!,title:String!): Post.
- Implement resolver with Sequelize for addPost.
- Write GraphQL query to fetch all users with their posts.
- Write GraphQL query using alias to fetch user data twice with different names.
- Add filtering query: fetch posts where title contains a given keyword.
- Add pagination query for posts with arguments (limit:Int,offset:Int).
- Test MySQL query result inside GraphQL Playground.
Intermediate Questions
- Create MySQL table tags(id,name) and relation posts_tags(post_id,tag_id).
- Define GraphQL schema for Tag with many-to-many relation to Post.
- Write resolver to fetch tags of a post.
- Write resolver to fetch posts under a tag.
- Implement mutation addTagToPost(postId:ID!, tagId:ID!): Post.
- Create MongoDB database graphql_mongo and collection users.
- Connect GraphQL server with MongoDB using mongoose.
- Define mongoose model UserSchema { name:String, email:String }.
- Write resolver getUsers to fetch all users from MongoDB.
- Write mutation addUser(name:String,email:String): User with mongoose.
- Create PostSchema { title:String, userId:ObjectId } in MongoDB.
- Implement nested query: fetch users with their posts.
- Add resolver addPost(title:String,userId:ID!): Post in MongoDB.
- Implement query with MongoDB filter: find posts with keyword in title.
- Write query with pagination in MongoDB (limit & skip).
- Create nested schema Comment { id, text, postId }.
- Fetch posts with nested comments from MongoDB.
- Implement mutation addComment(postId:ID!, text:String!): Comment.
- Combine MySQL + MongoDB: fetch users from MySQL and posts from MongoDB.
- Write a resolver that merges results from two databases.
Advanced Questions
- Implement cursor-based pagination for posts in MySQL using GraphQL.
- Create resolver for filtering users with multiple conditions (age > 25 AND name contains “a”).
- Implement advanced search query using Sequelize scopes.
- Create GraphQL union type SearchResult = User | Post from MySQL.
- Write query search(keyword:String!): [SearchResult] with Knex.js.
- Add GraphQL directive @auth to restrict access to mutation addPost.
- Implement batch resolver using DataLoader
- for MySQL user-post relation.
- Use MongoDB aggregation pipeline in resolver to fetch post counts per user.
- Implement resolver that joins MongoDB users with MySQL posts.