Class: Tapioca::Dsl::Compilers::FragmentResponseTypes
- Inherits:
-
Compiler
- Object
- Compiler
- Tapioca::Dsl::Compilers::FragmentResponseTypes
- Extended by:
- T::Sig
- Defined in:
- lib/tapioca/dsl/compilers/fragment_response_types.rb
Overview
Declares the response objects the query methods return, so that
client.get_ledger(...).data.ledger.name typechecks.
graphql-client builds those objects at runtime from anonymous classes whose
fields are served by method_missing, so there is nothing to reflect on.
The shape is instead derived statically from each operation's selection set
and the pinned Schema -- the same two inputs graphql-client itself uses,
which is what makes the declared types agree with the runtime.
In particular graphql-client refuses at runtime to read a field the
operation did not select (ImplicitlyFetchedFieldError), so a type derived
from the selection set cannot promise more than the runtime allows.
Emitted under FragmentClient::Responses::<Operation>, one nested class per
selection level.
Constant Summary collapse
- ConstantType =
type_member { { fixed: T.class_of(FragmentClient) } }
- SCALARS =
Scalar names this Schema uses, mapped for
GraphqlSorbetTypes. T.let( { 'String' => '::String', 'ID' => '::String', 'SafeString' => '::String', 'ParameterizedString' => '::String', 'Date' => '::String', 'DateTime' => '::String', 'FirstMoment' => '::String', 'LastMoment' => '::String', 'Period' => '::String', 'PeriodFilter' => '::String', 'UTCOffset' => '::String', 'Int96' => '::String', 'Int' => '::Integer', 'Float' => '::Float', 'Boolean' => 'T::Boolean', 'JSON' => 'T.untyped', 'Parameters' => 'T.untyped' }.freeze, T::Hash[String, String] )
- RESPONSES_NAMESPACE =
'FragmentClient::Responses'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.gather_constants ⇒ Object
52 53 54 |
# File 'lib/tapioca/dsl/compilers/fragment_response_types.rb', line 52 def gather_constants [FragmentClient] end |
Instance Method Details
#decorate ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tapioca/dsl/compilers/fragment_response_types.rb', line 58 def decorate operations = FragmentGraphQl.operations return if operations.empty? root.create_module(RESPONSES_NAMESPACE) do |namespace| operations.keys.sort.each do |name| declare_operation(namespace, name, T.must(operations[name])) end end end |