How to deprecate fields in GraphQL

Kevin Simper
Jul 2, 2017 · 2 min read

You can very easily deprecate a field and if you are using GraphiQL it will show you right in the interface.

There is no guide on the graphql about what you do with migrations and we are having a point now where we need to change some of the fields that we have in our GraphQL api.

So a little bit of digging and I found out you just do it by adding it like this:

var UserType = new GraphQLObjectType({
name: 'User',
fields: {
name: {
type: GraphQLString,
deprecationReason: 'We split up the name into two'
firstname: { type: GraphQLString },
lastname: { type: GraphQLString }

Now if point a GraphiQL browser towards your api, you will be able to see this in the documentation sidebar.

Image for post
Image for post

When you add a deprecationReason it will automatically marked as

isDeprecated: true

as you can see here in the request that GraphiQL makes:

Image for post
Image for post

You can read more about the api for declaring these types.

Also the work that has been done with GraphiQL is super amazing, you can read more about that here.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store