graphql

Deprecated argument in GraphQL API (spec 2021)


I have a GraphQL API described in accordance with the specification from October 2021.

I have an argument size that I want to remove.

type Product {
  picture(size: Int): Url
}

But I can't remove it right away without informing consumers in the API specification. I know the working draft spec allows using the @deprecated directive with arguments, but the 2021 spec doesn't allow that.

How can I delete the field in an informed manner without violating the 2021 specification?

I had an idea to deprecate the field and create a field next to it with the same name but without an argument, but unfortunately this is not a valid action.


Solution

  • There isn't a great solution here, but I can tell you what my team decided to do: either create "a field next to it with the same name" (+V2), or create a sibling field with a "better name" if you have a better name.

    Trade-offs between versions and new names:

    It's also worth nothing that the "clean" problem is a real thing, and it's not just about aesthetics. It will likely feel bad the first time you add V* to something, but I've found that at scale*, it's easier in the long run.

    * "at scale" here can mean a few different things, including


    So, if a teammate showed me your example specifically and asked what to do next, I would give these options, and they should do what is right for their product and their customer.

    1. pictureV2: You know your domain and your customer. If picture is the right word, use pictureV2.
    2. pictureUrl: You're returning a URL, which is a scalar. You're not returning a "picture", which might have dimensions, altText, titles, etc. Additionally, if you use the name pictureUrl today (when you're only returning a URL), in the future, if you DID want to introduce these other properties, you could use picture (the non-scalar name) for that. I don't recommend over-engineering for what "might happen", but if you name things with this principle in mind, you leave yourself open to adding features in the future without having to over-architect for maybe, today.
    3. image: This term conveys the same relative meaning as "picture", but it's more common in API design.
    4. imageUrl: The one I usually recommend, due to the previous two bullet points.