2017-08-18 6 views
2

Après avoir installé absinthe_plug je reçois l'erreur suivante:Absinthe.Plug pas disponible

= Compilation error in file lib/kerrigan_api_web/router.ex == 
** (UndefinedFunctionError) function KerriganApiWeb.Absinthe.Plug.init/1 is undefined (module KerriganApiWeb.Absinthe.Plug is not available) 

Voici mes DEPS

{:phoenix, "~> 1.3.0"}, 
    {:phoenix_pubsub, "~> 1.0"}, 
    {:phoenix_ecto, "~> 3.2"}, 
    {:postgrex, ">= 0.0.0"}, 
    {:phoenix_html, "~> 2.10"}, 
    {:phoenix_live_reload, "~> 1.0", only: :dev}, 
    {:gettext, "~> 0.11"}, 
    {:cowboy, "~> 1.0"}, 
    {:poison, "~> 3.1"}, 
    {:absinthe, "~> 1.3.0"}, 
    {:absinthe_plug, "~> 1.3.0"}, 
    {:absinthe_ecto, git: "https://github.com/absinthe-graphql/absinthe_ecto.git"}, 
    {:faker, "~> 0.7"}, 

Pour autant que je suis conscient que je ne avez pas besoin d'ajouter quoi que ce soit autre. J'ai suivi les étapes simples ici:

absinthe_slug

EDIT: Mon routeur

defmodule KerriganApiWeb.Router do 
    use KerriganApiWeb, :router 

    pipeline :browser do 
    plug :accepts, ["html"] 
    plug :fetch_session 
    plug :fetch_flash 
    plug :protect_from_forgery 
    plug :put_secure_browser_headers 
    end 

    pipeline :api do 
    plug :accepts, ["json"] 
    end 

    scope "/", KerriganApiWeb do 
    pipe_through :browser # Use the default browser stack 

    get "/", PageController, :index 
    resources "/hotsdata_user", UserController, except: [:new, :edit] 
    resources "/battletag_toonhandle_lookup", PlayerController, except: [:new, :edit] 

    forward "/graph", Absinthe.Plug, schema: KerriganApi.Schema 
    forward "/graphiql", Absinthe.Plug.GraphiQL, schema: KerriganApi.Schema 
    end 

end 

j'avais besoin ajouté Absinthe.Plug, mais cela n'a pas

+0

Pouvez-vous publier le contenu de 'router.ex'? – Dogbert

+0

Ajouté, voir ci-dessus. –

Répondre

5

Vous êtes de passage alias (KerriganApiWeb) à scope, qui ajoute l'alias à tous les modules transmis aux fonctions de déclaration d'itinéraire à l'intérieur. Cela convertit Absinthe.Plug en KerriganApiWeb.Absinthe.Plug dans l'appel à forward, ce qui n'est pas ce que vous voulez. Vous voulez le module Absinthe.Plug. Il y a deux façons de résoudre ce:

  1. Supprimer le Paramètre alias et l'utilisation KerriganApiWeb explicitement dans toutes les fonctions de déclaration d'itinéraire qui en ont besoin.

    scope "/" do 
        pipe_through :browser # Use the default browser stack 
    
        get "/", KerriganApiWeb.PageController, :index 
        resources "/hotsdata_user", KerriganApiWeb.UserController, except: [:new, :edit] 
        resources "/battletag_toonhandle_lookup", KerriganApiWeb.PlayerController, except: [:new, :edit] 
    
        forward "/graph", Absinthe.Plug, schema: KerriganApi.Schema 
        forward "/graphiql", Absinthe.Plug.GraphiQL, schema: KerriganApi.Schema 
    end 
    
  2. Créer une nouvelle scope avec le même chemin et pipeline et déclarer les forward routes il y a:

    scope "/", KerriganApiWeb do 
        pipe_through :browser # Use the default browser stack 
    
        get "/", PageController, :index 
        resources "/hotsdata_user", UserController, except: [:new, :edit] 
        resources "/battletag_toonhandle_lookup", PlayerController, except: [:new, :edit] 
    end 
    
    scope "/" do 
        forward "/graph", Absinthe.Plug, schema: KerriganApi.Schema 
        forward "/graphiql", Absinthe.Plug.GraphiQL, schema: KerriganApi.Schema 
    end 
    

Le Phoenix docs say que le premier va augmenter le temps de compilation de votre application. Même si ce n'était pas le cas, j'irais avec le second car je trouve cela plus lisible.

0

Vous pouvez simplement déplacer deux extrémités "/ graph" et "graphiql" hors de la portée "/".

defmodule KerriganApiWeb.Router do 
    use KerriganApiWeb, :router 

    pipeline :browser do 
    plug :accepts, ["html"] 
    plug :fetch_session 
    plug :fetch_flash 
    plug :protect_from_forgery 
    plug :put_secure_browser_headers 
    end 

    pipeline :api do 
    plug :accepts, ["json"] 
    end 

    scope "/", KerriganApiWeb do 
    pipe_through :browser # Use the default browser stack 

    get "/", PageController, :index 
    resources "/hotsdata_user", UserController, except: [:new, :edit] 
    resources "/battletag_toonhandle_lookup", PlayerController, except: [:new, :edit] 
    end 

    forward "/graph", Absinthe.Plug, schema: KerriganApi.Schema 
    forward "/graphiql", Absinthe.Plug.GraphiQL, schema: KerriganApi.Schema, interface: :advanced 

end