Spencer
11/15/2022, 4:06 PMDon't know how to instantiate leaf UnixTime. This is one of my scalar types, so I created a fake resolver, mostly using the example in the docs. This fixes up the one error, but then causes another one of Don't know how to instantiate leaf CardOrderStatus. This now is a Enum from our schema and if I mock it out, it causes another error saying it can’t find next enum from our schema. When I look at the value of __Schema.all, it is just an empty list, but looking at all the apollo generated code, I see the __Schema.all file is in the module that the schema.graphqls file is in, and all the types for CardOrderStatus and all the other enums types are in a other feature module. Is there a way to have all the types be in the __Schema.all list so I don’t have to mock them all out?Spencer
11/15/2022, 4:08 PMval data = FeatureScreenQuery.Data(resolver = MyFakeResolver()) {
user = buildUser {
id = "aaaaaaa=="
}
}
Fake Resolver:
class MyFakeResolver : FakeResolver {
private val delegate = DefaultFakeResolver(__Schema.all)
override fun resolveLeaf(context: FakeResolverContext): Any {
return when (context.mergedField.type.leafType().name) {
"UnixTime" -> UnixTime(123.toLong())
"CardOrderStatus" -> CardOrderStatus.PROCESSED
else -> delegate.resolveLeaf(context)
}
}
// ... everything else is the same from the example
}
__Schema file:
public object __Schema {
public val all: List<CompiledNamedType> = listOf(
)
public fun possibleTypes(type: CompiledNamedType): List<ObjectType> =
com.apollographql.apollo3.api.possibleTypes(all, type)
}mbonnin
11/15/2022, 4:18 PMapollo {
alwaysGenerateTypesMatching.set(listOf("/*"))
}
in your schema module?Spencer
11/15/2022, 4:22 PMNo signature of method: build_brv5thspzhdwg0pgic89546fl.apollo() is applicable for argument types: (build_brv5thspzhdwg0pgic89546fl$_run_closure3) values: [build_brv5thspzhdwg0pgic89546fl$_run_closure3@1dcd648d]
Possible solutions: apply(groovy.lang.Closure), apply(java.util.Map), apply(groovy.lang.Closure), apply(java.util.Map), split(groovy.lang.Closure)
mbonnin
11/15/2022, 4:23 PM.set() , editing now...mbonnin
11/15/2022, 4:23 PMSpencer
11/15/2022, 4:24 PMmbonnin
11/15/2022, 4:25 PMmbonnin
11/15/2022, 4:25 PMapollo {
alwaysGenerateTypesMatching.set(["/*"])
}Spencer
11/15/2022, 4:29 PMStylianos Gakis
11/15/2022, 4:30 PM./gradlew generateApolloSources after the change to make sure everything is generated with the new configmbonnin
11/15/2022, 4:30 PMmbonnin
11/15/2022, 4:31 PMgenerateDataBuilders in all your modules (including the schema one)?
apollo {
alwaysGenerateTypesMatching.set(["/*"])
generateDataBuilders.set(true)
}Spencer
11/15/2022, 4:35 PMmbonnin
11/15/2022, 4:36 PMSpencer
11/15/2022, 4:36 PMDon't know how to instantiate leaf CardOrderStatus
java.lang.IllegalStateException: Don't know how to instantiate leaf CardOrderStatus
at com.apollographql.apollo3.api.DefaultFakeResolver.resolveLeaf(fakeResolver.kt:244)
at com.example.wallet.MyFakeResolver.resolveLeaf(ExampleUnitTest.kt:25)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfNonNullType(fakeResolver.kt:197)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:150)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:145)
at com.apollographql.apollo3.api.FakeResolverKt.buildField(fakeResolver.kt:117)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfNonNullType(fakeResolver.kt:194)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:150)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:145)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfNonNullType(fakeResolver.kt:170)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:150)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:145)
at com.apollographql.apollo3.api.FakeResolverKt.buildField(fakeResolver.kt:117)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfNonNullType(fakeResolver.kt:183)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:150)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:139)
at com.apollographql.apollo3.api.FakeResolverKt.buildField(fakeResolver.kt:117)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfNonNullType(fakeResolver.kt:183)
at com.apollographql.apollo3.api.FakeResolverKt.buildFieldOfType(fakeResolver.kt:150)
at com.apollographql.apollo3.api.FakeResolverKt.buildFakeObject(fakeResolver.kt:98)
at com.apollographql.apollo3.api.FakeResolverKt.buildData(fakeResolver.kt:289)
at WalletScreen.WalletScreenQuery$Companion.Data(WalletScreenQuery.kt:205)
at com.example.wallet.ExampleUnitTest.addition_isCorrect(ExampleUnitTest.kt:54)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)Spencer
11/15/2022, 4:37 PMgenerateDataBuilders in all of my modulesmbonnin
11/15/2022, 4:37 PMCardOrderStatus in your __Schema.all ?Spencer
11/15/2022, 4:38 PMpublic object __Schema {
public val all: List<CompiledNamedType> = listOf(
)
public fun possibleTypes(type: CompiledNamedType): List<ObjectType> =
com.apollographql.apollo3.api.possibleTypes(all, type)
}mbonnin
11/15/2022, 4:38 PMmbonnin
11/15/2022, 4:42 PMmbonnin
11/15/2022, 4:43 PMmbonnin
11/15/2022, 4:44 PM./gradlew generateApolloSources and I get the Direction enum in com/example/schema/type/__Schema.ktmbonnin
11/15/2022, 4:44 PMpublic object __Schema {
public val all: List<CompiledNamedType> = listOf(
com.example.schema.type.Direction.type, com.example.schema.type.Query.type,
com.example.schema.type.Tag.type)mbonnin
11/15/2022, 4:47 PMSpencer
11/15/2022, 4:47 PMSpencer
11/15/2022, 5:00 PMalwaysGenerateTypesMatching.set(["/*"])
But then in your example it was
alwaysGenerateTypesMatching.set([".*"])
and that seemed to fix itmbonnin
11/15/2022, 5:01 PMSpencer
11/15/2022, 5:04 PMmbonnin
11/15/2022, 5:05 PM