GraphQL Declarative & Hierarchical Strongly Typed Concurrent Application-Focused http://absinthe-graphql.org Ben Wilson @benwilson512 some reasons to like
But wait! there’s more… def add_filter(:date, date, filters) do case Calendar.parse(date) do {:ok, date} -> Map.put(filters, :date, date) _ -> filters end end def add_filter(key, value, filters) do Map.put(filters, key, value) end
{ events(location_id: 4, date: "2016-08-30") { name } } http://absinthe-graphql.org Ben Wilson @benwilson512 Using: def events(filters, _) do {:ok, Event.list(filters)} end
{ events(location_id: 4, date: "2016-08-30") { name } } http://absinthe-graphql.org Ben Wilson @benwilson512 def events(filters, _) do ... end field :events, list_of(:event) do arg :date, :date arg :location_id, :id arg :name, :string resolve &events/2 end
http://absinthe-graphql.org Ben Wilson @benwilson512 Custom Scalar @desc """ ISO Date 2015-11-21 2015-01-02 """ scalar :date do parse &Calendar.Date.Parse.iso8601/1 serialize &Calendar.Date.Format.iso8601/1 end
http://absinthe-graphql.org Ben Wilson @benwilson512 Built-in Scalar @desc """ The `String` scalar type represents textual data, represented as UTF-8 character sequences. ... """ scalar :string do serialize &to_string/1 parse &parse_string/1 end
http://absinthe-graphql.org Ben Wilson @benwilson512 @desc """ A planned occasion, like a meeting or conference """ object :event do @desc "The date on which the event occurs" field :date, non_null(:date) @desc "The location at which the event happens" field :location, non_null(:location) @desc "The name of the event" field :name, non_null(:string) field :attendees, list_of(:person) end
Schema Errors web/schema.ex:12: Users :usre is not defined in your schema. Types must exist if referenced. object :organization do field :name, :string field :users, list_of(:usre) end http://absinthe-graphql.org Ben Wilson @benwilson512
Schema Compilation http://absinthe-graphql.org Ben Wilson @benwilson512 @desc "A faction in the Star Wars saga" node object :faction do @desc "The name of the faction" field :name, :string @desc "The ships used by the faction." connection field :ships, node_type: :ship do resolve &Ship.list/2 end end
Projection http://absinthe-graphql.org Ben Wilson @benwilson512 def events(filters, _) do {:ok Event.list(filters)} end def list(filters) do Event |> where(^filters) |> Repo.all end