Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Replicate types hints to DSL methods #3543

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/graphql/schema/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def method_conflict_warning?
# @param method_conflict_warning [Boolean] If false, skip the warning if this field's method conflicts with a built-in method
# @param validates [Array<Hash>] Configurations for validating this field
# @param legacy_edge_class [Class, nil] (DEPRECATED) If present, pass this along to the legacy field definition
# @note Keep this type definition in sync with GraphQL::Schema::Member::HasFields#field
def initialize(type: nil, name: nil, owner: nil, null: nil, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, hash_key: nil, resolver_method: nil, resolve: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: 1, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, legacy_edge_class: nil, &definition_block)
if name.nil?
raise ArgumentError, "missing first `name` argument or keyword `name:`"
Expand Down
32 changes: 31 additions & 1 deletion lib/graphql/schema/member/has_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,38 @@ class Member
# Shared code for Object and Interface
module HasFields
# Add a field to this object or interface with the given definition
# @see {GraphQL::Schema::Field#initialize} for method signature
# @param name [Symbol] The underscore-cased version of this field name (will be camelized for the GraphQL API)
# @param type [Class, GraphQL::BaseType, Array] The return type of this field
# @param owner [Class] The type that this field belongs to
# @param null [Boolean] `true` if this field may return `null`, `false` if it is never `null`
# @param description [String] Field description
# @param deprecation_reason [String] If present, the field is marked "deprecated" with this message
# @param method [Symbol] The method to call on the underlying object to resolve this field (defaults to `name`)
# @param hash_key [String, Symbol] The hash key to lookup on the underlying object (if its a Hash) to resolve this field (defaults to `name` or `name.to_s`)
# @param resolver_method [Symbol] The method on the type to call to resolve this field (defaults to `name`)
# @param connection [Boolean] `true` if this field should get automagic connection behavior; default is to infer by `*Connection` in the return type name
# @param connection_extension [Class] The extension to add, to implement connections. If `nil`, no extension is added.
# @param max_page_size [Integer, nil] For connections, the maximum number of items to return from this field, or `nil` to allow unlimited results.
# @param introspection [Boolean] If true, this field will be marked as `#introspection?` and the name may begin with `__`
# @param resolve [<#call(obj, args, ctx)>] **deprecated** for compatibility with <1.8.0
# @param field [GraphQL::Field, GraphQL::Schema::Field] **deprecated** for compatibility with <1.8.0
# @param function [GraphQL::Function] **deprecated** for compatibility with <1.8.0
# @param resolver_class [Class] (Private) A {Schema::Resolver} which this field was derived from. Use `resolver:` to create a field with a resolver.
# @param arguments [{String=>GraphQL::Schema::Argument, Hash}] Arguments for this field (may be added in the block, also)
# @param camelize [Boolean] If true, the field name will be camelized when building the schema
# @param complexity [Numeric] When provided, set the complexity for this field
# @param scope [Boolean] If true, the return type's `.scope_items` method will be called on the return value
# @param subscription_scope [Symbol, String] A key in `context` which will be used to scope subscription payloads
# @param extensions [Array<Class, Hash<Class => Object>>] Named extensions to apply to this field (see also {#extension})
# @param directives [Hash{Class => Hash}] Directives to apply to this field
# @param trace [Boolean] If true, a {GraphQL::Tracing} tracer will measure this scalar field
# @param broadcastable [Boolean] Whether or not this field can be distributed in subscription broadcasts
# @param ast_node [Language::Nodes::FieldDefinition, nil] If this schema was parsed from definition, this AST node defined the field
# @param method_conflict_warning [Boolean] If false, skip the warning if this field's method conflicts with a built-in method
# @param validates [Array<Hash>] Configurations for validating this field
# @param legacy_edge_class [Class, nil] (DEPRECATED) If present, pass this along to the legacy field definition
# @return [GraphQL::Schema::Field]
# @note Keep this type definition in sync with GraphQL::Schema::Field#initialize
def field(*args, **kwargs, &block)
field_defn = field_class.from_options(*args, owner: self, **kwargs, &block)
add_field(field_defn)
Expand Down