Skip to content

Commit

Permalink
Using raw results
Browse files Browse the repository at this point in the history
The results from GraphQL Client are already fancy objects with
accessors; no need to deal with JSONs.
  • Loading branch information
psguazz committed Feb 26, 2024
1 parent e37215f commit a8bf86f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/dato_cms_graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,12 @@ def headers(context)
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
end

def self._query(query, variables: {})
response = Client.query(query, variables: variables)
response.data.items
end

def self.query(query, variables: {})
Client.query(query, variables: variables).data.items.map do |result|
result.to_h.deep_transform_keys { |k| k.underscore }
end
Client.query(query, variables: variables).data
end

def self.query_one(query, variables: {})
Client.query(query, variables: variables).data.item.to_h.deep_transform_keys { |k| k.underscore }
Client.query(query, variables: variables).data
end

def self.count(query, variables: {})
Expand Down
1 change: 1 addition & 0 deletions lib/dato_cms_graphql/fields.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module DatoCmsGraphql
class Fields
attr_accessor :rv

def initialize(fields)
@fields = fields
@rv = ""
Expand Down

0 comments on commit a8bf86f

Please sign in to comment.