lib/graphql/schema/build_from_definition.rb in graphql-1.7.14 vs lib/graphql/schema/build_from_definition.rb in graphql-1.8.0.pre1

- old
+ new

@@ -105,42 +105,32 @@ end directives directives.values end - schema.ast_node = schema_definition if schema_definition - schema end NullResolveType = ->(type, obj, ctx) { raise(NotImplementedError, "Generated Schema cannot use Interface or Union types for execution.") } NullScalarCoerce = ->(val, _ctx) { val } def build_enum_type(enum_type_definition, type_resolver) - enum = GraphQL::EnumType.define( + GraphQL::EnumType.define( name: enum_type_definition.name, description: enum_type_definition.description, values: enum_type_definition.values.map do |enum_value_definition| - value = EnumType::EnumValue.define( + EnumType::EnumValue.define( name: enum_value_definition.name, value: enum_value_definition.name, deprecation_reason: build_deprecation_reason(enum_value_definition.directives), description: enum_value_definition.description, ) - - value.ast_node = enum_value_definition - - value end ) - - enum.ast_node = enum_type_definition - - enum end def build_deprecation_reason(directives) deprecated_directive = directives.find{ |d| d.name == 'deprecated' } return unless deprecated_directive @@ -156,12 +146,10 @@ name: scalar_type_definition.name, description: scalar_type_definition.description, coerce: NullScalarCoerce, ) - scalar_type.ast_node = scalar_type_definition - if default_resolve.respond_to?(:coerce_input) scalar_type = scalar_type.redefine( coerce_input: ->(val, ctx) { default_resolve.coerce_input(scalar_type, val, ctx) }, coerce_result: ->(val, ctx) { default_resolve.coerce_result(scalar_type, val, ctx) }, ) @@ -169,19 +157,15 @@ scalar_type end def build_union_type(union_type_definition, type_resolver) - union = GraphQL::UnionType.define( + GraphQL::UnionType.define( name: union_type_definition.name, description: union_type_definition.description, possible_types: union_type_definition.types.map{ |type_name| type_resolver.call(type_name) }, ) - - union.ast_node = union_type_definition - - union end def build_object_type(object_type_definition, type_resolver, default_resolve:) type_def = nil typed_resolve_fn = ->(field, obj, args, ctx) { default_resolve.call(type_def, field, obj, args, ctx) } @@ -189,36 +173,26 @@ name: object_type_definition.name, description: object_type_definition.description, fields: Hash[build_fields(object_type_definition.fields, type_resolver, default_resolve: typed_resolve_fn)], interfaces: object_type_definition.interfaces.map{ |interface_name| type_resolver.call(interface_name) }, ) - type_def.ast_node = object_type_definition - type_def end def build_input_object_type(input_object_type_definition, type_resolver) - input = GraphQL::InputObjectType.define( + GraphQL::InputObjectType.define( name: input_object_type_definition.name, description: input_object_type_definition.description, arguments: Hash[build_input_arguments(input_object_type_definition, type_resolver)], ) - - input.ast_node = input_object_type_definition - - input end def build_default_value(default_value) case default_value when GraphQL::Language::Nodes::Enum default_value.name when GraphQL::Language::Nodes::NullValue nil - when GraphQL::Language::Nodes::InputObject - default_value.to_h - when Array - default_value.map { |v| build_default_value(v) } else default_value end end @@ -228,73 +202,57 @@ if !input_argument.default_value.nil? kwargs[:default_value] = build_default_value(input_argument.default_value) end - argument = GraphQL::Argument.define( - name: input_argument.name, - type: type_resolver.call(input_argument.type), - description: input_argument.description, - **kwargs, - ) - - argument.ast_node = input_object_type_definition - [ input_argument.name, - argument + GraphQL::Argument.define( + name: input_argument.name, + type: type_resolver.call(input_argument.type), + description: input_argument.description, + **kwargs, + ) ] end end def build_directive(directive_definition, type_resolver) - directive = GraphQL::Directive.define( + GraphQL::Directive.define( name: directive_definition.name, description: directive_definition.description, arguments: Hash[build_directive_arguments(directive_definition, type_resolver)], locations: directive_definition.locations.map(&:to_sym), ) - - directive.ast_node = directive_definition - - directive end def build_directive_arguments(directive_definition, type_resolver) directive_definition.arguments.map do |directive_argument| kwargs = {} if !directive_argument.default_value.nil? kwargs[:default_value] = build_default_value(directive_argument.default_value) end - argument = GraphQL::Argument.define( - name: directive_argument.name, - type: type_resolver.call(directive_argument.type), - description: directive_argument.description, - **kwargs, - ) - - argument.ast_node = directive_argument - [ directive_argument.name, - argument + GraphQL::Argument.define( + name: directive_argument.name, + type: type_resolver.call(directive_argument.type), + description: directive_argument.description, + **kwargs, + ) ] end end def build_interface_type(interface_type_definition, type_resolver) - interface = GraphQL::InterfaceType.define( + GraphQL::InterfaceType.define( name: interface_type_definition.name, description: interface_type_definition.description, fields: Hash[build_fields(interface_type_definition.fields, type_resolver, default_resolve: nil)], ) - - interface.ast_node = interface_type_definition - - interface end def build_fields(field_definitions, type_resolver, default_resolve:) field_definitions.map do |field_definition| field_arguments = Hash[field_definition.arguments.map do |argument| @@ -309,12 +267,10 @@ description: argument.description, type: type_resolver.call(argument.type), **kwargs, ) - arg.ast_node = argument - [argument.name, arg] end] field = GraphQL::Field.define( name: field_definition.name, @@ -322,11 +278,9 @@ type: type_resolver.call(field_definition.type), arguments: field_arguments, resolve: ->(obj, args, ctx) { default_resolve.call(field, obj, args, ctx) }, deprecation_reason: build_deprecation_reason(field_definition.directives), ) - - field.ast_node = field_definition type_name = resolve_type_name(field_definition.type) field.connection = type_name.end_with?("Connection") [field_definition.name, field] end