We created a posts query that has a typeī_posts/3 function. Queries are defined as fields inside the GraphQL object returned by This uses a resolver module we've created (again, to match the Phoenix context naming)Īt blog_web/resolvers/content.ex: defmodule do def list_posts ( _parent, _args, _resolution ) do end end Their definitions in Absinthe.Schema and. list_posts / 3 end end end More informationįor more information on the macros available to build a schema, see In blog_web/schema.ex: defmodule BlogWeb.Schema do use Absinthe.Schema import_types alias BlogWeb.Resolvers query do "Get all posts" field :posts, list_of ( :post ) do resolve & Resolvers.Content. With our type completed we can now write a basic schema that will let If you're curious what the type :id is used by the :id field, seeĪn opaque value, and in our case is just the regular Ecto id, but If really needed, we could provide aĬustom type name as a :name option to the object macro. The GraphQL specification requires that type names be unique, TitleCased words.Ībsinthe does this automatically for us, extrapolating from our type identifier In blog_web/schema/content_types.ex: defmodule do use object :post do field :id, :id field :title, :string field :body, :string end end Since our Post Ecto schema lives in the Blog.Content PhoenixĬontext, we'll define its GraphQL counterpart type, :post, in a To use when representing a set of key value pairs. Types on top of which all of our types will beīuilt. Let's create some basic typesįor our schema, starting with a :post. The first thing our viewers want is a list of our blog posts, so
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |