Skip to content

Commit 3aa6244

Browse files
Warn user when field name is a ruby keyword
1 parent 74f736b commit 3aa6244

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/graphql/schema/member/has_fields.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# frozen_string_literal: true
2+
require 'irb/ruby-token'
3+
24
module GraphQL
35
class Schema
46
class Member
@@ -38,16 +40,23 @@ def get_field(field_name)
3840
end
3941
end
4042

43+
# A list of Ruby keywords.
44+
#
45+
# @api private
46+
RUBY_KEYWORDS = RubyToken::TokenDefinitions.select { |definition| definition[1] == RubyToken::TkId }
47+
.map { |definition| definition[2] }
48+
.compact
49+
50+
# A list of GraphQL-Ruby keywords.
51+
#
52+
# @api private
53+
GRAPHQL_RUBY_KEYWORDS = [:context, :object, :method]
54+
4155
# A list of field names that we should advise users to pick a different
4256
# resolve method name.
4357
#
4458
# @api private
45-
CONFLICT_FIELD_NAMES = Set.new([
46-
# GraphQL-Ruby conflicts
47-
:context, :object,
48-
# Ruby built-ins conflicts
49-
:method, :class
50-
])
59+
CONFLICT_FIELD_NAMES = Set.new(GRAPHQL_RUBY_KEYWORDS + RUBY_KEYWORDS)
5160

5261
# Register this field with the class, overriding a previous one if needed.
5362
# @param field_defn [GraphQL::Schema::Field]

0 commit comments

Comments
 (0)