If I have an interface type, and our client querie...
# apollo-kotlin
a
If I have an interface type, and our client queries that type. But server introduced a new concrete type, do we need to update the schema in client to parse that new concrete type if we select only the interface as a fragment?
m
Usually you don't as long as you only select interface fields
Copy code
{
  animal {
    species
    name
  }
}
You will get a model matching
Animal
irrespective of the different concrete types (
Lion
,
Turtle
, etc...)
a
Cool thanks!
Just making sure. I thought that was the case. This allows our backend teams to introduce more types by different subgraphs without requiring client change if we only select interface fields. 🥳
I think
m
yes, definitely. If not, that'd be a huge issue for all the apps already deployed
a
Yeah totally
I was thinking in the case of possible types, requiring that all types are present in the client schema . Maybe that was old Apollo client js code
m
Something you might have is not being able to read all the fields returned by the backend in some cases where you have 2 interfaces. Let me try to find an example
Copy code
{
  node {
    id
    ... on Animal {
      species
    }
  }
}
If you introduce a new type
Cat
then the backend knows it's a Animal
So the backend will send back
Copy code
{
  "animal": {
    "__typename": "Cat",
    "id": "42",
    "species": "Cat"
  }
}
But from Kotlin code, your old app cannot access
species
only id
The old app keeps working. Only it doesn't display as much data as it could
a
interesting. is it because the typename is not recognized? so only if we have a
node
query that references an interface vs a concrete type that has an interface field?
m
Only thing the old app can assume is that "Cat" is a "Node"
a
Copy code
{
  animal {
    id
    eyes {
      color
    }
  }
}
If
Animal
was concrete field type, then a field named
eyes
was an interface with
color
field.
m
Without the schema, it cannot know that "Cat" is also an "Animal"
a
App is bundled with
type DefaultEyes implements Eyes
but backend decides to send
type BrownEyes implements Eyes
, then it should work
m
Yes, because you don't have any fragment under the
eyes
field
The situation I described only happens with fragments
a
what if it was:
Copy code
eyes {
  color
  ... on DefaultEyes {
    anotherField
  }
}
app would still see color, is my thought. if im understanding correctly. which is perfectly fine
thank you color
m
app would still see color, is my thought. if im understanding correctly. which is perfectly fine
Yep, exactly. Every subfield of the given field ("just under") will be still be seen. But not always for fields that are nested in fragments
a
ok cool thanks