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

Providing functions to meta no longer works #928

Closed
gabrielpra1 opened this issue May 20, 2020 · 7 comments
Closed

Providing functions to meta no longer works #928

gabrielpra1 opened this issue May 20, 2020 · 7 comments

Comments

@gabrielpra1
Copy link

Environment

  • Elixir version (elixir -v): 1.10.2
  • Absinthe version (mix deps | grep absinthe): 1.5.1
  • Client Framework and version (Relay, Apollo, etc): Not relevant

Expected behavior

I expected the following to work (works in 1.4.16):

object :user do
  field :email, :string do
    meta([private: & !&1.is_email_public])
  end
end

When inspecting the meta[:private] field in 1.4.16, in a middleware:

def call(resolution, [object: %Type.Object{fields: fields} = object, field: field]) do
  fields[field] |> Type.meta(:private) |> IO.inspect() 
end

I get the function: #Function<5.7636899/1 in Rajska.FieldAuthorizationTest.Schema.__absinthe_type__/1>

Actual behavior

In 1.5.1, however, with the same code I'm getting the AST instead of the function:

{:&, [line: 84],
 [
   {:case, [optimize_boolean: true],
    [
      {{:., [line: 84], [{:&, [line: 84], [1]}, :is_email_public]},
       [no_parens: true, line: 84], []},
      [
        do: [
          {:->, [],
           [
             [
               {:when, [],
                [
                  {:x, [counter: {Rajska.FieldAuthorizationTest.Schema, 61}],
                   Kernel},
                  {{:., [], [:erlang, :orelse]}, [],
                   [
                     {{:., [], [:erlang, :"=:="]}, [],
                      [
                        {:x,
                         [counter: {Rajska.FieldAuthorizationTest.Schema, 61}],
                         Kernel},
                        false
                      ]},
                     {{:., [], [:erlang, :"=:="]}, [],
                      [
                        {:x,
                         [counter: {Rajska.FieldAuthorizationTest.Schema, 61}],
                         Kernel},
                        nil
                      ]}
                   ]}
                ]}
             ],
             true
           ]},
          {:->, [], [[{:_, [], Kernel}], false]}
        ]
      ]
    ]}
 ]}

Was this change intentional? By providing the AST instead of the actual value, it's now hard to use more complex structures in the meta, such as functions and maps, which is something some libraries depend upon.

@moperacz
Copy link

moperacz commented Jun 8, 2020

any news about this?

@tlvenn
Copy link
Member

tlvenn commented Sep 30, 2020

Hi, I am wondering if the work @Hermanverschooten did to fix meta on fields would not actually fix this issue as well. Can you try to reproduce on master ? Thanks.

@benwilson512
Copy link
Contributor

@tlvenn do functions work if you use the persistent term backend?

@gabrielpra1
Copy link
Author

gabrielpra1 commented Oct 5, 2020

@tlvenn I tried it again with the master version and still getting the same error, both when using the shortcut syntax and the meta/1 syntax 😢

I'm still not sure if this is how it's supposed to work, but I fixed my problem by evaluating the AST at runtime before trying to execute the function: jungsoft/rajska@01f716a.

@benwilson512 Should we evaluate the AST inside Absinthe or is it expected that the library clients do that on their own, like I did in that commit?

@stavro
Copy link
Contributor

stavro commented Nov 4, 2020

Duplicate issue that was already closed for this: #737

I still think it's a valuable property to keep, but apparently the complexity wasn't worth it, from @benwilson512 .

@benwilson512
Copy link
Contributor

Hey folks. I believe as we prep to switch to using :persistent_term as the backend in the next release this will be come possible.

@binaryseed
Copy link
Contributor

This can be accomplished in 1.5 using hydrate. Here's an example of dynamic Enum value hydration in the absinthe tests:

https://github.com/absinthe-graphql/absinthe/blob/master/test/absinthe/schema/hydrate_dynamic_values_test.exs

In your case, you can set the meta:

{:meta, dynamic_meta()}

Documented here: https://hexdocs.pm/absinthe/Absinthe.Schema.html#c:hydrate/2

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

6 participants