Skip to content

Instantly share code, notes, and snippets.

View aronbalog's full-sized avatar

Aron Balog aronbalog

View GitHub Profile
package com.example.demo.data
import org.springframework.data.mongodb.core.mapping.Document
import java.util.*
import javax.persistence.Id
@Document(collection="person")
data class Person(
@Id
val id: String = UUID.randomUUID().toString(),
package com.example.demo.repository
import com.example.demo.data.Person
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.stereotype.Repository
@Repository
interface PersonRepository : MongoRepository<Person, String> {
fun findByNameLike(name: String): List<Person>
}
package com.example.demo.dao
import com.example.demo.repository.PersonRepository
import org.springframework.stereotype.Component
@Component
class PersonDao(
private val personRepository: PersonRepository
) {
fun getPersonById(id: String) =
package com.example.demo.graphql.query
import com.coxautodev.graphql.tools.GraphQLQueryResolver
import com.example.demo.dao.PersonDao
import com.example.demo.data.Person
import org.springframework.stereotype.Component
@Component
class PersonQueryResolver(
private val personDao: PersonDao
type Query {
# The API Version
version: String!
# Get person with ID
person(id: ID!): Person
# Get persons by name
personsByName(name: String!): [Person]
}
package com.example.demo.graphql
import com.coxautodev.graphql.tools.GraphQLQueryResolver
import org.springframework.stereotype.Component
@Component
class Query: GraphQLQueryResolver {
fun version() = "1.0.0"
}
package com.example.demo.dao
import com.example.demo.repository.PersonRepository
import org.springframework.stereotype.Component
@Component
class PersonDao(
private val personRepository: PersonRepository
) {
fun getPersonById(id: String) =
package com.example.demo.graphql
import com.coxautodev.graphql.tools.GraphQLMutationResolver
import com.example.demo.dao.PersonDao
import com.example.demo.data.Person
import com.example.demo.graphql.input.PersonInput
import org.springframework.stereotype.Component
@Component
class Mutation(