Method: Rails::GraphQL::Request::PreparedData.lookup
- Defined in:
- lib/rails/graphql/request/prepared_data.rb
.lookup(request, field) ⇒ Object
Look up the given field using the request as a reference. It accepts any Rails::GraphQL::Field or a string where “query.create_user” means a query field on the request schema with create_user as name, or create_user as gql_name, and “User.devices” will use the schema of the request to lookup the type “User” and then pick the field devices
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rails/graphql/request/prepared_data.rb', line 31 def self.lookup(request, field) return field if field.is_a?(GraphQL::Field) source, name = field.to_s.split('.') return if source.nil? || name.nil? if SCHEMA_BASED.any? { |item| item.to_s == source } request.schema.find_field!(source.to_sym, name) elsif (type = request.schema.find_type!(source)).is_a?(Helpers::WithFields) type.find_field!(name) else field end rescue NotFoundError # Return the original value, maybe it will be resolved somewhere else field end |