Skip to content
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

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

Closed
Polenoso opened this issue Jan 31, 2024 · 2 comments
Closed

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

Polenoso opened this issue Jan 31, 2024 · 2 comments
Labels
feature New addition or enhancement to existing solutions

Comments

@Polenoso
Copy link

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

  • Files generated like Query.graphql.swift, SchemeMetadata.graphql.swift, SchemeConfiguration.graphql.swift are duplicated for each scheme, so it needs manual changes to remove redeclaration of files in order to make it possible to compile.

Possible Suggestion

  • Add a parameter on codegen-config.json where we can set a value of merge equal classes or files
{
...
      "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

@Polenoso Polenoso added bug Generally incorrect behavior needs investigation labels Jan 31, 2024
@calvincestari calvincestari added feature New addition or enhancement to existing solutions and removed bug Generally incorrect behavior needs investigation labels Jan 31, 2024
@calvincestari
Copy link
Member

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.

@calvincestari calvincestari closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

2 participants