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

Dynamically generate graphql types #78

Open
gjaldon opened this issue Jun 27, 2019 · 2 comments
Open

Dynamically generate graphql types #78

gjaldon opened this issue Jun 27, 2019 · 2 comments

Comments

@gjaldon
Copy link
Owner

gjaldon commented Jun 27, 2019

This would be a useful feature for users who typically use ecto with absinthe/graphql. Would this be useful to many? Feel free to share what you think.

@cospin
Copy link

cospin commented Feb 17, 2020

Yes, please. Tired of duplicating enums for DB and for GrpahQL types. Already found some some inconsistencies.

@coop
Copy link

coop commented May 18, 2020

I got tired of this also so I implemented the following for absinthe:

defmodule GraphQL.Enum do
  defmacro ecto_enum(name, ecto_enum) do
    values = Keyword.keys(Macro.expand(ecto_enum, __CALLER__).__enum_map__())

    quote do
      enum(unquote(name), values: unquote(values))
    end
  end
end

And then wherever you defined your types:

defmodule GraphQL.Types do
  use Absinthe.Schema.Notation

  import GraphQL.Enum, only: :macros

  ecto_enum(:field, NameOfEnum)
end

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

3 participants