Skip to content

Commit

Permalink
fix: make deepName public and move to extensions package (#108)
Browse files Browse the repository at this point in the history
It's a very handy utility method.
  • Loading branch information
brennantaylor authored and smyrick committed Dec 20, 2018
1 parent 36610c0 commit ba0f9f1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
19 changes: 19 additions & 0 deletions src/main/kotlin/com/expedia/graphql/extensions/deepName.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.expedia.graphql.extensions

import graphql.schema.GraphQLList
import graphql.schema.GraphQLNonNull
import graphql.schema.GraphQLType

/**
* Useful public extension that renders a readable string from the given
* graphql type no matter how deeply nested it is.
* Eg: [[Int!]]!
*
* @return a string representation of the type taking list and non-null into account
*/
val GraphQLType.deepName: String
get() = when {
this is GraphQLNonNull -> "${wrappedType.deepName}!"
this is GraphQLList -> "[${wrappedType.deepName}]"
else -> name
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
package com.expedia.graphql.schema.extensions

import com.expedia.graphql.exceptions.NestingNonNullTypeException
import graphql.schema.GraphQLList
import graphql.schema.GraphQLNonNull
import graphql.schema.GraphQLType
import kotlin.reflect.KType

/**
* Renders a readable string from the given graphql type no matter how deeply nested
* Eg: [[Int!]]!
*/
internal val GraphQLType.deepName: String
get() = when {
this is GraphQLNonNull -> "${this.wrappedType.deepName}!"
this is GraphQLList -> "[${this.wrappedType.deepName}]"
else -> name
}

/**
* Map null and non-null types.
* Throws an exception on wrapping a non-null graphql type twice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.expedia.graphql.schema.dataFetchers

import com.expedia.graphql.TopLevelObjectDef
import com.expedia.graphql.schema.SchemaGeneratorConfig
import com.expedia.graphql.schema.extensions.deepName
import com.expedia.graphql.extensions.deepName
import com.expedia.graphql.toSchema
import graphql.GraphQL
import graphql.schema.DataFetcher
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.expedia.graphql.schema.extensions

import com.expedia.graphql.exceptions.NestingNonNullTypeException
import com.expedia.graphql.extensions.deepName
import graphql.schema.GraphQLList
import graphql.schema.GraphQLNonNull
import graphql.schema.GraphQLType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.expedia.graphql.annotations.GraphQLID
import com.expedia.graphql.annotations.GraphQLIgnore
import com.expedia.graphql.exceptions.ConflictingTypesException
import com.expedia.graphql.exceptions.InvalidIdTypeException
import com.expedia.graphql.schema.extensions.deepName
import com.expedia.graphql.extensions.deepName
import com.expedia.graphql.schema.testSchemaConfig
import com.expedia.graphql.toSchema
import graphql.GraphQL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.expedia.graphql.schema.hooks

import com.expedia.graphql.TopLevelObjectDef
import com.expedia.graphql.schema.extensions.deepName
import com.expedia.graphql.extensions.deepName
import com.expedia.graphql.schema.getTestSchemaConfigWithHooks
import com.expedia.graphql.toSchema
import graphql.GraphQL
Expand Down

0 comments on commit ba0f9f1

Please sign in to comment.