Skip to content

Instantly share code, notes, and snippets.

View maniish-jaiin's full-sized avatar
🎯
Focusing

Manish Jain maniish-jaiin

🎯
Focusing
View GitHub Profile
{
"data": {
"hello": "Hello World!"
}
}
@Configuration
class GraphQLConfig() {
@Bean
fun schemaParserDictionary(): SchemaParserDictionary {
return SchemaParserDictionary()
.add(IBike::class)
.add(ICar::class)
}
}
query{
getIVehicles{
... on Car{
name
price
engineType
}
... on Bike{
name
price
{
"data": {
"getIVehicles": [
{
"name": "BMW X1",
"price": 45000,
"engineType": "PETROL"
},
{
"name": "Ducati",
mutation createCar($input: CarInput){
createCar(input: $input) {
name
}
}
{
"errors": [
{
"message": "Internal Server Error(s) while executing query"
}
],
"data": null
}
query{
getCar(input: "B Class"){
name
}
}
type Query{
hello: String
getCar(input: String) : Car!
}
type Mutation{
createCar(input: CarInput): Car
}
type Car {
@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
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()))
}