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

No value associated with key CodingKeys when passing authorization in headers in codegen-config file #2661

Closed
nikitrivedii opened this issue Nov 14, 2022 · 6 comments · Fixed by #2811
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation planned-next Slated to be included in the next release

Comments

@nikitrivedii
Copy link

nikitrivedii commented Nov 14, 2022

Bug report

I am trying to upgrade apollo SDK to 1.0.2 version.

when configuring codegen-config file I need to pass headers and bearer token as dict key value.

I am getting following error

Screenshot 2022-11-14 at 1 05 51 PM

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.2
  • Xcode version: 14.1
  • Swift version: 5
  • Package manager: SPM

Steps to reproduce

{
  "schemaName" : "My Schema",
  "input" : {
    "operationSearchPaths" : [
      "**/*.graphql"
    ],
    "schemaSearchPaths" : [
      "**/*.graphqls"
    ]
  },
  "output" : {
    "testMocks" : {
      "none" : {
      }
    },
    "schemaTypes" : {
      "path" : "./mySchema",
      "moduleType" : {
        "swiftPackageManager" : {
        }
      }
    },
    "operations" : {
      "relative" : {
      }
    },
    "operationIdentifiersPath": "./Generated/"
  },
  "schemaDownloadConfiguration": {
      "downloadMethod": {
          "introspection": {
              "endpointURL": "my url",
              "httpMethod": {
                  "POST": {}
              },
              "includeDeprecatedInputValues": false,
              "outputFormat": "SDL"
          }
      },
      "downloadTimeout": 60,
      "headers": [{"Authorization":"Bearer  my token"}],
      "outputPath": "./GraphQL/"
  }
}

My shell script is

./apollo-ios-cli fetch-schema 
    
./apollo-ios-cli generate

Try to fetch the schema

@nikitrivedii nikitrivedii changed the title No value associated with key CodingKeys when passing authorization in headers in config file No value associated with key CodingKeys when passing authorization in headers in codegen-config file Nov 14, 2022
@calvincestari
Copy link
Member

Hi @nikitrivedii, thanks for the issue. The JSON data you've got there looks correct, we'll take a deeper look into the decoding.

@calvincestari calvincestari added bug Generally incorrect behavior codegen Issues related to or arising from code generation labels Nov 15, 2022
@pavelmarchuk
Copy link

pavelmarchuk commented Nov 18, 2022

The following snippet works (not very intuitive though):

"headers": [ 
  {
    "key": "Authorization",
     "value": "Bearer TOKEN"
  }
]

@calvincestari
Copy link
Member

I agree, it's not intuitive at all. I'm going to explore whether I can get decoding working with the more intuitive "headers": [{"Authorization":"Bearer my token"}].

@Akhil-P41
Copy link

Akhil-P41 commented Dec 5, 2022

Hi, @calvincestari any update on this issue? The @pavelmarchuk workaround is not working for me and getting the below error.

Versions

  • apollo-ios SDK version: 1.0.5
  • Xcode version: 14.1
  • Swift version: 5
  • COCOAPODS: 1.11.3

Error:

Error: dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around line 1, column 0." UserInfo={NSDebugDescription=Invalid value around line 1, column 0., NSJSONSerializationErrorIndex=0})))

apollo-codegen-config:

{
    "schemaName" : "My_Schema",
    "options" : {
        "cocoapodsCompatibleImportStatements" : true
    },
    "input" : {
        "operationSearchPaths" : [
            "**/*.graphql"
        ],
        "schemaSearchPaths" : [
            "**/My_Schema.json"
        ]
    },
    "output" : {
        "testMocks" : {
            "none" : {
            }
        },
        "schemaTypes" : {
            "moduleType": {
                "embeddedInTarget": {
                    "name": "MY_APP"
                }
            },
            "path": "./My_Location"
        },
        "operations" : {
            "relative" : {
            }
        }
    },
    "schemaDownloadConfiguration": {
        "downloadMethod": {
            "introspection": {
                "endpointURL": "MyGraphqlURL",
                "httpMethod": {
                    "POST": {}
                },
                "includeDeprecatedInputValues": false,
                "outputFormat": "SDL"
            }
        },
        "downloadTimeout": 60,
        "headers": [{
            "key": "Authorization",
            "value": "My Token" 
        }],
        "outputPath": "./graphql/"
    }
}

Command Used

./Pods/Apollo/apollo-ios-cli generate -p apollo-codegen-config.json -s “Schema-name”

@calvincestari
Copy link
Member

Hi @Akhil-P41 👋🏻 - no progress on this issue yet. Your issue is not related to this though; you're using the wrong command parameters.

The generate command help menu states that -s (short format for --string) will override -p (short format for --path). What's happening is that the is CLI is trying to interpret "Schema-name" as your configuration JSON. Drop the -s parameter and the command should work for you.

@calvincestari
Copy link
Member

Hi @nikitrivedii, this is fixed and will go out in the next patch release - 1.0.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation planned-next Slated to be included in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants