Skip to content

Commit d91aac3

Browse files
author
Cole Turner
authored
fix(DocGenerator): entities syntax and idempotent mock values (#562)
* fix(DocGenerator): entities syntax * don't randomize values on every build * fix typo
1 parent 6093f9e commit d91aac3

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/shared/DocGenerator.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import graphql.schema.idl.TypeUtil
2727
import kotlinx.serialization.json.*
2828
import java.math.BigDecimal
2929
import java.math.BigInteger
30-
import kotlin.math.abs
31-
import kotlin.random.Random
3230

3331
@Suppress("FoldInitializerAndIfToElvis")
3432
class DocGenerator(private val config: CodeGenConfig, private val document: Document) {
@@ -116,13 +114,15 @@ class DocGenerator(private val config: CodeGenConfig, private val document: Docu
116114
private fun getExampleEntitiesQuery(definition: ObjectTypeDefinition): String? {
117115
val gql: String = """
118116
query(${'$'}representations: [_Any!]!) {
119-
... on ${definition.name} {
120-
${definition.fieldDefinitions.map {
117+
entities(representations: ${'$'}representations) {
118+
... on ${definition.name} {
119+
${definition.fieldDefinitions.map {
121120
val selectionSet : List<String> = getSelectionSet(it.type.findTypeDefinition(document))
122121
"""
123122
${it.name}${if (it.inputValueDefinitions.size > 0) "(${it.inputValueDefinitions.map{ "${it.name}: ${getMockGQLValueAsAST(it.type)}"}.joinToString(", ")})" else ""} ${if (selectionSet.size > 0) "{${selectionSet.joinToString("\n")}}" else ""}
124123
"""
125124
}.joinToString("\n")}
125+
}
126126
}
127127
}
128128
""".trimIndent()
@@ -194,11 +194,11 @@ class DocGenerator(private val config: CodeGenConfig, private val document: Docu
194194

195195
if (type is TypeName) {
196196
return when (type.name) {
197-
"ID" -> StringValue("random${Random.nextInt()}")
197+
"ID" -> StringValue("random12345")
198198
"String" -> StringValue("randomString")
199-
"Boolean" -> BooleanValue(Random.nextBoolean())
200-
"Int" -> IntValue(BigInteger.valueOf(abs(Random.nextLong())))
201-
"Float" -> FloatValue(BigDecimal.valueOf(abs(Random.nextDouble())))
199+
"Boolean" -> BooleanValue(true)
200+
"Int" -> IntValue(BigInteger.valueOf(123456789))
201+
"Float" -> FloatValue(BigDecimal.valueOf(12345.6789))
202202
else -> {
203203
getSchemaTypeMockValue(type)
204204
}

graphql-dgs-codegen-gradle/generated-docs/Entities.Result.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
### Query
33
```graphql
44
query ($representations: [_Any!]!) {
5-
... on Result {
6-
isSuccessful
7-
result
5+
entities(representations: $representations) {
6+
... on Result {
7+
isSuccessful
8+
result
9+
}
810
}
911
}
1012

graphql-dgs-codegen-gradle/generated-docs/Query.find.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
## Example
99
```graphql
1010
{
11-
find(filter: {mandatoryString : "randomString", optionalString : "randomString", mandatoryNumber : 269109734867147797, optionalNumber : 6032492703890891451}) {
11+
find(filter: {mandatoryString : "randomString", optionalString : "randomString", mandatoryNumber : 123456789, optionalNumber : 123456789}) {
1212
isSuccessful
1313
result
1414
}

0 commit comments

Comments
 (0)