Skip to content

Commit 3308a8d

Browse files
committed
doc(InputObjectType) improve header and examples
1 parent 47277b4 commit 3308a8d

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/graphql/define.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Define
1919
# # After definition, read the key from metadata
2020
# PostType.metadata[:resolves_to_class_names] # => [...]
2121
#
22-
# @param [Object] the key to assign in metadata
22+
# @param key [Object] the key to assign in metadata
2323
# @return [#call(defn, value)] an assignment for `.accepts_definitions` which writes `key` to `#metadata`
2424
def self.assign_metadata_key(key)
2525
GraphQL::Define::InstanceDefinable::AssignMetadataKey.new(key)

lib/graphql/field.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ module GraphQL
7272
# }
7373
# end
7474
#
75+
# Only certain types maybe used for inputs:
76+
#
77+
# - Scalars
78+
# - Enums
79+
# - Input Objects
80+
# - Lists of those types
81+
#
82+
# Input types may also be non-null -- in that case, the query will fail
83+
# if the input is not present.
84+
#
7585
# ## Complexity
7686
#
7787
# Fields can have _complexity_ values which describe the computation cost of resolving the field.

lib/graphql/input_object_type.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
module GraphQL
2-
# A complex input type for a field argument.
2+
# {InputObjectType}s are key-value inputs for fields.
3+
#
4+
# Input objects have _arguments_ which are identical to {GraphQL::Field} arguments.
5+
# They map names to types and support default values.
6+
# Their input types can be any input types, including {InputObjectType}s.
37
#
48
# @example An input type with name and number
59
# PlayerInput = GraphQL::InputObjectType.define do
610
# name("Player")
7-
# input_field :name, !types.String
8-
# input_field :number, !types.Int
11+
# argument :name, !types.String
12+
# argument :number, !types.Int
913
# end
1014
#
15+
# In a `resolve` function, you can access the values by making nested lookups on `args`.
16+
#
17+
# @example Accessing input values in a resolve function
18+
# resolve -> (obj, args, ctx) {
19+
# args[:player][:name] # => "Tony Gwynn"
20+
# args[:player][:number] # => 19
21+
# args[:player].to_h # { "name" => "Tony Gwynn", "number" => 19 }
22+
# # ...
23+
# }
24+
#
1125
class InputObjectType < GraphQL::BaseType
1226
accepts_definitions(
1327
input_field: GraphQL::Define::AssignArgument,

0 commit comments

Comments
 (0)