GraphQL Assignment-2
Basic Questions
- Define a schema with Movie { id, title, rating }.
- Write query getMovies that returns all movies.
- Implement resolver for getMovie(id:ID!): Movie.
- Create mutation addMovie(title:String!,rating:Int!): Movie.
- Define input MovieInput { title:String!, rating:Int! } and use it in mutation.
- Implement resolver for addMovie(input:MovieInput!): Movie.
- Create an enum Genre { ACTION, DRAMA, COMEDY }.
- Extend Movie type with genre: Genre.
- Write mutation updateGenre(id:ID!,genre:Genre!): Movie.
- Implement resolver to update movie genre.
- Define custom scalar Date for releaseDate.
- Use Date scalar in Movie type and fetch formatted dates.
- Create a schema type Actor { id, name, age }.
- Write query to fetch all actors.
- Implement resolver getActor(id:ID!): Actor.
- Write mutation addActor(name:String!,age:Int!): Actor.
- Define a query with variables to fetch movie by title.
- Use alias to fetch movie title twice under different names.
- Write query with fragment for common fields id, title.
- Test query with variables in GraphQL Playground.
Intermediate Questions
- Extend schema: Actor { movies: [Movie] }.
- Implement resolver to return movies for an actor.
- Create nested query: fetch actor and their movies.
- Add mutation assignActorToMovie(actorId:ID!,movieId:ID!): Movie.
- Implement resolver for assignActorToMovie.
- Create Director { id, name, age }.
- Extend Movie type with director: Director.
- Write nested query to fetch movie with director info.
- Define interface Person { id, name }.
- Implement Actor and Director as implements Person.
- Write query returning a list of Person (actors + directors).
- Define union SearchResult = Movie | Actor.
- Write query search(keyword:String!): [SearchResult].
- Implement resolver for union type SearchResult.
- Use directive @deprecated on a field oldRating.
- Test query using deprecated field.
- Implement @include(if:Boolean) directive in query.
- Implement @skip(if:Boolean) directive in query.
- Create mutation updateActorAge(id:ID!,age:Int!): Actor.
- Test mutation with variables in Playground.
Advanced Questions
- Design schema where User has relationships with Posts and Comments.
- Write nested query: user → posts → comments.
- Implement resolver with multiple nested resolvers.
- Add directive @auth (custom) on query getUsers.
- Implement resolver to check authentication before returning data.
- Use fragments to fetch nested fields for both Actor and Director.
- Implement query that fetches multiple types with fragments.
- Create mutation with input type RegisterUserInput.
- Add resolver for registerUser mutation with validation.
- Implement advanced query with variables + fragments + alias combined.