-
Notifications
You must be signed in to change notification settings - Fork 24
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 support for variables #23
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
package me.lazmaid.kraph.lang | ||
|
||
import me.lazmaid.kraph.KraphVariable | ||
|
||
/** | ||
* Created by OinkIguana on 10/25/2017 AD. | ||
*/ | ||
|
||
// TODO: implement variables | ||
internal class Variables() { | ||
fun print(): String? = null | ||
internal class Variables { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the node should implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be confusing if Variables implements GraphQLNode, since the parameters of print (format: PrintFormat, previousLevel: Int) don't make any sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this moment, It may not make sense much to make it implement |
||
|
||
val variables = mutableMapOf<String, KraphVariable>() | ||
|
||
fun print(): String? = variables | ||
.takeIf { it.isNotEmpty() } | ||
?.let { | ||
it.entries.joinToString(separator = ",", prefix = "{", postfix = "}") { "\"${it.key}\": ${it.value.jsonValue}" } | ||
} | ||
|
||
fun asArgument(): Argument? = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, this should be an extension of this class more than a member function itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really care. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is no different in this case. You may leave it like this. |
||
variables.takeIf { it.isNotEmpty() } | ||
?.let { Argument(it.values.map { it.dollarName to it.type }.toMap()) } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these 2 classes deserve their own package. Maybe we can have the package for custom GraphQL type. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean a package that has a class with only those 2 lines of code?
Or any other class as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, It would be another package with a file contain these 2 classes