formatter.ex (865B)
1 defmodule Absinthe.Formatter do 2 @moduledoc """ 3 Formatter task for graphql 4 5 Will format files with the extensions .graphql or .gql 6 7 ## Example 8 ```elixir 9 Absinthe.Formatter.format("{ version }") 10 "{\n version\n}\n" 11 ``` 12 13 14 From Elixir 1.13 onwards the Absinthe.Formatter can be added to 15 the formatter as a plugin: 16 17 ```elixir 18 # .formatter.exs 19 [ 20 # Define the desired plugins 21 plugins: [Absinthe.Formatter], 22 # Remember to update the inputs list to include the new extensions 23 inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}", "{lib, priv}/**/*.{gql,graphql}"] 24 ] 25 ``` 26 """ 27 28 def features(_opts) do 29 [sigils: [], extensions: [".graphql", ".gql"]] 30 end 31 32 def format(contents, _opts \\ []) do 33 {:ok, blueprint} = Absinthe.Phase.Parse.run(contents, []) 34 inspect(blueprint.input, pretty: true) 35 end 36 end