Receiving `typeMismatch ApolloCodegenLib.ApolloCodegenConfiguration.FileOutput "Unrecognized key found: options"` error updating from Apollo Swift Package v1.3.0 to v1.4.0

I’m attempting to update the version of the Apollo Swift Package in our project from v1.3.0 to v1.4.0 and cannot use the updated cli tool to generate code. I receive the following error trying to generate the Apollo code:

Error: typeMismatch(ApolloCodegenLib.ApolloCodegenConfiguration.FileOutput, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "output", intValue: nil)], debugDescription: "Unrecognized key found: options", underlyingError: nil))

I can reproduce the error with my current setup (v1.3.0) by downloading apollo-ios-cli from the v1.4.0 release page and running with my current apollo-codegen-config.json using

apollo-ios-cli generate --ignore-version-mismatch

I’ve looked for documentation on changes to apollo-codegen-config.json content but the docs still show options as the valid key.

Here’s my output dict in apollo-codegen-config.json:

    "output": {
        "testMocks": {
            "swiftPackage": {
                "targetName": "BFFTestMocks"
            }
        },
        "schemaTypes": {
            "path": "./BFF",
            "moduleType": {
                "swiftPackageManager": {}
            }
        },
        "operations": {
            "inSchemaModule": {}
        },
        "options": {
            "queryStringLiteralFormat": "multiline",
            "deprecatedEnumCases": "include",
            "warningsOnDeprecatedUsage": "include",
            "conversionStrategies": {
                "enumCases": "camelCase"
            },
            "pruneGeneratedFiles": false,
            "selectionSetInitializers" : {
                "localCacheMutations" : true,
                "namedFragments" : true,
                "operations" : true
            }
        }
    }

Is there a change to the “options” key I’m missing that hasn’t been documented?

TIA, Jim

@jimmc_dat It looks like the issue you are seeing is because the options part of the codegen config is actually it’s own top-level section, not nested inside the output section. Previously this wouldn’t cause an error in codegen, however the options also wouldn’t have been being applied correctly. Starting with version 1.3.2 there is now error checking to alert users of invalid keys so they can catch and fix issues early which is what you are seeing now. changing your config to look like this should fix your issue:

"output": {
        "testMocks": {
            "swiftPackage": {
                "targetName": "BFFTestMocks"
            }
        },
        "schemaTypes": {
            "path": "./BFF",
            "moduleType": {
                "swiftPackageManager": {}
            }
        },
        "operations": {
            "inSchemaModule": {}
        }
    },
"options": {
            "queryStringLiteralFormat": "multiline",
            "deprecatedEnumCases": "include",
            "warningsOnDeprecatedUsage": "include",
            "conversionStrategies": {
                "enumCases": "camelCase"
            },
            "pruneGeneratedFiles": false,
            "selectionSetInitializers" : {
                "localCacheMutations" : true,
                "namedFragments" : true,
                "operations" : true
            }
        }

Awesome, thank you! I was actually wondering about the Options section as i hadn’t seen evidence that the options were getting applied, just been too busy to investigate. Thanks for saving me even more time, I appreciate it.

Is there a doc page with every apollo-codegen-config option stubbed with values? I’ve found the documentation often difficult to parse trying to build/flesh out our config.

Thanks, Jim

I don’t believe we have an example in the docs of a fully stubbed our apollo-codegen-config although that is good feedback, I will double check to make sure we don’t already have it and if not it’s something we can look at adding.

1 Like

@jimmc_dat Once this PR lands there will be a full json example at the end of the existing codegen configuration docs page.