Skip to content

Setup Phoenix app to reload schema.json file whenever GraphQL schema files change

Sean Abrahams edited this page Mar 11, 2016 · 5 revisions

Add eye_drops as a dependency to your app.

In your config/dev.exs add eye_drops to your watchers list and add config for eye_drops:

watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin"],
           mix: ["eye_drops"]]

config :eye_drops,
  tasks: [
    %{
      id: :graphql_update_schema,
      name: "Update GraphQL Schema",
      cmd: "mix graphql.gen.schema",
      paths: ["web/graphql/*"] # path to graphql files
    }
  ]

Create lib/mix/tasks/graphql.gen.schema.ex file with the following contents:

defmodule Mix.Tasks.Graphql.Gen.Schema do
  @moduledoc """
  Updates GraphQL schema.json file.
  """

  use Mix.Task

  @doc false
  def run(_args) do
    GraphQL.Relay.generate_schema_json!
    System.cmd("brunch", ["build"])
  end
end
Clone this wiki locally