If I got two separate queries that are querying th...
# apollo-kotlin
s
If I got two separate queries that are querying the same fields which should have the right @typePolicy set on them for the cache to store them in the same way. Should I expect the
watch
of one query to be hit if the response from that other query comes in and updates the cache?
More context: For a schema like
Copy code
type Query {
  chat(until: Instant): Chat!
}
type Chat {
  id: ID!
  messages: [ChatMessage!]!
}
interface ChatMessage {
  id: ID!
  sender: ChatMessageSender!
}
enum ChatMessageSender {
  ONE
  TWO
}
And an
extra.graphql
like
Copy code
extend type Chat @typePolicy(keyFields: "id")
extend type ChatMessage @typePolicy(keyFields: "id")
If I got a query like
Copy code
query NumberOfChatMessages {
  chat(until: null) {
    messages {
      id
      sender
    }
  }
}
And one like
Copy code
query ChatMessages($until: Instant) {
  chat(until: $until) {
    id
    messages {
      ...MessageFragment
    }
    ... more here
  }
}
fragment MessageFragment on ChatMessage {
  id
  sender
  ... more here
}
And there's a place I am doing a watch on
NumberOfChatMessages
and I was hoping to properly get notified for new information in the cache since I am in some other place polling on
ChatMessages(null)
and in turn populating the cache. But it does not seem to be the case, and I wonder what I am doing wrong. Does anything stand out here on first sight?
Should I be doing
extend interface ChatMessage @typePolicy(keyFields: "id")
instead of
extend type ChatMessage @typePolicy(keyFields: "id")
I just realized this is looking wrong since I am doing the wrong
extend
here? ๐Ÿ‘€
b
hmm nothing on first sight - did you have a look at the contents of the cache (e.g. with the IDE plugin's cache viewer)? Sometimes just looking at it will reveal issues.
Should I be doing
extend interface ChatMessage @typePolicy(keyFields: "id")
wow definitely
extend type
on something that's not a type should probably raise an error
s
I must've had it this way since forever ๐Ÿ’€
Is there a way for me to know that the
extra
file is picked up properly in the first place?
extend type
on something that's not a type should probably raise an error
Yeah good idea ๐Ÿ‘
b
haha good point maybe it's just not seen at all, which would explain why there is no error (unless it's just not checked)
try to put total gibberish in it? That should definitely fail it it's picked
s
I must've messed up smth now that I am working on this. I put just a raw "gibberish" text here and it still runs awkward monkey
Am I going crazy or did I just never have this working properly? I just saw in the docs that you have to do
schemaFiles.setFrom(...
and pass the schema and the extra.graphql directories. I really don't remember if I had this some time and I accidentally removed it? Was this always required? I am having an existential crisis here ๐Ÿ˜…
I feel certain I have had the extras file work in the past ๐Ÿ˜„
m
IIRC the default is to collect all
.graphqls
files in
src/main/graphql
So unless you call
.srcDir()
it should โ€œjustโ€ work
s
Okay, so I might've just had it working in the past and then broke it. That would at least make me feel less stupid :D
Adding it explicitly with setFrom does fail when I write gibberish, so I can take it from here, thanks! I'll be back if I'm still confused ๐Ÿ˜… Thanks ๐Ÿคฉ
๐Ÿ‘ 2
๐Ÿ˜„ 1
m
FWIW, this is the logic to collect the schemas
thank you color 1
s
Hey btw all good, I fixed it by giving it the right path to the extra file, and using the IDE plugin to look inside the cache database (so useful btw, not the first time I use it but still worth mentioning) I made sure it all works as expected! Thanks for the help ๐Ÿคฉ๐Ÿคฉ
๐ŸŽ‰ 1