-
Notifications
You must be signed in to change notification settings - Fork 728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple schemas / endpoint in one project #3357
Comments
Thanks for the feature request @michaelloo. Apollo iOS is not designed to be used directly with multiple schemas in the same target and I don't believe this is a change we're likely to make in the future. That said, there are a few ways forward:
It's just the generated schema modules that need to be separate, so you may not need to split your frameworks. Your frameworks would then need to gain new dependencies on those separate schema modules, and where you are calling the various APIs currently would need to use the new module namespace.
With the above solutions this becomes a project workflow concern; wanting to generate multiple separate GraphQL schemas into a single target. Apollo iOS is not designed for this use case.
It looks like the |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better. |
Hi @calvincestari, i'll look into the Apollo Federation. In the meantime let me share some more context on our setup. We have a large codebase with over 50 developers contributing to it. It was divided into modules to make ownership of certain areas clearer. We have local development pods for each of those feature areas. See a simplified example diagram here of what it looked like with 0.52.0: graph LR
App --> Module1
App --> Module2
Module1_API_Models_For_FooAPI -- generated for --> FooAPI
Module2_API_Models_For_FooAPI -- generated for --> FooAPI
Module2_API_Models_For_BarAPI -- generated for --> BarAPI
subgraph podpsecs
Module1
Module2
end
subgraph Module1
Module1_API_Models_For_FooAPI
end
subgraph Module2
Module2_API_Models_For_FooAPI
Module2_API_Models_For_BarAPI
end
subgraph APIs
FooAPI
BarAPI
end
Whilst we we generated the models for the same endpoint in 2 different modules, it was ok because:
When we updated to 1.9.0, we've had to adjust some of our modules as they were requesting from different APIs: graph LR
App --> Module1
App --> Module2
Module1_API_Models_For_FooAPI -- generated for --> FooAPI
Module2_API_Models_For_FooAPI -- generated for --> FooAPI
Module2_API_Models_For_BarAPI -- generated for --> BarAPI
Module2 --> Module2_API_Models_For_BarAPI
subgraph podpsecs
Module1
Module2
Module2_API_Models_For_BarAPI
end
subgraph Module1
Module1_API_Models_For_FooAPI
end
subgraph Module2
Module2_API_Models_For_FooAPI
end
subgraph APIs
FooAPI
BarAPI
end
Whilst this works, it doesnt feel right as we:
We've decided to swallow these for now, but it isn't ideal for the way our company operates, as we prefer to have one team owning each modules to reduce the amount of synchronisation needed and communication overhead (especially if you multiply this setup to have about 15 modules) From a quick read at Apollo Federation, whilst it will indeed support the feature I am requesting here, I am not sure it will support our immediate needs (as it means creating another system in our architecture to host the We might run into "ownership" of how the generated code is updated, given I assume we'll need to create another module in with the generated code from all the different APIs, which becomes a single point of failure. We prefer automy and independent delivery of features as much as possible so this might not work for us (unless i misunderstand how this will work on the client side) |
Is this the only piece of the puzzle preventing you from using your preferred module configuration in diagram 1? |
There is:
I feel in general it might be safe to prefix the file name with the schema namespace the same way the structs are part of the schema namespace enum for all generated models, that way we will never get a file name conflict. This will be similar to how some of the protocols in |
I can get behind the argument that Xcodes inability to handle files of the same name, within the same target even though they're in different paths, is an Xcode bug and best fixed there. In short I'm saying that filename prefixing with the schema namespace is not a change we're willing to make. The codegen templating engine is fairly easy to understand so you should be able to adapt the source to that style of filename output if you really want to go down that path. |
@michaelloo - I've created two issues that could alleviate the issues you're experiencing:
We haven't prioritized them into our projected work and they should be relatively easy to get done. If you are interested in collaborating on them we'd be happy to provide design/implementation review. |
Use case
As a developer working on a large software
I want to be able to use the Apollo SDK with different schemas
So that I am able to request data against multiple GraphQL servers
I am using Apollo on a large codebase with over 50 developers, we split our codebases into multiple different frameworks, so typically we are able to use Apollo SDK (at time of writing using 1.9.0) to generate the models we need to receive or send data to a server. However, some of our frameworks actually interacts with more than 1 server (i.e.: we need to support generating code from more than one schema under the same target).
At time of writing, we have to further split our frameworks in order to avoid filename and namespace conflicts (see thread).
This is not ideal as it requires a large refactoring piece in order for us to keep using Apollo
Describe the solution you'd like
It would be ideal if Apollo could support multiple schemas without the users having to split their codebase into smaller chunks.
Whilst using 1.9.0 the code gen will generate files that cannot be compiled via Xcode as the filename conflicts, e.g.:
SchemaConfiguration
is common across all schemas and Xcode will complain:A couple of suggestions that might work:
schemaNamespace
property be used as a prefix to all the generated files?schemaNamespace
likeSchemaConfiguration
, can they be in the created namespace as well?The text was updated successfully, but these errors were encountered: