-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-use loaders after they have been performed, but clear on mutation (#…
…63)
- Loading branch information
1 parent
058213b
commit f815fe6
Showing
7 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,54 @@ | ||
module GraphQL::Batch | ||
module Setup | ||
extend self | ||
class Setup | ||
class << self | ||
def start_batching | ||
raise NestedError if GraphQL::Batch::Executor.current | ||
GraphQL::Batch::Executor.current = GraphQL::Batch::Executor.new | ||
end | ||
|
||
def end_batching | ||
GraphQL::Batch::Executor.current = nil | ||
end | ||
|
||
def instrument_field(schema, type, field) | ||
return field unless type == schema.mutation | ||
old_resolve_proc = field.resolve_proc | ||
field.redefine do | ||
resolve ->(obj, args, ctx) { | ||
GraphQL::Batch::Executor.current.clear | ||
begin | ||
Promise.sync(old_resolve_proc.call(obj, args, ctx)) | ||
ensure | ||
GraphQL::Batch::Executor.current.clear | ||
end | ||
} | ||
end | ||
end | ||
|
||
def before_query(query) | ||
warn "Deprecated graphql-batch setup `instrument(:query, GraphQL::Batch::Setup)`, replace with `use GraphQL::Batch`" | ||
start_batching | ||
end | ||
|
||
def after_query(query) | ||
end_batching | ||
end | ||
end | ||
|
||
def initialize(schema) | ||
@schema = schema | ||
end | ||
|
||
def before_query(query) | ||
raise NestedError if GraphQL::Batch::Executor.current | ||
GraphQL::Batch::Executor.current = GraphQL::Batch::Executor.new | ||
Setup.start_batching | ||
end | ||
|
||
def after_query(query) | ||
GraphQL::Batch::Executor.current = nil | ||
Setup.end_batching | ||
end | ||
|
||
def instrument(type, field) | ||
Setup.instrument_field(@schema, type, field) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
module GraphQL::Batch | ||
module SetupMultiplex | ||
extend self | ||
class SetupMultiplex | ||
def initialize(schema) | ||
@schema = schema | ||
end | ||
|
||
def before_multiplex(multiplex) | ||
raise NestedError if GraphQL::Batch::Executor.current | ||
GraphQL::Batch::Executor.current = GraphQL::Batch::Executor.new | ||
Setup.start_batching | ||
end | ||
|
||
def after_multiplex(multiplex) | ||
GraphQL::Batch::Executor.current = nil | ||
Setup.end_batching | ||
end | ||
|
||
def instrument(type, field) | ||
Setup.instrument_field(@schema, type, field) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters