How to install PostgreSQL and pgAdmin4 on Ubuntu 18.04

1. Install PostgreSQL $ sudo apt update $ sudo apt install postgresql postgresql-contrib 2. Update password for postpres user $ sudo -u postgres psql postgres=# ALTER USER user_name WITH PASSWORD 'new_password'; postgres=# \q 3. Install Python PIP for Ubuntu $ sudo apt update $ sudo apt install python3-pip 4. Get the PgAdmin 4 Python Installer at https://www.pgadmin.org/download/pgadmin-4-python-wheel 5. Install pgAdmin4 $ pip install ~/Downloads/pgadmin4*.whl Or for a System wide installation: $ sudo pip install ~/Downloads/pgadmin4*.whl 6. Locate PgAdmin 4 Script $ sudo updatedb $ locate pgAdmin4.py Copy the path displayed from above command. I call it PATH /pgAdmin4.py from now 7. Create config_local.py file for pgAdmin4 local config, add content and save it $ vim PATH /config_local.py import os SERVER_MODE = False DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/')) LOG_FILE = os.path.join(DATA_DIR...

Elixir Phoenix Using GraphQL Basic Flow(My Notes) - Part 1

Elixir Phoenix GraphQL Basic Flow


Here we are going to see the basic flow in running a sample GraphQL project.

Step1 : Create a Phoenix project and do ecto migration stuff


mix phx.new --no-brunch --no-html instagram

in config/dev.exs change the password
# Configure your database
config :instagram, Instagram.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "123456",
  database: "instagram_dev",
  hostname: "localhost",
  pool_size: 10

  mix ecto.create

Step 2 : Install Absinthe dependencies


  {:absinthe_phoenix, "~> 1.4"}

install using this command

  mix deps.get

Step 3: Create file and folders as belows


#File
lib/instagram_web/schema.ex
#Folder
lib/instagram_web/schema
lib/instagram_web/resolvers


in instagram_web/schema.ex just put a skeleton
defmodule InstagramWeb.Schema do
  use Absinthe.Schema

  query do

  end
end

Edit the instagram_web/router.ex file add the below code

  scope "/" do
    pipe_through :api

    forward "/api/graphql",
            Absinthe.Plug,
            schema: InstagramWeb.Schema

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


So now when you run this URL http://localhost:4000/api/graphiql you will get a graphql interface on the browser.

But it show error for now since the steps are not completed.

Step 4 : Create types in Schema folder


Inside the schema folder create a file named photo_types.ex where you mention types of the photo object

Just a sample skeleton of photo object types

 defmodule  InstagramWeb.Schema.PhotoTypes do
  use Absinthe.Schema.Notation

  object :photo do
    field :image_url, non_null(:string) 
  end
end

Step 5 : Create a resolver file where you place all the queries


Inside the resolver folder create a file name photo.ex

defmodule InstagramWeb.Resolvers.Photo do
    def create(_,_,_) do
        {:ok, {image_url: "Hey its working"}}
    end
end


Step 6 : Call the above resolver fn in schema.ex file


defmodule InstagramWeb.Schema do
  use Absinthe.Schema

  alias InstagramWeb.Resolvers

  import_types __MODULE__.PhotoTypes

  query do
    field :photos, list_of(:photo) do
      resolve &Resolvers.Photo.create/3
    end
  end
end


Output :





Comments

Popular posts from this blog

Elixir Ecto - My Notes

Phoenix Channels