How can I mark a GraphQL field deprecated using Absinthe?

I’ve been starting to learn GraphQL and Absinthe and I’m trying to figure out how to mark a field as deprecated. I see that the field macro has a few extra options including a deprecation option, but when I set that, I don’t see any difference in the object descriptions in the GraphiQL interface. I also purchased the Absinthe book, but there’s no mention of it either. Can anyone show me an example of how to make use of this feature and how to verify that it is working? Thanks!

I’m guessing that you have a typo. The option is deprecate not deprecation: https://hexdocs.pm/absinthe/Absinthe.Schema.Notation.html#deprecate/1

Here’s an example:

    field :post_channel, :string do
      deprecate("Use channel on the message container interface instead.")
      resolve fn %{container: post}, _, _ -> {:ok, Communities.post_channel(post)} end
    end

I think this should work as well (but I haven’t tested it):

field :name, :string, deprecate: "Use first and last name instead"
3 Likes

Thanks! No, that’s not a typo – that’s from the docs at https://hexdocs.pm/absinthe/Absinthe.Type.Field.html#content

but without an example included, it’s been guesswork as to how to make it work.

I’ll test your example and put the updates into my PR for the docs.

Skimming the docs you linked, I found a link to Absinthe.Schema.Notation.deprecate/1, there are examples about how to deprecate a field.

2 Likes

Thank you! Do you know if Graphiql introspects that? I.e. can a user see a deprecation notice for the field when using Graphiql?

I do not have any experience with GraphQL by myself, neither do I have with associated tools :frowning: Our greenfields still rely on free-form JSON APIs :frowning:

3 Likes