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 import_types/2 for A.{B, C} #1022

Merged
merged 2 commits into from
Jan 2, 2021

Conversation

maartenvanvliet
Copy link
Contributor

Fixes #937

I can reproduce issue #937 with a repo with absinthe as a dependency but not from within a test in absinthe. Has to do with the modules not being compiled (yet)

Changing https://github.com/absinthe-graphql/absinthe/blob/master/lib/absinthe/schema/notation.ex#L1683 to if Code.ensure_compiled(type_module) do fixed it. (See #534 for dealing with this in an earlier version).

Or, removing the if-clause entirely and relying on the TypeImports phase to handle this. This is what happens for ordinary imports like import_types(MyApp.Schema.Types.UnknownModule). I've done this in this PR and let failed imports add a phase error to the schema.

This could also be extended that whenever non absinthe modules are imported another error is added e.g.

defmodule Test do
end
defmodule Schema do
   use Absinthe.Schema
   import_types Test
end

The TypeImports phase could check function_exported(Test, :__absinthe_blueprint__, 0) and add an error if it's not present.

@maartenvanvliet maartenvanvliet changed the title Issues/937 Fix import_types/2 for A.{B, C} Jan 2, 2021
Absinthe.Phase.Error.t()
defp error(module, reason) do
%Absinthe.Phase.Error{
message: "Could not load module `#{module}`. It returned reason: `#{reason}`.",
Copy link
Contributor

Choose a reason for hiding this comment

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

If you inspect(module) it'll get rid of the Elixir. prefix in the output...

@binaryseed
Copy link
Contributor

This is great!

@binaryseed binaryseed merged commit 4392bfa into absinthe-graphql:master Jan 2, 2021
@maartenvanvliet maartenvanvliet deleted the issues/937 branch January 2, 2021 21:55
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.

import_types breaking change
2 participants