Skip to content

Feature: field_from_name on TypeDefinition#5

Merged
mikkoh merged 2 commits intomasterfrom
field-from-name
Mar 21, 2017
Merged

Feature: field_from_name on TypeDefinition#5
mikkoh merged 2 commits intomasterfrom
field-from-name

Conversation

@mikkoh
Copy link
Copy Markdown
Contributor

@mikkoh mikkoh commented Jan 18, 2017

This PR adds field_from_name onto TypeDefinition.

I don't like how include_deprecated is handled but I'm not sure there's a nicer way to handle it.

@mikkoh mikkoh requested a review from dylanahsmith January 18, 2017 20:39
Comment thread lib/graphql_schema.rb Outdated
end

def field_from_name(field_name, include_deprecated: false)
@fields_by_name ||= fields(include_deprecated: include_deprecated).map{ |field| [field.name, field]}.to_h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will memoize the hash based on the include_deprecated value of the first call and ignore it on subsequent calls.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should just be.

def fields_by_name
    @fields_by_name ||= fields(include_deprecated: true).map{ |field| [field.name, field]}.to_h
end

And then the user can check later if the field is deprecated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

@mikkoh mikkoh requested a review from swalkinshaw March 20, 2017 18:26
@mikkoh mikkoh merged commit 6355e84 into master Mar 21, 2017
@mikkoh mikkoh deleted the field-from-name branch March 21, 2017 17:19
@mikkoh mikkoh deployed to rubygems March 21, 2017 18:01 Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants