As mentioned in the LPW "trailer" for shiny new toys, I will be giving a talk on graphql-perl. I promised to talk about introspecting a DBIx::Class schema to make a GraphQL interface. This is how!

The API for a "convert plugin" for graphql-perl is simple: implement a to_graphql , and optionally a from_graphql method. The to_graphql returns a hash-ref with three keys:

schema

root_value

resolver

These are all the entities, apart from the specifics of an individual query/request, needed for GraphQL's execute to operate. The Mojolicious and Dancer2 plugins need only to be given which plugin to call, and any necessary arguments (e.g. a DBIx::Class::Schema object) and they can now create a GraphQL endpoint from that.

The newly-released v0.03 of GraphQL::Plugin::Convert::DBIC is the first functioning plugin. It implements generic CRUD for the given DBIC schema: it creates two types of Read (primary key, and "search" on fields), and Create, Update and Delete mutations.

You can try this out yourself using my modified, re-purposed version of tempire's Mojolicious example repo. Clone it, start it up, follow the "GraphiQL" link at the top, and try this query:

{ blog(id: [1, 2]) { id title tags { name } } }

Next on the agenda: to make a "convert plugin" for OpenAPI to hook up an existing OpenAPI / Mojolicious controller to GraphQL, and also making GraphQL work with Promises. This will benefit from the recent addition of full Promises/A+ promises in Mojolicious.