Skip to content

Commit

Permalink
give request to executables rather than context.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmac committed Dec 27, 2023
1 parent dc15230 commit a44b534
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ It's perfectly fine to mix and match schemas that implement an `_entities` query

## Executables

An executable resource performs location-specific GraphQL requests. Executables may be `GraphQL::Schema` classes, or any object that responds to `.call(location, source, variables, context)` and returns a raw GraphQL response:
An executable resource performs location-specific GraphQL requests. Executables may be `GraphQL::Schema` classes, or any object that responds to `.call(location, source, variables, request)` and returns a raw GraphQL response:

```ruby
class MyExecutable
def call(location, source, variables, context)
def call(location, source, variables, request)
# process a GraphQL request...
return {
"data" => { ... },
Expand Down Expand Up @@ -392,7 +392,7 @@ supergraph = GraphQL::Stitching::Composer.new.perform({
},
fourth: {
schema: FourthSchema,
executable: ->(loc, query, vars, ctx) { ... },
executable: ->(loc, query, vars, req) { ... },
},
})
```
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/stitching/executor/boundary_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def fetch(ops)
@executor.request.operation_directives,
)
variables = @executor.request.variables.slice(*variable_names)
raw_result = @executor.supergraph.execute_at_location(@location, query_document, variables, @executor.request.context)
raw_result = @executor.supergraph.execute_at_location(@location, query_document, variables, @executor.request)
@executor.query_count += 1

merge_results!(origin_sets_by_operation, raw_result.dig("data"))
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/stitching/executor/root_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def fetch(ops)
@executor.request.operation_directives,
)
query_variables = @executor.request.variables.slice(*op.variables.keys)
result = @executor.supergraph.execute_at_location(op.location, query_document, query_variables, @executor.request.context)
result = @executor.supergraph.execute_at_location(op.location, query_document, query_variables, @executor.request)
@executor.query_count += 1

@executor.data.merge!(result["data"]) if result["data"]
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/stitching/http_executable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(url:, headers:{})
@headers = { "Content-Type" => "application/json" }.merge!(headers)
end

def call(_location, document, variables, _context)
def call(_location, document, variables, _request)
response = Net::HTTP.post(
URI(@url),
JSON.generate({ "query" => document, "variables" => variables }),
Expand Down
6 changes: 3 additions & 3 deletions lib/graphql/stitching/supergraph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def memoized_schema_fields(type_name)
end
end

def execute_at_location(location, source, variables, context)
def execute_at_location(location, source, variables, request)
executable = executables[location]

if executable.nil?
Expand All @@ -218,11 +218,11 @@ def execute_at_location(location, source, variables, context)
executable.execute(
query: source,
variables: variables,
context: context.frozen? ? context.dup : context,
context: request.context.frozen? ? request.context.dup : request.context,
validate: false,
)
elsif executable.respond_to?(:call)
executable.call(location, source, variables, context)
executable.call(location, source, variables, request)
else
raise StitchingError, "Missing valid executable for #{location} location."
end
Expand Down

0 comments on commit a44b534

Please sign in to comment.