Skip to content

Commit ba0f9f1

Browse files
brennantaylorsmyrick
authored andcommitted
fix: make deepName public and move to extensions package (#108)
It's a very handy utility method.
1 parent 36610c0 commit ba0f9f1

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.expedia.graphql.extensions
2+
3+
import graphql.schema.GraphQLList
4+
import graphql.schema.GraphQLNonNull
5+
import graphql.schema.GraphQLType
6+
7+
/**
8+
* Useful public extension that renders a readable string from the given
9+
* graphql type no matter how deeply nested it is.
10+
* Eg: [[Int!]]!
11+
*
12+
* @return a string representation of the type taking list and non-null into account
13+
*/
14+
val GraphQLType.deepName: String
15+
get() = when {
16+
this is GraphQLNonNull -> "${wrappedType.deepName}!"
17+
this is GraphQLList -> "[${wrappedType.deepName}]"
18+
else -> name
19+
}

src/main/kotlin/com/expedia/graphql/schema/extensions/graphQLTypeExtensions.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
package com.expedia.graphql.schema.extensions
22

33
import com.expedia.graphql.exceptions.NestingNonNullTypeException
4-
import graphql.schema.GraphQLList
54
import graphql.schema.GraphQLNonNull
65
import graphql.schema.GraphQLType
76
import kotlin.reflect.KType
87

9-
/**
10-
* Renders a readable string from the given graphql type no matter how deeply nested
11-
* Eg: [[Int!]]!
12-
*/
13-
internal val GraphQLType.deepName: String
14-
get() = when {
15-
this is GraphQLNonNull -> "${this.wrappedType.deepName}!"
16-
this is GraphQLList -> "[${this.wrappedType.deepName}]"
17-
else -> name
18-
}
19-
208
/**
219
* Map null and non-null types.
2210
* Throws an exception on wrapping a non-null graphql type twice.

src/test/kotlin/com/expedia/graphql/schema/dataFetchers/CustomDataFetcherTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.expedia.graphql.schema.dataFetchers
22

33
import com.expedia.graphql.TopLevelObjectDef
44
import com.expedia.graphql.schema.SchemaGeneratorConfig
5-
import com.expedia.graphql.schema.extensions.deepName
5+
import com.expedia.graphql.extensions.deepName
66
import com.expedia.graphql.toSchema
77
import graphql.GraphQL
88
import graphql.schema.DataFetcher

src/test/kotlin/com/expedia/graphql/schema/extensions/GraphQLTypeExtensionsTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.expedia.graphql.schema.extensions
22

33
import com.expedia.graphql.exceptions.NestingNonNullTypeException
4+
import com.expedia.graphql.extensions.deepName
45
import graphql.schema.GraphQLList
56
import graphql.schema.GraphQLNonNull
67
import graphql.schema.GraphQLType

src/test/kotlin/com/expedia/graphql/schema/generator/SchemaGeneratorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.expedia.graphql.annotations.GraphQLID
66
import com.expedia.graphql.annotations.GraphQLIgnore
77
import com.expedia.graphql.exceptions.ConflictingTypesException
88
import com.expedia.graphql.exceptions.InvalidIdTypeException
9-
import com.expedia.graphql.schema.extensions.deepName
9+
import com.expedia.graphql.extensions.deepName
1010
import com.expedia.graphql.schema.testSchemaConfig
1111
import com.expedia.graphql.toSchema
1212
import graphql.GraphQL

src/test/kotlin/com/expedia/graphql/schema/hooks/SchemaGeneratorHooksTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.expedia.graphql.schema.hooks
22

33
import com.expedia.graphql.TopLevelObjectDef
4-
import com.expedia.graphql.schema.extensions.deepName
4+
import com.expedia.graphql.extensions.deepName
55
import com.expedia.graphql.schema.getTestSchemaConfigWithHooks
66
import com.expedia.graphql.toSchema
77
import graphql.GraphQL

0 commit comments

Comments
 (0)