Skip to content

Commit

Permalink
Add Preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
abshierjoel committed Oct 3, 2021
1 parent b6339aa commit 796e50c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule UserPreferences.Preferences do
defmodule UserPreferences.Preference do
use Ecto.Schema
import Ecto.Changeset

Expand All @@ -11,8 +11,8 @@ defmodule UserPreferences.Preferences do
end

@doc false
def changeset(preferences, attrs) do
preferences
def changeset(preference, attrs) do
preference
|> cast(attrs, [:likes_emails, :likes_phone_calls])
|> validate_required([:likes_emails, :likes_phone_calls])
end
Expand Down
7 changes: 4 additions & 3 deletions lib/gql_preferences/users.ex → lib/gql_preferences/user.ex
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
defmodule UserPreferences.Users do
defmodule UserPreferences.User do
use Ecto.Schema
import Ecto.Changeset

schema "users" do
field :email, :string
field :name, :string
has_one :preference, UserPreferences.Preference

timestamps()
end

@doc false
def changeset(users, attrs) do
users
def changeset(user, attrs) do
user
|> cast(attrs, [:name, :email])
|> validate_required([:name, :email])
end
Expand Down
11 changes: 8 additions & 3 deletions lib/gql_preferences_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ defmodule UserPreferencesWeb.Router do
plug :accepts, ["json"]
end

scope "/", UserPreferencesWeb do
pipe_through :browser
scope "/" do
pipe_through :api

get "/", PageController, :index
forward "/api", Absinthe.Plug,
schema: UserPreferencesWeb.Schema

forward "/graphiql", Absinthe.Plug.GraphiQL,
schema: UserPreferencesWeb.Schema,
interface: :simple
end

# Other scopes may use custom stacks.
Expand Down
6 changes: 5 additions & 1 deletion lib/gql_preferences_web/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ defmodule UserPreferencesWeb.Schema do
end
end

mutation
mutation do
field :create_user, type: :user do
arg
end
end

object :user do
field :id, :id
Expand Down

0 comments on commit 796e50c

Please sign in to comment.