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.

When you add a deprecationReason it will automatically marked as

isDeprecated: true

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

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.

Show your support

Clapping shows how much you appreciated Kevin Simper’s story.