iOS code generation CLI - httpMethod GET expecting a query parameter when API does not support it

Hi there, I am using Cocoapods to import the Apollo iOS client into my native iOS project.

I am using the following schema but getting a 400 when hitting my endpoint:

{
  "schemaNamespace" : "<name >",
  "schemaDownload": {
    "downloadMethod": {
        "introspection": {
            "endpointURL": "some.url/graphql",
            "httpMethod": {
                "GET": {}
            },
            "includeDeprecatedInputValues": false,
            "outputFormat": "JSON"
        }
    },
    "downloadTimeout": 60,
    "headers": {
      "Allow-Introspection": true
    },
    "outputPath": "./graphql/"
  },
  "input" : {
    "operationSearchPaths" : [
      "**/*.graphql"
    ],
    "schemaSearchPaths" : [
      "**/schema.json"
    ]
  },
  "output" : {
    "testMocks" : {
      "none" : {
      }
    },
    "schemaTypes" : {
      "path" : "./GeneratedFiles",
      "moduleType" : {
        "other" : {}
      }
    },
    "operations" : {
      "inSchemaModule" : {
      }
    }
  },
  "options": {
    "cocoapodsCompatibleImportStatements": true
  }
}

Based on my observation, the endpoint I am hitting is expecting a GET method to introspect, however it seems the ./Pods/Apollo/apollo-ios-cli is expecting a queryParameterName as per error:

Error: keyNotFound(
  GETCodingKeys(stringValue: "queryParameterName", intValue: nil),
  Swift.DecodingError.Context(
    codingPath: [
      CodingKeys(stringValue: "schemaDownload", intValue: nil),
      CodingKeys(stringValue: "downloadMethod", intValue: nil),
      CodingKeys(stringValue: "introspection", intValue: nil),
      IntrospectionCodingKeys(stringValue: "httpMethod", intValue: nil),
      CodingKeys(stringValue: "GET", intValue: nil)
    ],
    debugDescription: "No value associated with key GETCodingKeys(stringValue: \"queryParameterName\", intValue: nil) (\"queryParameterName\").",
    underlyingError: nil
  )
)

If I do pass a parameter like "GET": { "queryParameterName": "foo" }, I get the following: Error: Received bad response from server (code 404): Optional("")

Speaking to my backend team, it seems that usually you’d get a 400 if a header is missing to allow introspection: Allow-Introspection, but as you can see in my config above I am passing that value in

Is this expected?

Hi @mike_loo_rea - I can’t say I’ve used GET to fetch a schema but from the documentation and code the query parameter is meant to contain the query name to be executed.

I believe HTTPMethod is shared with a regular GET request for general GraphQL requests but I wonder if it shouldn’t be for introspection thouugh? :thinking: Do you have a working curl statement that you can download the schema with?

Hi @calvincestari , thanks for the prompt reply. After further investigation it seems that the POST requests works as expected from curl. When using the IntrospectionQuery from here and this curl command:

curl -i -X POST some.url/graphql -H "Allow-Introspection: true" -H "Content-Type: application/json" -d @introspection_query.json

I get a successful response:

HTTP/2 200
date: Tue, 12 Mar 2024 02:33:12 GMT
content-type: application/json
content-length: 75524
server: nginx
vary: Accept-Encoding
x-transaction-id: <some id>
vary: Origin

But I still get a 400 when using the config file:

"schemaDownload": {
    "downloadMethod": {
        "introspection": {
            "endpointURL": "some.url/graphql",
            "httpMethod": {
                "POST": {}
            },
            "includeDeprecatedInputValues": false,
            "outputFormat": "JSON"
        }
    },
    "downloadTimeout": 60,
    "headers": {
      "Allow-Introspection": true
    },
    "outputPath": "./graphql/"
  }

It seems like the “Allow-Introspection” header that I’m passing it might not be sent with the query, is there a way to check this?

Actually I think I found the cause, the header is expecting a string "true" rather than a boolean true :man_facepalming:

Ah, good catch. Glad you managed to get it working.