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

extend schema cannot parse maps in arguments #1225

Closed
kzlsakal opened this issue Feb 3, 2023 · 1 comment
Closed

extend schema cannot parse maps in arguments #1225

kzlsakal opened this issue Feb 3, 2023 · 1 comment

Comments

@kzlsakal
Copy link
Contributor

kzlsakal commented Feb 3, 2023

Environment

  • Elixir version (elixir -v): Elixir 1.14.0 (compiled with Erlang/OTP 25)
  • Absinthe version (mix deps | grep absinthe): 1.7.1
  • Client Framework and version (Relay, Apollo, etc): n/a

Expected behavior

Extending the schema with the link directive and its arguments should result the following SDL output:

schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: ["@key", "@tag", {name: "@override", as: "@replace"}]) {
  query: RootQueryType
}

type RootQueryType {
  hello: String
}

Actual behavior

The map is eventually supplied to Absinthe.Blueprint.Input.parse/1 but in AST format, therefore we get the following compile-time error:

(FunctionClauseError) no function clause matching in Absinthe.Blueprint.Input.parse/1    
    
    The following arguments were given to Absinthe.Blueprint.Input.parse/1:
    
        # 1
        {:quote, [closing: [line: 37, column: 36], line: 37, column: 10], [{:%{}, [closing: [line: 37, column: 35], line: 37, column: 17], [name: "@override"]}]}
    
    Attempted function clauses (showing 8 out of 8):
    
        def parse(-%struct{} = value-) when -struct === Absinthe.Blueprint.Input.Boolean- or -struct === Absinthe.Blueprint.Input.Enum- or -struct === Absinthe.Blueprint.Input.Field- or -struct === Absinthe.Blueprint.Input.Float- or -struct === Absinthe.Blueprint.Input.Integer- or -struct === Absinthe.Blueprint.Input.List- or -struct === Absinthe.Blueprint.Input.Object- or -struct === Absinthe.Blueprint.Input.String- or -struct === Absinthe.Blueprint.Input.Null-
        def parse(+value+) when -is_integer(value)-
        def parse(+value+) when -is_float(value)-
        def parse(+value+) when -value == nil-
        def parse(+value+) when -is_binary(value)-
        def parse(+value+) when -is_boolean(value)-
        def parse(+value+) when -is_list(value)-
        def parse(+value+) when -is_map(value)-

Stacktrace:
  │ (absinthe 1.7.1) lib/absinthe/blueprint/input.ex:37: Absinthe.Blueprint.Input.parse/1
  │ (absinthe 1.7.1) lib/absinthe/blueprint/input.ex:67: anonymous fn/1 in Absinthe.Blueprint.Input.parse/1
  │ (elixir 1.14.0) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
  │ (absinthe 1.7.1) lib/absinthe/blueprint/input.ex:66: Absinthe.Blueprint.Input.parse/1
  │ (absinthe 1.7.1) lib/absinthe/blueprint/input.ex:67: anonymous fn/1 in Absinthe.Blueprint.Input.parse/1
  │ (elixir 1.14.0) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
  │ (elixir 1.14.0) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
  │ (absinthe 1.7.1) lib/absinthe/blueprint/input.ex:66: Absinthe.Blueprint.Input.parse/1

Relevant Schema/Middleware Code

defmodule MacroSchemaWithRenamedDirectives do
  use Absinthe.Schema

  extend schema do
    directive :link,
      url: "https://specs.apollo.dev/federation/v2.0",
      import: ["@key", "@tag", %{name: "@override", as: "@replace"}]
    end

  query do
    field :hello, :string
  end
end

Additional Information

  • Trying a keyword list instead of a map yielded a similar error when the parse function received a tuple of {:name, "@override"} for the first item.
  • Trying a string literal doesn't work because the spec expects an object - related docs.
  • Removing %{name: "@override", as: "@replace"} from the import argument in the example code results in a successful compilation as expected.
@kzlsakal
Copy link
Contributor Author

Fixed by #1226

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