Is there a way to share fragments between schemas?...
# apollo-kotlin
c
Is there a way to share fragments between schemas? Where I work we have several services which draw from a common schema which define types we expect from frontend facing services. For example Service A has its own schema, Service B has its own schema, but they both feature type Foo {}. Ideally I’d like to have one fragment for Foo defined and shared across both, is this possible?
m
Not really. Usually the best way to do this is server side using something like federation.
From the client side of things, there is no way to know 2 types are identical between two different schemas
c
Hey @mbonnin, exactly yeah we’re using federation to share the common types on the backend. Client side I guess theres no way of expressing that federation through apollo? I’m thinking maybe I just make a common-fragments directory and symlink it into each dependant module 🤔
m
Federation is implementation detail as far as the client is concerned
The client should "just" see a big supergraph
c
right okay, am I write in thinking apollo lets you create a service from multiple schema files? So in theory I could place my common schema in one module and my full service schema in another and they would be merged? If it allowed multiple schemas across modules?
m
schemaFiles
is plural mainly in case you have client side schema extension
it cannot do federation composition
Federation composition belongs in the server
Your backend should ideally give you an "API schema" that is the result of all the merged schemas
c
Ah it does, ultimately Service A and Services B schemas are just super sets of the common schema. I get that from a information perspective you don’t know how to decompose the aggregated schema, but theres no reason why you can’t supplement that on the client. It sounds like this is a fairly uncommon usecase anyway, I’ll figure out a more naive way of not repeating the fragments across modules. Thank you @mbonnin
m
Sure thing!