I am creating a microanuat and kotlin app using grapqhl but when trying with curl am
getting an error which i have pasted below the code, am trying to figure wher i am going wrong
import graphql.ExecutionInput
import graphql.GraphQL
import io.micronaut.http.annotation.Controller
import io.micron " curl -X POST -H "Content-Type: application/json" -d '{
"query": "mutation {
createItem(name: "New Item", description: "Description of the new item") {
id
name
description
}
}"
}' https://localhost:8080/graphql
{"_links":{"self":[{"href":"/graphql","templated":false}]},"_embedded":{"errors":[{"message":"Method [POST] not allowed for URI [/graphql]. Allowed methods: [HEAD, GET]"}]},"message":"Method Not Allowed"}aut.http.annotation.Post
import io.micronaut.http.HttpRequest
@Controller("/graphql")
class GraphQLController(private val graphQL: GraphQL) {
@Post
fun executeQuery(request: HttpRequest<String>): Any {
val executionInput = ExecutionInput.newExecutionInput()
.query(request.body.orElse(""))
.build()
return graphQL.execute(executionInput)
}
}
import graphql.GraphQL
import graphql.schema.GraphQLSchema
import javax.inject.Singleton
@Singleton
class GraphQLConfiguration(private val graphQLSchema: GraphQLSchema) {
@Singleton
fun graphQL(): GraphQL {
return GraphQL.newGraphQL(graphQLSchema).build()
}
}
type Item {
id: ID!
name: String!
description: String
}
type Query {
getAllItems: [Item]
getItemById(id: ID!): Item
}
type Mutation {
createItem(name: String!, description: String): Item
updateItem(id: ID!, name: String!, description: String): Item
deleteItem(id: ID!): Boolean
}
@Singleton
@Transactional
class ItemGraphQL(private val itemRepository: ItemRepository) : GraphQLQueryResolver, GraphQLMutationResolver {
@ReadOnly
fun getAllItems(): List<Item> {
return itemRepository.findAll()
}
@ReadOnly
fun getItemById(id: Long): Item? {
return itemRepository.findById(id).orElse(null)
}
fun createItem(name: String, description: String): Item {
val item = Item(name = name, description = description)
return itemRepository.save(item)
}
fun updateItem(id: Long, name: String, description: String): Item {
val item = itemRepository.findById(id).orElseThrow { NoSuchElementException("Item not found") }
item.name = name
item.description = description
return itemRepository.update(item)
}
fun deleteItem(id: Long): Boolean {
itemRepository.deleteById(id)
return true
}
}
{"_links":{"self":[{"href":"/graphql","templated":false}]},"_embedded":{"errors":[{"message":"Internal Server Error: Failed to inject value for parameter [graphQL] of class: shoprite.moneymarket.GraphQLControllernnMessage: No bean of type [graphql.GraphQL] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for ‘io.micronaut.context.condition’ to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the ‘micronaut-inject-java’ dependency should be configured as an annotation processor).nPath Taken: new GraphQLController(GraphQL graphQL) –> new GraphQLController([GraphQL graphQL])"}]},"message":"Internal Server Error"}