David Nikel-Shepherd
10/13/2022, 12:57 PMval user = Builder(__CustomScalarAdapters).run {
buildUser {
contactMobile = "+2217730634835"
// etc, lots of setup
}
}
addMockResponse(LoginMutation, LoginMutation.Data(fakeResolver) { user = user })
addMockResponse(PermissionsQuery, PermissionsQuery.Data(fakeResolver) { user = user })
addMockResponse(AnnouncementsQuery, AnnouncementsQuery.Data(fakeResolver) { user = user })
// ^ not actually this simple, but this gives the idea
This almost works but there are a few issues:
• If we use any fake resolvers, they are run separately for each response. So different responses will actually return different data even though it's supposed to be the same user.
• We use __CustomScalarAdapters
which is presumably supposed to be private since it has the __
• user
is a weakly typed map object which isn't a blocker but means we aren't type safe if we want to get e.g. the user's id for use in another builder.mbonnin
10/13/2022, 1:05 PMData
?mbonnin
10/13/2022, 1:05 PMDavid Nikel-Shepherd
10/13/2022, 1:05 PMmbonnin
10/13/2022, 1:05 PMmbonnin
10/13/2022, 1:23 PMmbonnin
10/13/2022, 1:24 PM{
user: {
id: firstName
}
}
mbonnin
10/13/2022, 1:24 PMuser.id
is not what you think it ismbonnin
10/13/2022, 1:25 PMmbonnin
10/13/2022, 1:25 PMfakeResolver
returning different values, I can see the pain.mbonnin
10/13/2022, 1:34 PMDavid Nikel-Shepherd
10/13/2022, 1:37 PMmbonnin
10/13/2022, 1:39 PMFakeResolver
, i.e. something that always returns the same value for the same objectmbonnin
10/13/2022, 1:40 PMmbonnin
10/13/2022, 1:47 PMFakeResolverContext
just yetDavid Nikel-Shepherd
10/13/2022, 1:48 PMDavid Nikel-Shepherd
10/13/2022, 1:50 PMmbonnin
10/13/2022, 1:51 PMmbonnin
10/13/2022, 1:51 PM{
viewer {
name
}
repository {
owner {
# Same user, different path
name
}
}
}
David Nikel-Shepherd
10/13/2022, 1:52 PMmbonnin
10/13/2022, 1:52 PMMap<String, Any>
for each path in your graph and reusembonnin
10/13/2022, 1:53 PMDavid Nikel-Shepherd
10/13/2022, 1:53 PMmbonnin
10/13/2022, 1:53 PMval user = Builder(__CustomScalarAdapters).run {
buildUser(seed = "42") {
contactMobile = "+2217730634835"
// etc, lots of setup
}
}
mbonnin
10/13/2022, 1:54 PMseed
value that resets the fake resolver statembonnin
10/13/2022, 1:56 PMseed
is specified, it uses the stringified pathDavid Nikel-Shepherd
10/13/2022, 2:00 PMfakeResolver
in the buildUser
function after builder.block
? That would mean that the auto-generated defaults are stored into the UserMap.
I think that would be easier to understand as a user of this, but it would mean that you can't have e.g. the path (and maybe other things) in the fakeResolver equivalent.mbonnin
10/13/2022, 2:02 PMmbonnin
10/13/2022, 2:07 PMmbonnin
10/13/2022, 2:07 PMval user = Builder(__CustomScalarAdapters, fakeResolver).run {
buildUser {
contactMobile = "+2217730634835"
// etc, lots of setup
}
}
mbonnin
10/13/2022, 2:08 PM{
viewer {
personalPhone: phone(PERSONAL)
professionalPhone: phone(PROFESSIONAL)
}
}
mbonnin
10/13/2022, 2:09 PMDavid Nikel-Shepherd
10/13/2022, 2:09 PMmbonnin
10/13/2022, 2:09 PMfakeResolver's interface would need to change for that to work though, no?Indeed, we'd need to remove the path, alias, arguments from
FakeResolverContext
mainlymbonnin
10/13/2022, 2:10 PMYou also need to fake for each queryThat would take us back to step 1 anytime aliases are involved because there's no way "in advance" (without knowledge of the query) to compute those values
David Nikel-Shepherd
10/13/2022, 2:14 PM{
user {
id: firstName
}
}
wouldn't we set id
in the query data to be equal to firstName
from the builder-generated map?mbonnin
10/13/2022, 2:22 PM{
viewer {
personalPhone: phone(PERSONAL)
professionalPhone: phone(PROFESSIONAL)
}
}
mbonnin
10/13/2022, 2:22 PMphone
field name but with different arguments so most of the times you'll want different valuesmbonnin
10/13/2022, 2:33 PM.seed(seed)
function.mbonnin
10/13/2022, 2:33 PMDavid Nikel-Shepherd
10/13/2022, 2:33 PMIt's the same phone field name but with different arguments so most of the times you'll want different valuesAh yeah. For fields with arguments could we store a function in the map instead of a value? I guess that's quite a big change from the current setup where it's only primitives and maps of primitives...
David Nikel-Shepherd
10/13/2022, 2:33 PMmbonnin
10/13/2022, 2:48 PMstore a function in the map instead of a valueThat's a neat idea. I'll play with this a bit.
David Nikel-Shepherd
10/13/2022, 2:51 PMmbonnin
10/13/2022, 2:52 PMmbonnin
10/13/2022, 2:52 PMmbonnin
11/14/2022, 4:26 PMDavid Nikel-Shepherd
11/21/2022, 9:42 AM