Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline module not compiled at schema compilation time #1351

Open
jdewar opened this issue Jan 23, 2025 · 0 comments
Open

Pipeline module not compiled at schema compilation time #1351

jdewar opened this issue Jan 23, 2025 · 0 comments

Comments

@jdewar
Copy link

jdewar commented Jan 23, 2025

I ran into the error described here: #1331 (comment) sometime ago and used the unreleased commit (ref: 3d0823bd71c2ebb94357a5588c723e053de8c66a) to fix my compilation problem, but the problem has returned.

== Compilation error in file lib/sga/frontend_schema.ex ==
** (ArgumentError) could not load module SGA.Pipeline.PublicFieldVisibility due to reason :nofile
    (elixir 1.17.2) lib/code.ex:1837: Code.ensure_loaded!/1
    (absinthe 1.7.8) lib/absinthe/schema.ex:382: anonymous fn/3 in Absinthe.Schema.apply_modifiers/3
    (elixir 1.17.2) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3
    (absinthe 1.7.8) lib/absinthe/schema.ex:405: Absinthe.Schema.__after_compile__/2
    (stdlib 5.2) lists.erl:1594: :lists.foldl/3

Removing _build fixes it at the time, but it has recurred 3 times across 2 different developers in the past few weeks. Here is the pipeline definition and how it is used, in case I'm 'holding it wrong':


public_field_visibility.ex:

defmodule SGA.Pipeline.PublicFieldVisibility do
  alias Absinthe.{Blueprint, Phase, Pipeline}

  # Add this module to the pipeline of phases
  # to run on the schema
  def pipeline(pipeline) do
    Pipeline.insert_after(pipeline, Phase.Schema.TypeImports, __MODULE__)
  end

  # Here's the blueprint of the schema, let's do whatever we want with it.
  def run(%Blueprint{} = blueprint, _) do
    blueprint =
      update_in(
        blueprint,
        [
          Access.key!(:schema_definitions),
          Access.all(),
          Access.key!(:type_definitions),
          Access.all()
        ],
        &update_type_def/1
      )

    {:ok, blueprint}
  end

  defp update_type_def(%Absinthe.Type.Object{fields: type_fields} = type_def) do
    public_fields = Absinthe.Type.meta(type_def, :public_fields) || []
    public_fields = [:id | public_fields]
    filtered_fields = filter_fields(public_fields, type_fields)

    %{type_def | fields: filtered_fields}
  end

  defp update_type_def(type_def), do: type_def

  # we probably want to whitelist certain fields (specifically Relay fields like pageInfo { hasNextPage etc... })
  defp filter_fields(public_fields, type_def_fields) do
    Enum.filter(type_def_fields, &(&1.identifier in public_fields))
  end
end

frontend_schema.ex:

use Absinthe.Schema
use Absinthe.Relay.Schema, :modern
@pipeline_modifier SGA.Pipeline.PublicFieldVisibility

import_types ...

router.ex:

forward("/graphql", Absinthe.Plug,
  schema: SGA.FrontendSchema,
  before_send: {SGA.Context.Frontend, :before_send}
)

Since originally fixing the problem ancillary things have changed in the codebase, like Elixir version updated to 1.17.2, so I am now using the most recent commit, {:absinthe, github: "absinthe-graphql/absinthe", ref: "d28ebb4fdb16c195a41259ea12552800a695df42", override: true}, but updating absinthe did not make the error go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant