25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/gql_serializer/extensions.rb', line 25
def as_gql(query = nil, options = {})
options_with_defaults = GqlSerializer.configuration.to_h.merge(options)
query_hasharray = query ? GqlSerializer.parse_query(query) : []
include_hasharray = GqlSerializer.query_include(self.class, query_hasharray)
if options_with_defaults[:preload]
GqlSerializer._preload([self], include_hasharray)
GqlSerializer.serialize(self, query_hasharray, options_with_defaults)
else
record = include_hasharray.empty? ? self : self.class.where(id: self).includes(include_hasharray).first
GqlSerializer.serialize(record, query_hasharray, options_with_defaults)
end
end
|