Skip to content

Commit d9f3ac9

Browse files
authored
Support augmentation of enum fields (#310)
Co-authored-by: isstabb <6967489+isstabb@users.noreply.github.com>
1 parent 21ef768 commit d9f3ac9

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

core/src/main/kotlin/org/neo4j/graphql/AugmentationHandler.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ abstract class AugmentationHandler(
291291

292292
fun ImplementingTypeDefinition<*>.getScalarFields(): List<FieldDefinition> = fieldDefinitions
293293
.filterNot { it.isIgnored() }
294-
.filter { it.type.inner().isScalar() || it.type.inner().isNeo4jType() }
294+
.filter { it.type.inner().isScalar() || it.type.inner().isNeo4jType() || it.type.inner().isEnum() }
295295
.sortedByDescending { it.type.inner().isID() }
296296

297297
fun ImplementingTypeDefinition<*>.getFieldDefinition(name: String) = this.fieldDefinitions
@@ -304,6 +304,7 @@ abstract class AugmentationHandler(
304304

305305
fun Type<*>.resolve(): TypeDefinition<*>? = getTypeFromAnyRegistry(name())
306306
fun Type<*>.isScalar(): Boolean = resolve() is ScalarTypeDefinition
307+
fun Type<*>.isEnum(): Boolean = resolve() is EnumTypeDefinition
307308
private fun Type<*>.isNeo4jType(): Boolean = name()
308309
?.takeIf {
309310
!ScalarInfo.GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.containsKey(it)

core/src/test/resources/augmentation-tests.adoc

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
[source,graphql,schema=true]
88
----
99
interface HasMovies { movies:[Movie] }
10+
enum MovieType { documentary, action }
1011
type Person0 { name: String, born: _Neo4jTime, location: _Neo4jPoint }
1112
type Person1 { name: String, born: _Neo4jDate }
1213
type Person2 { name: String, age: Int, born: _Neo4jDateTime }
1314
type Person3 { name: String!, born: _Neo4jLocalTime }
1415
type Person4 { id:ID!, name: String, born: _Neo4jLocalDateTime }
1516
type Person5 implements HasMovies { id:ID!, movies:[Movie] @relation(name: "LIKES")}
16-
type Movie { id:ID!, publishedBy: Publisher @relation(name: "PUBLISHED_BY")}
17+
type Movie { id:ID!, movieType: MovieType, publishedBy: Publisher @relation(name: "PUBLISHED_BY")}
1718
type Publisher { name:ID! }
1819
type Knows0 @relation(name:"KNOWS", from: "source", to: "knows"){
1920
id: ID!
@@ -96,14 +97,15 @@ type Knows4 {
9697
9798
type Movie {
9899
id: ID!
100+
movieType: MovieType
99101
publishedBy: Publisher
100102
}
101103
102104
type Mutation {
103105
addMoviePublishedBy(id: ID!, publishedBy: ID!): Movie!
104106
addPerson5Movies(id: ID!, movies: [ID!]!): Person5!
105107
createKnows4(json: DynamicProperties, knows_id: ID!, source_id: ID!): Knows4!
106-
createMovie(id: ID!): Movie!
108+
createMovie(id: ID!, movieType: MovieType): Movie!
107109
createPerson1(born: _Neo4jDateInput, name: String): Person1!
108110
createPerson2(age: Int, born: _Neo4jDateTimeInput, name: String): Person2!
109111
createPerson3(born: _Neo4jLocalTimeInput, name: String!): Person3!
@@ -128,9 +130,11 @@ type Mutation {
128130
deletePublisher(name: ID!): Publisher
129131
mergeKnows0(id: ID!, json: DynamicProperties): Knows0!
130132
mergeKnows4(_id: ID!, json: DynamicProperties): Knows4!
133+
mergeMovie(id: ID!, movieType: MovieType): Movie!
131134
mergePerson4(born: _Neo4jLocalDateTimeInput, id: ID!, name: String): Person4!
132135
updateKnows0(id: ID!, json: DynamicProperties): Knows0
133136
updateKnows4(_id: ID!, json: DynamicProperties): Knows4
137+
updateMovie(id: ID!, movieType: MovieType): Movie
134138
updatePerson4(born: _Neo4jLocalDateTimeInput, id: ID!, name: String): Person4
135139
}
136140
@@ -274,6 +278,11 @@ type _Neo4jTime {
274278
timezone: String
275279
}
276280
281+
enum MovieType {
282+
action
283+
documentary
284+
}
285+
277286
enum RelationDirection {
278287
BOTH
279288
IN
@@ -283,6 +292,8 @@ enum RelationDirection {
283292
enum _MovieOrdering {
284293
id_asc
285294
id_desc
295+
movieType_asc
296+
movieType_desc
286297
}
287298
288299
enum _Person0Ordering {
@@ -381,7 +392,7 @@ schema {
381392
}
382393
383394
interface HasMovies {
384-
movies(filter: _MovieFilter, first: Int, id: ID, id_contains: ID, id_ends_with: ID, id_gt: ID, id_gte: ID, id_in: [ID!], id_lt: ID, id_lte: ID, id_matches: ID, id_not: ID, id_not_contains: ID, id_not_ends_with: ID, id_not_in: [ID!], id_not_starts_with: ID, id_starts_with: ID, offset: Int, orderBy: [_MovieOrdering!]): [Movie]
395+
movies(filter: _MovieFilter, first: Int, id: ID, id_contains: ID, id_ends_with: ID, id_gt: ID, id_gte: ID, id_in: [ID!], id_lt: ID, id_lte: ID, id_matches: ID, id_not: ID, id_not_contains: ID, id_not_ends_with: ID, id_not_in: [ID!], id_not_starts_with: ID, id_starts_with: ID, movieType: MovieType, movieType_in: [MovieType!], movieType_not: MovieType, movieType_not_in: [MovieType!], offset: Int, orderBy: [_MovieOrdering!]): [Movie]
385396
}
386397
387398
type Knows0 {
@@ -406,6 +417,7 @@ type Knows4 {
406417
407418
type Movie {
408419
id: ID!
420+
movieType: MovieType
409421
publishedBy: Publisher
410422
}
411423
@@ -439,7 +451,7 @@ type Person4 {
439451
440452
type Person5 implements HasMovies {
441453
id: ID!
442-
movies(filter: _MovieFilter, first: Int, id: ID, id_contains: ID, id_ends_with: ID, id_gt: ID, id_gte: ID, id_in: [ID!], id_lt: ID, id_lte: ID, id_matches: ID, id_not: ID, id_not_contains: ID, id_not_ends_with: ID, id_not_in: [ID!], id_not_starts_with: ID, id_starts_with: ID, offset: Int, orderBy: [_MovieOrdering!]): [Movie]
454+
movies(filter: _MovieFilter, first: Int, id: ID, id_contains: ID, id_ends_with: ID, id_gt: ID, id_gte: ID, id_in: [ID!], id_lt: ID, id_lte: ID, id_matches: ID, id_not: ID, id_not_contains: ID, id_not_ends_with: ID, id_not_in: [ID!], id_not_starts_with: ID, id_starts_with: ID, movieType: MovieType, movieType_in: [MovieType!], movieType_not: MovieType, movieType_not_in: [MovieType!], offset: Int, orderBy: [_MovieOrdering!]): [Movie]
443455
}
444456
445457
type Publisher {
@@ -452,7 +464,7 @@ type Query {
452464
knows0(filter: _Knows0Filter, first: Int, id: ID, id_contains: ID, id_ends_with: ID, id_gt: ID, id_gte: ID, id_in: [ID!], id_lt: ID, id_lte: ID, id_matches: ID, id_not: ID, id_not_contains: ID, id_not_ends_with: ID, id_not_in: [ID!], id_not_starts_with: ID, id_starts_with: ID, offset: Int, orderBy: [_Knows0Ordering!]): [Knows0!]!
453465
knows1(filter: _Knows1Filter, first: Int, id: ID, id_contains: ID, id_ends_with: ID, id_gt: ID, id_gte: ID, id_in: [ID!], id_lt: ID, id_lte: ID, id_matches: ID, id_not: ID, id_not_contains: ID, id_not_ends_with: ID, id_not_in: [ID!], id_not_starts_with: ID, id_starts_with: ID, offset: Int, orderBy: [_Knows1Ordering!]): [Knows1!]!
454466
knows4(_id: ID, filter: _Knows4Filter, first: Int, offset: Int, orderBy: [_Knows4Ordering!]): [Knows4!]!
455-
movie(filter: _MovieFilter, first: Int, id: ID, id_contains: ID, id_ends_with: ID, id_gt: ID, id_gte: ID, id_in: [ID!], id_lt: ID, id_lte: ID, id_matches: ID, id_not: ID, id_not_contains: ID, id_not_ends_with: ID, id_not_in: [ID!], id_not_starts_with: ID, id_starts_with: ID, offset: Int, orderBy: [_MovieOrdering!]): [Movie!]!
467+
movie(filter: _MovieFilter, first: Int, id: ID, id_contains: ID, id_ends_with: ID, id_gt: ID, id_gte: ID, id_in: [ID!], id_lt: ID, id_lte: ID, id_matches: ID, id_not: ID, id_not_contains: ID, id_not_ends_with: ID, id_not_in: [ID!], id_not_starts_with: ID, id_starts_with: ID, movieType: MovieType, movieType_in: [MovieType!], movieType_not: MovieType, movieType_not_in: [MovieType!], offset: Int, orderBy: [_MovieOrdering!]): [Movie!]!
456468
person1(born: _Neo4jDateInput, born_in: [_Neo4jDateInput!], born_not: _Neo4jDateInput, born_not_in: [_Neo4jDateInput!], filter: _Person1Filter, first: Int, name: String, name_contains: String, name_ends_with: String, name_gt: String, name_gte: String, name_in: [String!], name_lt: String, name_lte: String, name_matches: String, name_not: String, name_not_contains: String, name_not_ends_with: String, name_not_in: [String!], name_not_starts_with: String, name_starts_with: String, offset: Int, orderBy: [_Person1Ordering!]): [Person1!]!
457469
person2(age: Int, age_gt: Int, age_gte: Int, age_in: [Int!], age_lt: Int, age_lte: Int, age_not: Int, age_not_in: [Int!], born: _Neo4jDateTimeInput, born_in: [_Neo4jDateTimeInput!], born_not: _Neo4jDateTimeInput, born_not_in: [_Neo4jDateTimeInput!], filter: _Person2Filter, first: Int, name: String, name_contains: String, name_ends_with: String, name_gt: String, name_gte: String, name_in: [String!], name_lt: String, name_lte: String, name_matches: String, name_not: String, name_not_contains: String, name_not_ends_with: String, name_not_in: [String!], name_not_starts_with: String, name_starts_with: String, offset: Int, orderBy: [_Person2Ordering!]): [Person2!]!
458470
person3(born: _Neo4jLocalTimeInput, born_in: [_Neo4jLocalTimeInput!], born_not: _Neo4jLocalTimeInput, born_not_in: [_Neo4jLocalTimeInput!], filter: _Person3Filter, first: Int, name: String, name_contains: String, name_ends_with: String, name_gt: String, name_gte: String, name_in: [String!], name_lt: String, name_lte: String, name_matches: String, name_not: String, name_not_contains: String, name_not_ends_with: String, name_not_in: [String!], name_not_starts_with: String, name_starts_with: String, offset: Int, orderBy: [_Person3Ordering!]): [Person3!]!
@@ -560,6 +572,11 @@ type _Neo4jTime {
560572
timezone: String
561573
}
562574
575+
enum MovieType {
576+
action
577+
documentary
578+
}
579+
563580
enum RelationDirection {
564581
BOTH
565582
IN
@@ -588,6 +605,8 @@ enum _Knows4Ordering {
588605
enum _MovieOrdering {
589606
id_asc
590607
id_desc
608+
movieType_asc
609+
movieType_desc
591610
}
592611
593612
enum _Person0Ordering {
@@ -803,6 +822,10 @@ input _MovieFilter {
803822
id_not_in: [ID]
804823
id_not_starts_with: ID
805824
id_starts_with: ID
825+
movieType: MovieType
826+
movieType_in: [MovieType]
827+
movieType_not: MovieType
828+
movieType_not_in: [MovieType]
806829
"Filters only those `Movie` for which the `publishedBy`-relationship matches this filter. If `null` is passed to this field, only those `Movie` will be filtered which has no `publishedBy`-relations"
807830
publishedBy: _PublisherFilter
808831
"@deprecated Use the `publishedBy_not`-field"
@@ -1155,14 +1178,15 @@ type Knows4 {
11551178
11561179
type Movie {
11571180
id: ID!
1181+
movieType: MovieType
11581182
publishedBy: Publisher
11591183
}
11601184
11611185
type Mutation {
11621186
addMoviePublishedBy(id: ID!, publishedBy: ID!): Movie!
11631187
addPerson5Movies(id: ID!, movies: [ID!]!): Person5!
11641188
createKnows4(json: DynamicProperties, knows_id: ID!, source_id: ID!): Knows4!
1165-
createMovie(id: ID!): Movie!
1189+
createMovie(id: ID!, movieType: MovieType): Movie!
11661190
createPerson5(id: ID!): Person5!
11671191
createPublisher(name: ID!): Publisher!
11681192
"Deletes Knows0 and returns the type itself"
@@ -1181,8 +1205,10 @@ type Mutation {
11811205
deletePublisher(name: ID!): Publisher
11821206
mergeKnows0(id: ID!, json: DynamicProperties): Knows0!
11831207
mergeKnows4(_id: ID!, json: DynamicProperties): Knows4!
1208+
mergeMovie(id: ID!, movieType: MovieType): Movie!
11841209
updateKnows0(id: ID!, json: DynamicProperties): Knows0
11851210
updateKnows4(_id: ID!, json: DynamicProperties): Knows4
1211+
updateMovie(id: ID!, movieType: MovieType): Movie
11861212
}
11871213
11881214
type Person0 {
@@ -1325,6 +1351,11 @@ type _Neo4jTime {
13251351
timezone: String
13261352
}
13271353
1354+
enum MovieType {
1355+
action
1356+
documentary
1357+
}
1358+
13281359
enum RelationDirection {
13291360
BOTH
13301361
IN
@@ -1334,6 +1365,8 @@ enum RelationDirection {
13341365
enum _MovieOrdering {
13351366
id_asc
13361367
id_desc
1368+
movieType_asc
1369+
movieType_desc
13371370
}
13381371
13391372
enum _Person0Ordering {

0 commit comments

Comments
 (0)