-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Support lazy objects - Adds field extension that supports lazy object resolution and type assignment - Adds field extension to _entities field * test: Scope lazy class - Scopes lazy object class within let block - Resolves other rubocop issues
- Loading branch information
Showing
3 changed files
with
64 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class EntityTypeResolutionExtension < GraphQL::Schema::FieldExtension | ||
def after_resolve(value:, context:, **_rest) | ||
synced_value = | ||
value.map do |type, result| | ||
[type, context.query.schema.sync_lazy(result)] | ||
end | ||
|
||
# TODO: This isn't 100% correct: if (for some reason) 2 different resolve_reference calls | ||
# return the same object, it might not have the right type | ||
# Right now, apollo-federation just adds a __typename property to the result, | ||
# but I don't really like the idea of modifying the resolved object | ||
synced_value.each { |type, result| context[result] = type } | ||
|
||
synced_value.map { |_, result| result } | ||
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