Class: GraphQL::Language::VariableDefinition
- Inherits:
-
Struct
- Object
- Struct
- GraphQL::Language::VariableDefinition
- Defined in:
- lib/graphql/language/variable_definition.rb
Instance Attribute Summary collapse
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#type ⇒ Object
Returns the value of attribute type.
-
#variable ⇒ Object
Returns the value of attribute variable.
Instance Method Summary collapse
Instance Attribute Details
#default_value ⇒ Object
Returns the value of attribute default_value
3 4 5 |
# File 'lib/graphql/language/variable_definition.rb', line 3 def default_value @default_value end |
#type ⇒ Object
Returns the value of attribute type
3 4 5 |
# File 'lib/graphql/language/variable_definition.rb', line 3 def type @type end |
#variable ⇒ Object
Returns the value of attribute variable
3 4 5 |
# File 'lib/graphql/language/variable_definition.rb', line 3 def variable @variable end |
Instance Method Details
#materialize(schema, param) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/graphql/language/variable_definition.rb', line 6 def materialize(schema, param) schema_type = type.materialize(schema) if schema_type.nil? || !schema_type.is_a?(GraphQLInputType) raise GraphQLError, "Variable '#{variable.name}' expected value " + "of type '#{schema_type}' which cannot be used as input type." end if Validator.valid_value?(param, schema_type) if !param && default_value return default_value.materialize(schema_type) end return Validator.coerce_value(param, schema_type) end if param raise GraphQLError, "Variable '#{variable.name}' expected value " + "of type '#{schema_type}' but got '#{param}'." else raise GraphQLError, "Variable '#{variable.name}' " + "of required type '#{type}' was not provided." end end |