That should be enough to have something going. The products resolver looks like this: # lib/graphql_tutorial_web/resolvers/products.exĭefmodule do Resolvers will be the modules that connects to the products context. ![]() Note that in the code above, I refer to _products. I need to add the file: # lib/graphql_tutorial_web/schema/product_types.exĭefmodule do That is the module that will handle specify and handle calling the product part of the api. It will be a single schema file where I build the entire api.Ĭreate the file: # lib/graphql_tutorial_web/schema.ex Remember that in the router, I specified a specific schema. Now that we have the functional pieces in place, let's configure our Phoenix router to wire this into HTTP: In blogweb/router.ex: defmodule BlogWeb.Router do use BlogWeb, :router pipeline :api do plug :accepts, 'json' end scope '/api' do pipethrough :api. So what I want to do is to just hook up with that. The tutorial content here is intentionally focused on the Absinthe-specific code. Note that the Absinthe Plug we are adding are pointing to a Schema file that I also need to create before I can start the server.Īlso note that the Graphiql interface are only accessible in dev.Īs I mentioned above, we already have an existing json endpoint and a database storage for products. # lib/graphql_tutorial_web/router.exįorward "/", Absinthe.Plug, schema: GraphqlTutorialWeb.Schemaįorward "/graphiql",, schema: GraphqlTutorialWeb.Schema Next is to add routes for both the graphql schema and Graphiql, the visual query helper and documentation tool for the api. ![]() In this tutorial, I will go into also adding the same functionality in Phoenix in GraphQl with the Absinthe library.Īdd Absinthe and Absinthe Plug to the mix file: # mix.exs In the last tutorial, there I had an app with a simple rest api that was authenticated with Guardian and Json Web Token.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |