apollo-tooling icon indicating copy to clipboard operation
apollo-tooling copied to clipboard

Warn on deprecated fields

Open unindented opened this issue 8 years ago • 4 comments

How hard would it be to have apollo-codegen emit warnings (or fail) during the generate phase when one of your queries is using deprecated fields?

If you're open to the idea and can give some guidance on how to go about it, we'd try to create a PR.

unindented avatar Apr 07 '18 02:04 unindented

We already generate appropriate code for Swift and Android for deprecated fields, so these show up as warnings during compilation. I don't think TypeScript or Flow support deprecation annotations however.

You could try adding a validation rule for this, but failing codegen seems too drastic to me.

martijnwalraven avatar Apr 09 '18 05:04 martijnwalraven

Hi @martijnwalraven, I guess TypeScript doesn't support deprecation annotations like @available(*, deprecated, message: "deprecation message") in Swift. Then how about showing deprecated fields warnings directly in the terminal/console when running generate command?

ipadthree avatar Apr 09 '18 23:04 ipadthree

@martijnwalraven - We are using the iOS Apollo library with a GraphQL db. We have deprecated some properties, but these do not generate warnings in Xcode when generating code. Has this function been removed from the code generation, or do we need to do something to enable it?

itsallmememe avatar Jun 18 '19 08:06 itsallmememe

We're using Xcode 10.2.1 with Apollo 0.10.1 installed via CocoaPods.

Here's an example from our schema.json

    "name": "coverImage",
    "description": "Deprecated",
    "args": [],
    "type": { "kind": "OBJECT", "name": "SignedUrl", "ofType": null },
    "isDeprecated": true,
     "deprecationReason": "Cover images are not used on tags."
}```

Which is generating this code
```/// Deprecated
public var coverImage: CoverImage? {
    get {
        return (resultMap["coverImage"] as? ResultMap).flatMap { CoverImage(unsafeResultMap: $0) }
    }
    set {
        resultMap.updateValue(newValue?.resultMap, forKey: "coverImage")
    }
}

itsallmememe avatar Jun 18 '19 08:06 itsallmememe