graphql v0.19.0 Release Notes
Release Date: 2016-09-30 // over 7 years ago-
๐ฅ Breaking changes
๐
GraphQL::Relay::GlobalNodeIdentification
was removed. Its features were moved toGraphQL::Schema
orGraphQL::Relay::Node
. The new hooks support more robust & flexible global IDs. #243- Relay's
"Node"
interface andnode(id: "...")
field were both moved toGraphQL::Relay::Node
. To use them in your schema, call.field
and.interface
. For example:
# Adding a Relay-compliant `node` field: field :node, GraphQL::Relay::Node.field
# This object type implements Relay's `Node` interface: interfaces [GraphQL::Relay::Node.interface]
- UUID hooks were renamed and moved to
GraphQL::Schema
. You should defineid_from_object
andobject_from_id
in yourSchema.define { ... }
block. For example:
MySchema = GraphQL::Schema.define do # Fetch an object by UUID object_from_id ->(id, ctx) { MyApp::RelayLookup.find(id) } # Generate a UUID for this object id_from_object ->(obj, type_defn, ctx) { MyApp::RelayLookup.to_id(obj) } end
- The new hooks have no default implementation. To use the previous default, use
GraphQL::Schema::UniqueWithinType
, for example:
MySchema = GraphQL::Schema.define do object_from_id ->(id, ctx) { # Break the id into its parts: type_name, object_id = GraphQL::Schema::UniqueWithinType.decode(id) # Fetch the identified object # ... } id_from_object ->(obj, type_defn, ctx) { # Provide the the type name & the object's `id`: GraphQL::Schema::UniqueWithinType.encode(type_defn.name, obj.id) } end
If you were using a custom
id_separator
, it's now accepted as an input toUniqueWithinType
's methods, asseparator:
. For example:# use "---" as a ID separator GraphQL::Schema::UniqueWithinType.encode(type_name, object_id, separator: "---") GraphQL::Schema::UniqueWithinType.decode(relay_id, separator: "---")
type_from_object
was previously deprecated and has been replaced bySchema#resolve_type
. You should define this hook in your schema to return a type definition for a given object:
MySchema = GraphQL::Schema.define do # ... resolve_type ->(obj, ctx) { # based on `obj` and `ctx`, # figure out which GraphQL type to use # and return the type } end
Schema#node_identification
has been removed.
- Relay's
0๏ธโฃ
Argument
default values have been changed to be consistent withInputObjectType
default values. #267
Previously, arguments expected GraphQL values as
default_value
s. Now, they expect application values. (InputObjectType
s always worked this way.)Consider an enum like this one, where custom values are provided:
PowerStateEnum = GraphQL::EnumType.define do name "PowerState" value("ON", value: 1) value("OFF", value: 0) end
Previously, enum names were provided as default values, for example:
field :setPowerState, PowerStateEnum do # Previously, the string name went here: argument :newValue, default_value: "ON" end
Now, enum values are provided as default values, for example:
field :setPowerState, PowerStateEnum do # Now, use the application value as `default_value`: argument :newValue, default_value: 1 end
Note that if you don't have custom values, then there's no change, because the name and value are the same.
Here are types that are affected by this change:
- Custom scalars (previously, the
default_value
was a string, now it should be the application value, egDate
orBigDecimal
) - Enums with custom
value:
s (previously, thedefault_value
was the name, now it's the value)
If you can't replace
default_value
s, you can also use a type's#coerce_input
method to translate a GraphQL value into an application value. For example:# Using a custom scalar, "Date" # PREVIOUSLY, provide a string: argument :starts_on, DateType, default_value: "2016-01-01" # NOW, transform the string into a Date: argument :starts_on, DateType, default_value: DateType.coerce_input("2016-01-01")
๐ New features
- ๐ Support
@deprecated
in the Schema language #275 - ๐ Support
directive
definitions in the Schema language #280 - ๐ Use the same introspection field descriptions as
graphql-js
#284
๐ Bug fixes
- Operation name is no longer present in execution error
"path"
values #276 - 0๏ธโฃ Default values are correctly dumped & reloaded in the Schema language #267