This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"errors": [ | |
{ | |
"message": "Internal Server Error(s) while executing query" | |
} | |
], | |
"data": null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query getComments { | |
comment { | |
body | |
user{ | |
id | |
name | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Comment { | |
body: String | |
user: User | |
} | |
type User{ | |
id: ID | |
name: String | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Comment { | |
body: String | |
userId: ID | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Mutation { | |
addComment(input: AddCommentInput!): Comment | |
} | |
input AddCommentInput { | |
userId: ID | |
body: String | |
} | |
type Comment { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"errors": [ | |
{ | |
"message": | |
"Exception while fetching data (/getCar) : Car with name = B Class not found", | |
"path": [ | |
"getCar" | |
], | |
"extensions": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
class CarService { | |
fun getCar(input: String): Car { | |
return CarMap.cars[input] | |
?: throw CarNotFoundException("Car with name = $input not found", | |
mapOf("name" to input)) | |
} | |
fun createCar(input: CarInput): Car { | |
val car = Car(input.name, input.price, input.engineType) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GraphQLException extends RuntimeException implements GraphQLError { | |
String customMessage; | |
public GraphQLException(String customMessage) { | |
this.customMessage = customMessage; | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class CarNotFoundException( | |
errorMessage: String? = "", | |
private val parameters: Map<String, Any>? = mutableMapOf() | |
) : GraphQLException(errorMessage) { | |
override val message: String? | |
get() = super.message | |
override fun getExtensions(): MutableMap<String, Any> { | |
return mutableMapOf("parameters" to (parameters ?: mutableMapOf())) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
class CarService { | |
fun getCar(input: String): Car { | |
return CarMap.cars[input]!! | |
} | |
fun createCar(input: CarInput): Car { | |
val car = Car(input.name, input.price, input.engineType) | |
CarMap.cars[input.name] = car | |
return car |