DefaultFakeResolver

A FakeResolver that generates:

  • values based on the object id hashcode for Int/Float/Boolean/ID

  • values based on the field name for strings

For object id, DefaultFakeResolver uses @typePolicy if present. Or you can also override it by setting the "__stableId" property:

val cat = buildCat {
this["stableId"] = "foo"
}

Constructors

Link copied to clipboard
constructor(types: List<CompiledNamedType>)

Functions

Link copied to clipboard
open override fun resolveLeaf(context: FakeResolverContext): Any

Resolves a leaf (scalar or enum) type. Note that because of list and not-nullable types, the type of context.mergedField is not always the leaf type. You can get the type of the leaf type with:

Link copied to clipboard
open override fun resolveListSize(context: FakeResolverContext): Int

Resolves the size of a list. Note that lists might be nested. You can use context.path to get the current nesting depth

Link copied to clipboard
open override fun resolveMaybeNull(context: FakeResolverContext): Boolean
Link copied to clipboard
open override fun resolveTypename(context: FakeResolverContext): String
Link copied to clipboard
open override fun stableIdForObject(obj: Map<String, Any?>, mergedField: CompiledField): String?

Use stableIdForObject to provide FakeResolverContext.id. You can then use FakeResolverContext.id to derive stable values in the resolveXyz() methods above. This way, you're guaranteed that a fake object will have the same field values no matter its path in the query.