apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.87k stars 717 forks source link

Can't Use 2 Different Schemas in same Package #3329

Closed Polenoso closed 8 months ago

Polenoso commented 8 months ago

Summary

We're using 2 different schemes for 2 different services in GraphQL.

We have provided 2 different codegen scripts to generate both schemes Models, since while using 2 different schemes within the same codegen-config.json file was mistakenly trying to generate queries from one scheme using the other scheme.

Each configuration file uses a different namespace.

Problem

Possible Suggestion

{
...
      "options":
               {
                  "mergeFiles": true
               }
...
}
More context

We are using Apollo inside a Package outside of our main project target in order to avoid the need of adding files manually to the project target

Version

1.8.0

Steps to reproduce the behavior

Config Example

Config File 1

{
    "schemaNamespace" : "Namespace1Graphql",
    "input" : {
        "operationSearchPaths" : [
            "Home/**/*.graphql"
        ],
        "schemaSearchPaths" : [
            "Home/**/*.graphqls"
        ]
    },
    "output" : {
        "testMocks" : {
            "absolute" : {
                "path": "./Sources/Tests/Home/Mocks",
                "accessModifier": "public"
            }
        },
        "schemaTypes" : {
            "path" : "./Sources/GraphQLClient/Home/Generated",
            "moduleType" : {
                "embeddedInTarget": {
                    "name": "GraphQLClient",
                    "accessModifier": "public"
                }
            }
        },
        "operations" : {
            "inSchemaModule" : {
            }
        }
    }
}

Config File 2

{
    "schemaNamespace" : "Namespace2Graphql",
    "input" : {
        "operationSearchPaths" : [
            "Content/**/*.graphql"
        ],
        "schemaSearchPaths" : [
            "Content/**/*.json"
        ]
    },
    "output" : {
        "testMocks" : {
            "absolute" : {
                "path": "./Sources/Tests/Content/Mocks",
                "accessModifier": "public"
            }
        },
        "schemaTypes" : {
            "path" : "./Sources/GraphQLClient/Content/Generated",
            "moduleType" : {
                "embeddedInTarget": {
                    "name": "GraphQLClient",
                    "accessModifier": "public"
                }
            }
        },
        "operations" : {
            "inSchemaModule" : {
            }
        }
    }
}

Logs

No response

Anything else?

No response

calvincestari commented 8 months ago

Hi @Polenoso

We have provided 2 different codegen scripts to generate both schemes Models, since while using 2 different schemes within the same codegen-config.json file was mistakenly trying to generate queries from one scheme using the other scheme.

This is not a bug but part of the design. Apollo iOS, both the client and the code generator, are designed to be used for a single schema only. It is possible to have more than one schema generated and used in your project but they are separate packages, cannot share schema metadata and each will require their own Apollo Client instance.

Unfortunately merging multiple schemas into a single schema is not a feature we plan on supporting.

github-actions[bot] commented 8 months ago

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.