Skip to content

Commit

Permalink
Adds query type lookup_term and TermType
Browse files Browse the repository at this point in the history
  • Loading branch information
JPrevost committed Nov 8, 2023
1 parent 8151162 commit f301976
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,14 @@ def log_search_event(search_term:, source_system:)
term = Term.create_or_find_by!(phrase: search_term)
term.search_events.create!(source: source_system)
end

field :lookup_term, TermType, null: true,
description: 'Lookup a term to return information about it (bypasses logging)' do
argument :search_term, String, required: true
end

def lookup_term(search_term:)
term = Term.find_by(phrase: search_term)
end
end
end
16 changes: 16 additions & 0 deletions app/graphql/types/term_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Types
class TermType < Types::BaseObject
field :id, ID, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :phrase, String, null: false
field :occurence_count, Integer
field :search_events, [SearchEventType], null: false

def occurence_count
@object.search_events.count
end
end
end

0 comments on commit f301976

Please sign in to comment.