zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

execution.ex (2298B)


      1 defmodule Absinthe.Blueprint.Execution do
      2   @moduledoc """
      3   Blueprint Execution Data
      4 
      5   The `%Absinthe.Blueprint.Execution{}` struct holds on to the core values that
      6   drive a document's execution.
      7 
      8   Here's how the execution flow works. Given a document like:
      9   ```graphql
     10   {
     11     posts {
     12       title
     13       author { name }
     14     }
     15   }
     16   ```
     17 
     18   After all the validation happens, and we're actually going to execute this document,
     19   an `%Execution{}` struct is created. This struct is passed to each plugin's
     20   `before_resolution` callback, so that plugins can set initial values in the accumulator
     21   or context.
     22 
     23   Then the resolution phase walks the document until it hits the `posts` field.
     24   To resolve the posts field, an `%Absinthe.Resolution{}` struct is created from
     25   the `%Execution{}` struct. This resolution struct powers the normal middleware
     26   resolution process. When a field has resolved, the `:acc`, `:context`, and `:field_cache`
     27   values within the resolution struct are pulled out and used to update the execution.
     28   """
     29 
     30   alias Absinthe.Blueprint.Result
     31   alias Absinthe.Phase
     32 
     33   @type acc :: map
     34 
     35   defstruct [
     36     :adapter,
     37     :schema,
     38     fragments: %{},
     39     fields_cache: %{},
     40     validation_errors: [],
     41     result: nil,
     42     acc: %{},
     43     context: %{},
     44     root_value: %{}
     45   ]
     46 
     47   @type t :: %__MODULE__{
     48           validation_errors: [Phase.Error.t()],
     49           result: nil | Result.Object.t(),
     50           acc: acc
     51         }
     52 
     53   @type node_t ::
     54           Result.Object
     55           | Result.List
     56           | Result.Leaf
     57 
     58   def get(%{execution: %{result: nil} = exec} = bp_root, operation) do
     59     result = %Result.Object{
     60       root_value: exec.root_value,
     61       emitter: operation
     62     }
     63 
     64     %{
     65       exec
     66       | result: result,
     67         adapter: bp_root.adapter,
     68         schema: bp_root.schema,
     69         fragments: Map.new(bp_root.fragments, &{&1.name, &1})
     70     }
     71   end
     72 
     73   def get(%{execution: exec}, _) do
     74     exec
     75   end
     76 
     77   def get_result(%__MODULE__{result: nil, root_value: root_value}, operation) do
     78     %Result.Object{
     79       root_value: root_value,
     80       emitter: operation
     81     }
     82   end
     83 
     84   def get_result(%{result: result}, _, _) do
     85     result
     86   end
     87 
     88   def update(resolution, result, context, acc) do
     89     %{resolution | context: context, result: result, acc: acc}
     90   end
     91 end