Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ID scalar type to BUILT_IN_TYPE #173

Open
ima9dan opened this issue Dec 12, 2021 · 0 comments
Open

Add ID scalar type to BUILT_IN_TYPE #173

ima9dan opened this issue Dec 12, 2021 · 0 comments

Comments

@ima9dan
Copy link

ima9dan commented Dec 12, 2021

The graphql specification states that id scalar type should be supported by all graphql servers.
Therefore, I think that it is necessary to add the ID type to "BUILT_IN_TYPE" even in kgraphql.

[graphql specification]
http://spec.graphql.org/October2021/

At present, it can be realized in each project by the following method, but I think that it should be provided by default of kgraphql, but what about?

// define
class ID(var value:String) {
    override fun toString():String {
        return value
    }
}

// make scalar type
fun SchemaBuilder.schemaScalar() {
    stringScalar<ID> {
        description = "ID"
        deserialize = { it:String -> ID(it) }
        serialize = { it: ID -> it.toString() }
    }
}

// option. convenient to have
fun String.toID():ID {
    return ID(this)
}

//  make data class
data class User(var id:ID, var name:String)

val user = User("user01".toID(), "Hathaway Noa")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant