COMMUNITY

Tools for using Haxe + GraphQL


(Jeff Ward) #1

Hi Haxe friends,

Here’s a new screenshot of my Haxe + GraphQL project that my company, wootmath.com, plans to open source soon:

If you widen the window, you can see the parser step, too. It’s built on top of @back2dos tink_parse lib.

Overall, it’s very alpha. Lots to work out still. Here’re are the bits I’m planning / building - above is the webdemo powered by parser+hxgen.

image

No progress on the macro workflow yet.

I’m going to offer an option to generate either typedefs or interfaces + classes. I believe they both technically work, it just depends on how you want to work with (and instantiate) your data (as class instances, or typed structs.)

This only deals with mapping simple schema / type definitions at the moment. Not yet any GraphQL queries, arguments, fragments, servers, etc. But it’s a nice, tidy interface description language, so we’re minimally looking into it for cross-stack data type definitions.

Cheers,
-Jeff


#2

wow graphql with haxe , really hope this progress , so i can combine it with gatsbyjs


(Philippe) #3

I guess it’s using the JS client (Relay?) to query the data right?


(Jeff Ward) #4

So far, I’m just working on basic schema / type mapping. Later I’ll look into typing queries. Once Haxe has all the correct types from a .graphql schema, I assume that you’d typically compile to JS and use the JS servers / etc.

That is, I don’t plan on building a server / query implementation in Haxe. Just the type definitions, so Haxe can be easily integrated with graphql-specified systems.


(Philippe) #5

Not suggesting the server, but the client side requires quite a heavy logic.


(Jeff Ward) #6

Well, that’s got me thinking “server / queries”. As I mentioned up top, all I’m focused on so far is graphql schema / type definitions. :slight_smile:

But… what is shown above is 100% in Haxe, no JS dependencies.


(Philippe) #7

Without a client at least it’s a bit senseless, no?


(Jeff Ward) #8

I don’t think so. That’d be like saying externs are useless because they don’t do anything.

Schema / type definitions are a small piece of the graphql ecosystem, but it is the foundation. You have to start somewhere! Or, looking at the graphql homepage… this project is currently in this realm:

Even besides the type definition generation, this repo has nice, small, digestible examples of:

  • a repo that delivers an npm module and a haxelib, from Haxe source
  • a small web editor demo that uses highlight.js
  • a parser built on tink_parse (I had a hard time finding simple examples)
  • a place to work together on Haxe + graphql tools & ideas

(Aaron) #9

Very cool!
Any idea when the source will be public?


(Jeff Ward) #10

Probably this or next week.


(Jeff Ward) #11

Ok, I’ve gone ahead and published the bare bones project to: https://github.com/jcward/haxe-graphql

NPM package: https://www.npmjs.com/package/gql2hx

No haxelib yet (see issue describing planned macro workflow)…

Also, I’ve created an issue to discuss expanding beyond schema / other use cases - feel free to add to that thread.


(Jeff Ward) #12

FYI, I got tired of implementing a fragile parser clone, so I ported the official v0.13.2 graphql-js parser (parser.js, lexer.js, and ast.js). For the curious, I devised a few dozen regex’s in Ruby scripts, and it took about a day.

Naturally, this closes a bunch of issues and makes this library a ton more stable.

image

Also, expected query result types are now being generated – have a play with the updated web demo example:

image


(Aaron) #13

I’ve been working on a way to simplify working with aws AppSync and haxe (one click to full project up and running goal). This graphql parser was the missing link between haxe and Apollo. Thanks!

A working demo is here: https://randonee.github.io/amazonian/

The graphql parts of the code are here: https://github.com/Randonee/amazonian/blob/master/example/todo/web/src/todo/view/TodoView.hx

It’s basically doing what graphql-tag does, creates graphql AST and passes it to an Apollo function.

Code for the whole thing is here: