Skip to content

Commit 6355fd2

Browse files
committed
Temporal Type Definitions
1 parent e1fe6e2 commit 6355fd2

File tree

2 files changed

+148
-1
lines changed

2 files changed

+148
-1
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package org.neo4j.graphql
2+
3+
import java.time.*
4+
import java.time.temporal.Temporal
5+
6+
fun temporalTypeDefinitions(config: Translator.Context, types: Set<Class<Temporal>>) =
7+
when {
8+
config.temporal -> temporalTypeDefinitions.filter { types.contains(it.type) }
9+
.flatMap { listOf(it.output.second to it.input.second) }
10+
.joinToString("\n")
11+
else -> ""
12+
}
13+
14+
data class TypeDefinition(val name: String, val type: Class<out Temporal>, val output:Pair<String,String>, val input:Pair<String,String>)
15+
16+
val temporalTypeDefinitions = listOf(
17+
TypeDefinition(
18+
"LocalTime", OffsetTime::class.java,
19+
"_Neo4jTime" to """
20+
type _Neo4jTime {
21+
hour: Int
22+
minute: Int
23+
second: Int
24+
millisecond: Int
25+
microsecond: Int
26+
nanosecond: Int
27+
timezone: String
28+
formatted: String
29+
}
30+
""",
31+
"_Neo4jTimeInput" to """
32+
input _Neo4jTimeInput {
33+
hour: Int
34+
minute: Int
35+
second: Int
36+
nanosecond: Int
37+
millisecond: Int
38+
microsecond: Int
39+
timezone: String
40+
formatted: String
41+
}
42+
"""),
43+
TypeDefinition(
44+
"Date", LocalDate::class.java,
45+
"_Neo4jDate" to """
46+
type _Neo4jDate {
47+
year: Int
48+
month: Int
49+
day: Int
50+
formatted: String
51+
}
52+
""",
53+
"_Neo4jDateInput" to """
54+
input _Neo4jDateInput {
55+
year: Int
56+
month: Int
57+
day: Int
58+
formatted: String
59+
}
60+
"""),
61+
TypeDefinition(
62+
"DateTime",LocalDateTime::class.java,
63+
"_Neo4jDateTime" to """
64+
type _Neo4jDateTime {
65+
year: Int
66+
month: Int
67+
day: Int
68+
hour: Int
69+
minute: Int
70+
second: Int
71+
millisecond: Int
72+
microsecond: Int
73+
nanosecond: Int
74+
timezone: String
75+
formatted: String
76+
}
77+
""",
78+
"_Neo4jDateTimeInput" to """
79+
input _Neo4jDateTimeInput {
80+
year: Int
81+
month: Int
82+
day: Int
83+
hour: Int
84+
minute: Int
85+
second: Int
86+
millisecond: Int
87+
microsecond: Int
88+
nanosecond: Int
89+
timezone: String
90+
formatted: String
91+
}
92+
"""),
93+
TypeDefinition(
94+
"Time", Instant::class.java,
95+
"_Neo4jLocalTime" to """
96+
type _Neo4jLocalTime {
97+
hour: Int
98+
minute: Int
99+
second: Int
100+
millisecond: Int
101+
microsecond: Int
102+
nanosecond: Int
103+
formatted: String
104+
}
105+
""",
106+
"_Neo4jLocalTimeInput" to """
107+
input _Neo4jLocalTimeInput {
108+
hour: Int
109+
minute: Int
110+
second: Int
111+
millisecond: Int
112+
microsecond: Int
113+
nanosecond: Int
114+
formatted: String
115+
}
116+
"""),
117+
TypeDefinition(
118+
"LocalDateTime", OffsetDateTime::class.java,
119+
"_Neo4jLocalDateTime" to """
120+
type _Neo4jLocalDateTime {
121+
year: Int
122+
month: Int
123+
day: Int
124+
hour: Int
125+
minute: Int
126+
second: Int
127+
millisecond: Int
128+
microsecond: Int
129+
nanosecond: Int
130+
formatted: String
131+
}
132+
""",
133+
"_Neo4jLocalDateTimeInput" to """
134+
input _Neo4jLocalDateTimeInput {
135+
year: Int
136+
month: Int
137+
day: Int
138+
hour: Int
139+
minute: Int
140+
second: Int
141+
millisecond: Int
142+
microsecond: Int
143+
nanosecond: Int
144+
formatted: String
145+
}
146+
""")
147+
)

src/main/kotlin/org/neo4j/graphql/Translator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.antlr.v4.runtime.misc.ParseCancellationException
1212
import java.util.*
1313

1414
class Translator(val schema: GraphQLSchema) {
15-
data class Context @JvmOverloads constructor(val topLevelWhere: Boolean = true, val fragments : Map<String,FragmentDefinition> = emptyMap())
15+
data class Context @JvmOverloads constructor(val topLevelWhere: Boolean = true, val fragments : Map<String,FragmentDefinition> = emptyMap(),val temporal : Boolean = false)
1616
data class Cypher( val query: String, val params : Map<String,Any?> = emptyMap()) {
1717
companion object {
1818
val EMPTY = Cypher("")

0 commit comments

Comments
 (0)