Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marking fields as deprecated with graphql shorthand

Tags:

graphql

I'm using GraphQL shorthand to specify the types in a schema, eg

type Car {
  id: ID!
  make: String
  model: String
  description: String
}

Using this shorthand, is there a way to mark a field as deprecated? Say I wanted to mark description as deprecated. Here's my wild guess on how to do this.

type Car {
  id: ID!
  make: String
  model: String
  @deprecated
  description: String
}

But no dice. Is field deprecation achievable in GraphQL shorthand?

Thanks!

like image 880
Ranj Avatar asked Mar 08 '18 14:03

Ranj


People also ask

How do you mark a field as deprecated in GraphQL?

To mark a field as deprecated, we'll use GraphQL schema directives. A schema directive is indicated with an @ character, and it decorates a specific symbol in your schema, such as a type or field definition.

How do you deprecate a GraphQL query?

The typical process would be: Remove all references to the item (query, mutation, field, etc) from core code. If the schema item is a field or enum, mark the GraphQL schema item as deprecated using the @deprecated directive.

Is GraphQL obsolete?

The conclusion to all of this is a simple statement – no, GraphQL is not made obsolete by HTTP/2.

What is __ Typename in GraphQL?

The __typename field returns the object type's name as a String (e.g., Book or Author ). GraphQL clients use an object's __typename for many purposes, such as to determine which type was returned by a field that can return multiple types (i.e., a union or interface).


1 Answers

Yup, you can mark fields as deprecated like this:

type Car {
  id: ID!
  make: String
  model: String
  description: String @deprecated(reason: "Field is deprecated!")
}
like image 87
Daniel Rearden Avatar answered Nov 11 '22 19:11

Daniel Rearden