Skip to content

Commit

Permalink
prettifier
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsamson7 committed Oct 7, 2024
1 parent 2b1b8d1 commit 1468e37
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 43 deletions.
4 changes: 1 addition & 3 deletions src/main/kotlin/org/sirius/dorm/graphql/ObjectMutator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ package org.sirius.dorm.graphql
import org.sirius.dorm.ObjectManager
import org.sirius.dorm.model.AttributeDescriptor
import org.sirius.dorm.model.ObjectDescriptor
import org.sirius.dorm.model.PropertyDescriptor
import org.sirius.dorm.`object`.DataObject
import kotlin.reflect.full.isSuperclassOf


class ObjectMutator(val objectManager: ObjectManager) {
// bulk update

fun bulkUpdate(descriptor: ObjectDescriptor, results: List<DataObject>, input: Map<String,Any>) : Array<DataObject> {
fun bulkUpdate(results: List<DataObject>, input: Map<String,Any>) : Array<DataObject> {
for ( obj in results)
writeProperties(obj, input)

Expand Down
59 changes: 19 additions & 40 deletions src/main/kotlin/org/sirius/dorm/graphql/SchemaBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SchemaBuilder(val objectManager: ObjectManager) {
.dataFetcher {
it.getSource<DataObject>()!!.get(it.field.name)
}
.type(type4(field.asAttribute().baseType()))
.type(type4<GraphQLOutputType>(field.asAttribute().baseType()))
)
else {
if ( field.asRelation().multiplicity.mutliValued) {
Expand Down Expand Up @@ -92,7 +92,7 @@ class SchemaBuilder(val objectManager: ObjectManager) {
inputObject.field(
GraphQLInputObjectField.newInputObjectField()
.name(field.name)
.type(inputType4(field.asAttribute().baseType()))
.type(type4<GraphQLInputType>(field.asAttribute().baseType()))
)
else {
if ( field.asRelation().multiplicity.mutliValued) {
Expand Down Expand Up @@ -144,8 +144,8 @@ class SchemaBuilder(val objectManager: ObjectManager) {
GraphQLInputObjectField.newInputObjectField()
.name(property.name)
.type(when ( property.asAttribute().baseType()) {
String::class.javaObjectType -> booleanFilter
String::class.javaObjectType -> stringFilter
Boolean::class.javaObjectType -> booleanFilter
Short::class.javaObjectType -> intFilter
Int::class.javaObjectType -> intFilter
Long::class.javaObjectType -> intFilter
Expand Down Expand Up @@ -224,7 +224,7 @@ class SchemaBuilder(val objectManager: ObjectManager) {
.dataFetcher {
executeBulkUpdate(descriptor, it)
}
.type(GraphQLList.list(GraphQLTypeReference.typeRef("${descriptor.name}")))
.type(GraphQLList.list(GraphQLTypeReference.typeRef(descriptor.name)))
)

// delete
Expand Down Expand Up @@ -260,22 +260,22 @@ class SchemaBuilder(val objectManager: ObjectManager) {
}

private fun executeCreate(descriptor: ObjectDescriptor, environment: DataFetchingEnvironment) : DataObject {
return mutator.create(descriptor, environment.getArgument<Any>("input") as Map<String,Any>)
return mutator.create(descriptor, environment.getArgument<Map<String,Any>>("input")!!)
}

private fun executeUpdate(descriptor: ObjectDescriptor, environment: DataFetchingEnvironment) : DataObject {
return mutator.update(descriptor, environment.getArgument<Any>("input") as Map<String,Any>)
return mutator.update(descriptor, environment.getArgument<Map<String,Any>>("input")!!)
}

private fun executeBulkUpdate(descriptor: ObjectDescriptor, environment: DataFetchingEnvironment) : Array<DataObject> {
val where = environment.getArgument<Any>("where") as Map<String,Any>
val input = environment.getArgument<Any>("input") as Map<String,Any>
val where = environment.getArgument<Map<String,Any>>("where")
val input = environment.getArgument<Map<String,Any>>("input")!!

return mutator.bulkUpdate(descriptor, queryBuilder.buildQuery(descriptor, where).execute().getResultList(), input)
return mutator.bulkUpdate(queryBuilder.buildQuery(descriptor, where).execute().getResultList(), input)
}

private fun executeDelete(descriptor: ObjectDescriptor, environment: DataFetchingEnvironment) : Int {
val result = queryBuilder.buildQuery(descriptor, environment.getArgument<Any>("where") as Map<String,Any>).execute().getResultList()
val result = queryBuilder.buildQuery(descriptor, environment.getArgument<Map<String,Any>>("where")).execute().getResultList()

for ( value in result)
objectManager.delete(value)
Expand Down Expand Up @@ -354,55 +354,34 @@ class SchemaBuilder(val objectManager: ObjectManager) {
private fun floatFilter() : GraphQLInputObjectType {
return GraphQLInputObjectType.newInputObject()
.name("FloatFilter")
.field(
GraphQLInputObjectField.newInputObjectField()
.field(GraphQLInputObjectField.newInputObjectField()
.name("lt")
.type(Scalars.GraphQLFloat)
)
.field(
GraphQLInputObjectField.newInputObjectField()
.field(GraphQLInputObjectField.newInputObjectField()
.name("le")
.type(Scalars.GraphQLFloat)
)
.field(
GraphQLInputObjectField.newInputObjectField()
.field(GraphQLInputObjectField.newInputObjectField()
.name("gt")
.type(Scalars.GraphQLFloat)
)
.field(
GraphQLInputObjectField.newInputObjectField()
.field(GraphQLInputObjectField.newInputObjectField()
.name("ge")
.type(Scalars.GraphQLFloat)
)
.field(
GraphQLInputObjectField.newInputObjectField()
.field(GraphQLInputObjectField.newInputObjectField()
.name("eq")
.type(Scalars.GraphQLInt)
.type(Scalars.GraphQLFloat)
)
.field(
GraphQLInputObjectField.newInputObjectField()
.field(GraphQLInputObjectField.newInputObjectField()
.name("ne")
.type(Scalars.GraphQLFloat)
)
.build()
}

private fun inputType4(clazz : Class<*>) : GraphQLInputType {
return when ( clazz ) {
Boolean::class.javaObjectType -> Scalars.GraphQLBoolean
Int::class.javaObjectType -> Scalars.GraphQLInt
Short::class.javaObjectType -> Scalars.GraphQLInt
Long::class.javaObjectType -> Scalars.GraphQLInt
Float::class.javaObjectType -> Scalars.GraphQLFloat
Double::class.javaObjectType -> Scalars.GraphQLFloat
String::class.javaObjectType -> Scalars.GraphQLString
else -> {
throw Error("unsupported type ${clazz}")
}
}
}

private fun type4(clazz : Class<*>) : GraphQLOutputType {
private fun <T:GraphQLType>type4(clazz : Class<*>) : T {
return when ( clazz ) {
Boolean::class.javaObjectType -> Scalars.GraphQLBoolean
Int::class.javaObjectType -> Scalars.GraphQLInt
Expand All @@ -414,6 +393,6 @@ class SchemaBuilder(val objectManager: ObjectManager) {
else -> {
throw Error("unsupported type ${clazz}")
}
}
} as T
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/org/sirius/dorm/graphql/TODO-GRAPHQL.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ angular :-) mit builder simple

=== NOW

- kopieren nach service :-)
- entity status
- version counter
- date?

=== DONE
Expand Down

0 comments on commit 1468e37

Please sign in to comment.