Slide 17
Slide 17 text
FooOperation and BarOperation might need to
fetch data from other services
class FooOperation
QUERY = "query(bazId: $ID!) { baz(id: $bazId) { a } }"
def self.execute!(baz_id)
data = client.execute(query: QUERY, variables: { bazId: baz_id })
ActiveRecord::Base.transaction do
Foo.create!(a: data.baz.a)
BarOperation.execute!(baz_id)
end
end
end
class BarOperation
QUERY = "query(id: $ID!) { baz(id: $id) { b { c, d } } }"
def self.execute!(baz_id)
data = client.execute(query: QUERY, variables: { bazId: baz_id })
Bar.create!(c: data.baz.b.c, d: data.baz.b.d)
# more complicated logics...
end
end