Skip to content

Commit

Permalink
add graphql long to wiring factory
Browse files Browse the repository at this point in the history
  • Loading branch information
temaEmelyan committed Jun 17, 2024
1 parent f95b257 commit bd96d8b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 28 deletions.
76 changes: 52 additions & 24 deletions lib/src/main/java/graphql/nadel/schema/NeverWiringFactory.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package graphql.nadel.schema

import graphql.Assert.assertShouldNeverHappen
import graphql.GraphQLContext
import graphql.execution.CoercedVariables
import graphql.language.Value
import graphql.scalars.ExtendedScalars
import graphql.schema.Coercing
import graphql.schema.DataFetcher
Expand All @@ -12,9 +15,10 @@ import graphql.schema.idl.ScalarInfo
import graphql.schema.idl.ScalarWiringEnvironment
import graphql.schema.idl.UnionWiringEnvironment
import graphql.schema.idl.WiringFactory
import java.util.Locale

/**
* This wiring factory is designed to be NEVER called and will assert if it ever is. Nadel
* This wiring factory is designed to be NEVER called and will assert if it ever is. Nadel
* uses this for the overall schema and also in part for the underlying schema by default.
*/
open class NeverWiringFactory : WiringFactory {
Expand All @@ -24,31 +28,55 @@ open class NeverWiringFactory : WiringFactory {
}

override fun getScalar(environment: ScalarWiringEnvironment): GraphQLScalarType? {
val scalarName = environment.scalarTypeDefinition.name
if (scalarName == ExtendedScalars.Json.name) {
return ExtendedScalars.Json
}
return GraphQLScalarType
.newScalar()
.name(scalarName)
.definition(environment.scalarTypeDefinition)
.coercing(object : Coercing<Any?, Any?> {
override fun serialize(dataFetcherResult: Any): Any? {
return assertShouldNeverHappen("This %s scalar coercing should NEVER be called from Nadel",
scalarName)
}
return when (val scalarName = environment.scalarTypeDefinition.name) {
ExtendedScalars.Json.name -> {
ExtendedScalars.Json
}
ExtendedScalars.GraphQLLong.name -> {
ExtendedScalars.GraphQLLong
}
else -> {
GraphQLScalarType.newScalar()
.name(scalarName)
.definition(environment.scalarTypeDefinition)
.coercing(object : Coercing<Any?, Any?> {
override fun serialize(
dataFetcherResult: Any,
graphQLContext: GraphQLContext,
locale: Locale,
): Any? {
return assertShouldNeverHappen(
"This %s scalar coercing should NEVER be called from Nadel",
scalarName
)
}

override fun parseValue(input: Any): Any {
return assertShouldNeverHappen("This %s scalar coercing should NEVER be called from Nadel",
scalarName)
}
override fun parseValue(
input: Any,
graphQLContext: GraphQLContext,
locale: Locale,
): Any? {
return assertShouldNeverHappen(
"This %s scalar coercing should NEVER be called from Nadel",
scalarName
)
}

override fun parseLiteral(input: Any): Any {
return assertShouldNeverHappen("This %s scalar coercing should NEVER be called from Nadel",
scalarName)
}
})
.build()
override fun parseLiteral(
input: Value<*>,
variables: CoercedVariables,
graphQLContext: GraphQLContext,
locale: Locale,
): Any? {
return assertShouldNeverHappen(
"This %s scalar coercing should NEVER be called from Nadel",
scalarName
)
}
})
.build()
}
}
}

override fun providesTypeResolver(environment: InterfaceWiringEnvironment): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "long scalar argument with default values"
enabled: true
# language=GraphQL
overallSchema:
service: |
type Query {
getFoo(arg: Long = 123): String
}
scalar Long
# language=GraphQL
underlyingSchema:
service: |
type Query {
getFoo(arg: Long = 123): String
}
scalar Long
query: |
query {
getFoo(arg: 15)
}
variables: { }
serviceCalls:
- serviceName: "service"
request:
# language=GraphQL
query: |
query {
getFoo(arg: 15)
}
variables: { }
# language=JSON
response: |-
{
"data": {
"getFoo": "KFC Good"
},
"extensions": {}
}
# language=JSON
response: |-
{
"data": {
"getFoo": "KFC Good"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ enabled: true
overallSchema:
service: |
type Query {
aField: URL
aField: Long
}
scalar URL
scalar Long
# language=GraphQL
underlyingSchema:
service: |
type Query {
aField: URL
aField: Long
}
scalar URL
scalar Long
query: |
query {
aField
Expand Down

0 comments on commit bd96d8b

Please sign in to comment.