Fetch Schema giving error when downloading the schema from server

I have updated my Apollo SDK version from 0.33 to latest 1.9.3. As there is a major change in the SDK, I am facing a lot of issues. I have successfully solved some but now stuck and downloading Schema using Apollo codegen CLI.
Problem Statements 1 - My Schema is stored at S3 server always. Using the CLI terminal I have created the apollo-codegen-config and now before I call generate command, I am trying to fetch the schema using command -

./apollo-ios-cli fetch-schema

But I am getting below error on:

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))

This is my apollo-codegen-config file -

{
  "schemaNamespace" : "STXAPI",
  "input" : {
    "operationSearchPaths" : [
      "**/*.graphql"
    ],
    "schemaSearchPaths" : [
      "**/schema.json"
    ]
  },
  "output" : {
    "testMocks" : {
      "none" : {
      }
    },
    "schemaTypes" : {
      "path" : "./STXAPI",
      "moduleType" : {
        "swiftPackageManager" : {
        }
      }
    },
    "operations" : {
      "inSchemaModule" : {
      }
    }
  },
  "schemaDownload": {
      "downloadMethod": {
          "introspection": {
              "endpointURL": "https://s3.us-east-1.amazonaws.com/schema.stxapp.io/v2.0.74/schema.json",
              "httpMethod": {
                  "GET": {}
              },
              "includeDeprecatedInputValues": false,
              "outputFormat": "JSON"
          }
      },
      "downloadTimeout": 60,
      "headers": {
          "Allow-Introspection": "true"
      },
      "outputPath": "./graphql/schema.graphqls"
  }
}

What I am missing out or I need to change please help?

Problem Statement 2 - How can I do all the Schema Init and generate and fetch schema in a CI/CD pipeline, I am using Bitrise for that?

Any help is appreciated.

Hi @Mayank_Mathur :wave:

Problem Statements 1 - My Schema is stored at S3 server always. Using the CLI terminal I have created the apollo-codegen-config and now before I call generate command, I am trying to fetch the schema using command

I’ll admit the GET schema download method isn’t very well documented but I think the larger problem is that you appear to have a static schema at that URL rather than using introspection. The GET http method requires a queryParameterName property because Apollo iOS wants to know the query name for introspection. So it’s expecting to find something like this:

"httpMethod": {
    "GET": {
        "queryParameterName": "MyIntrospectionQuery"
    }
}

You might be able to fudge it by just using a blank string ("") as the value for queryParameterName but Apollo iOS will still attempt to send an entire introspection query in the URL because it’s expecting a GraphQL server to be listening at that URL.

Downloading of static schemas isn’t a supported workflow for the fetch-schema method. I recommend you rather download your static schema just using something like curl and then just feed it into the codegen as an input.

Problem Statement 2 - How can I do all the Schema Init and generate and fetch schema in a CI/CD pipeline, I am using Bitrise for that?

Init is always separate because the initialization parameters used in a fresh configuration file are default parameters that still need to be changed for your configuration.

Fetching the schema and generation can be done in one step but as I said above, fetching a static schema isn’t a supported workflow.

Your CI could do these steps:

  1. Download schema from S3 with curl
  2. Call generate command on Apollo CLI with pre-existing codegen configuration file
1 Like