apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.88k stars 726 forks source link

Add support for specifying module dependencies in the configuration file #2987

Closed e-001 closed 1 year ago

e-001 commented 1 year ago

👋,

It would be beneficial to have the ability to include dependencies directly in the configuration file. We use them in our scalar parsing and are currently manually sed-ing it into Package.swift after every generation, as it is written over.

I propose adding a dependencies field to schemaTypes.moduleType.swiftPackageManager, allowing users to specify additional dependencies that should be included in the generated package. The updated configuration syntax would look like this:

...
  "output": {
    "schemaTypes": {
      "path": "./EnigmaGQL",
      "moduleType": {
        "swiftPackageManager": {
          "dependencies": [
            {
              "url": "https://github.com/mapbox/turf-swift.git",
              "from": "2.6.0"
            }
          ]
        }
      }
    }
...

Which would generate:

...
    dependencies: [
        .package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"),
        .package(url: "https://github.com/mapbox/turf-swift.git", from: "2.6.0")
    ],
    targets: [
        .target(
            name: "EnigmaGQL",
            dependencies: [
                .product(name: "ApolloAPI", package: "apollo-ios"),
                .product(name: "Turf", package: "turf-swift")
            ],
            path: "./Sources"
        ),
    ]
)

This would allow users to easily include additional dependencies in their projects without manually modifying the generated Package.swift file.

calvincestari commented 1 year ago

Hi @e-001, thanks for the idea.

The proposed configuration syntax doesn't cater for the many options of specifying a dependency in a Swift package. It seems rather limiting to only allow url and from but also a high maintenance cost of matching all the parameters that SPM allows. If this did end up being added to the configuration I'd rather have the user specify the entire line that should be included as a dependency, i.e.:

...
  "output": {
    "schemaTypes": {
      "path": "./EnigmaGQL",
      "moduleType": {
        "swiftPackageManager": {
          "dependencies": [
            ".package(url: \"https://github.com/mapbox/turf-swift.git\", from: \"2.6.0\")"
          ]
        }
      }
    }
...

You may not have seen https://github.com/apollographql/apollo-ios/issues/2839 but we're considering the option of making the maintenance of the swift package manifest completely your responsibility; only creating it once when not found, once it exists you can edit it in any way you want and the changes will persist.

e-001 commented 1 year ago

Hard agree on #2839, I hadn't seen it. Yes, makes perfect sense especially if the only expected updates to Package.swift in the current workflow are to bump Apollo versions. I'd take that over my request.