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

Fix #650 (@desc not working on field arguments) #738

Merged
merged 2 commits into from
May 29, 2019

Conversation

darrenclark
Copy link
Contributor

Approach I took

Since Absinthe.Blueprint.Schema.build_types/3 doesn't push a InputValueDefinition onto the stack (it sets is on the FieldDefinition), a {:desc, _} tuple doesn't get applied to the Schema.InputValueDefinition.

I added a clause to build_types/3 that peeks ahead of a InputValueDefinition to consume the {:desc, _} tuple

Other thoughts

Looking back, would it make more sense to instead to:

  • Have Absinthe.Schema.Notation create a :close element after Schema.InputValueDefinition (and any {:desc, _} for that argument), and,
  • put the Schema.InputValueDefinition on the stack in build_types/3, then wait for the :close to set it on the Schema.FieldDefinition, and
  • let the existing build_types/3 clause for {:desc, _} handle setting description on the Schema.InputValueDefinition

Thoughts?

Also fixes the `:name` option not working for arguments
Copy link
Contributor

@benwilson512 benwilson512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on!

In theory, the only clause that should be necessary within build types is

defp build_types([{:desc, desc} | rest], [item | stack], buff) do
. Doing a lookahead as you did also works but the look behind is more generalized and ought to work here as well. One issue you fixed was


[
get_desc(ref)
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, if we weren't adding the get_desc call here, then it wouldn't have ended up on the stack at all.

@@ -1201,15 +1201,19 @@ defmodule Absinthe.Schema.Notation do
attrs
|> handle_deprecate
|> Keyword.put(:identifier, identifier)
|> Keyword.put(:name, to_string(identifier))
|> Keyword.put_new(:name, to_string(identifier))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@@ -141,6 +141,11 @@ defmodule Absinthe.Blueprint.Schema do
build_types(rest, [enum | stack], buff)
end

defp build_types([%Schema.InputValueDefinition{} = arg, {:desc, desc} | rest], stack, buff) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's weird is that this shouldn't be necessary because the

defp build_types([{:desc, desc} | rest], [item | stack], buff) do
clause should already handle this. Doing a lookahead to find the desc should be exactly identical to just moving one more item through the stack, matching on desc, and modifying the previous thing.

However if I remove this clause locally, the tests no longer pass. Investigating.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah of course, this is what you were saying, I see it now.

defp build_types([%Schema.InputValueDefinition{} = arg | rest], [field | stack], buff) do
eagerly removes the InputValue definition from the stack, so further items can't do anything to it.

Copy link
Contributor

@benwilson512 benwilson512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darrenclark Thanks again for taking this on, and your thoughtful remarks in the description. I do think after looking through this that I'd prefer to treat arg as scoped so that there is only one {:desc oriented clause within build_types. This may be helpful for other macros as well, if I had to guess value probably has this issue too. I don't really want to add special case look-aheads for each of those macros.

@darrenclark
Copy link
Contributor Author

Any thoughts on if I should go as far as adding it to @scoped_defs and having it handled via record!?

Or just update record_arg! to emit a :close as well?

@scoped_types [
Schema.ObjectTypeDefinition,
Schema.FieldDefinition,
Schema.ScalarTypeDefinition,
Schema.EnumTypeDefinition,
Schema.EnumValueDefinition,
Schema.InputObjectTypeDefinition,
Schema.UnionTypeDefinition,
Schema.InterfaceTypeDefinition,
Schema.DirectiveDefinition
]
def record!(env, type, identifier, attrs, block) when type in @scoped_types do
attrs = expand_ast(attrs, env)
scoped_def(env, type, identifier, attrs, block)
end

@benwilson512
Copy link
Contributor

@darrenclark go ahead and add it to scoped defs.

@darrenclark
Copy link
Contributor Author

@benwilson512 updated

@benwilson512 benwilson512 merged commit fc171a8 into absinthe-graphql:master May 29, 2019
@benwilson512
Copy link
Contributor

Thank you!!!

@FloatingFront
Copy link

Likewise thanks!

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

Successfully merging this pull request may close these issues.

@desc does not work for field arguments
3 participants