haxe-graphql icon indicating copy to clipboard operation
haxe-graphql copied to clipboard

Let's talk about expanding beyond schema / Other Uses Cases

Open jcward opened this issue 6 years ago • 3 comments

Right now these tools focus on using graphql merely as a schema / type description tool.

For me, this is my primary use case -- generating Haxe type definitions from a graphql schema. As such, my next step is to generate type definitions for queries, and think about how arguments affect the schema.

I know this is only a small subset of the GraphQL ecosystem. Tell me about how you'd like to use Haxe+GraphQL.

jcward avatar Jun 01 '18 18:06 jcward

I'd like to implement something like graphql-tag in haxe and integrate it with Apollo.

Randonee avatar Jun 05 '18 21:06 Randonee

@Randonee So, if I understand the graphql-tag description, it looks like it takes a graphql string and generates GraphQL AST? This is exactly what Parser.hx does, in pure Haxe. I've just added query support today. You can play with it in the web demo - enter some queries on the left:

image

It's missing the "kind":"Document" tag at the top level, but that is fixed in an unpushed commit. After parsing, you should be able to take the parser.document (that's the top level of the AST) and pass it to apollo. Here's a simple query parsing example.

It's not a complete implementation (e.g. directives are tbd, fragments will come shortly, loc.start is generally accurate, but loc.end may not be, and loc.token is always null.) But it's a start, and we can add more tests!

The thing I'm working on beyond AST is generating a Haxe typedef to strongly-type the expected result from the server, e.g. for the above:

typedef QueryResult = {
  data:{
    ?hero:{
      ?id:IDString,
      ?name:String
    }
  },
  ?errors:Dynamic
}

Ha, just noticed a bug... :)

jcward avatar Jun 06 '18 02:06 jcward

wow that was fast, thanks for adding operations!
Yes, graphql-tag outputs GraphQL AST and this looks perfect. I'll see if I can get something running with Apollo over the next couple days.

Randonee avatar Jun 06 '18 04:06 Randonee