How to deprecate fields in GraphQL

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.

Written by

I really like building stuff with React.js and Docker and also Meetups ❤

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