jcward / haxe-graphql

Utilities for working with Haxe and GraphQL.
MIT License
23 stars 6 forks source link

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

Open jcward opened 6 years ago

jcward commented 6 years ago

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.

Randonee commented 6 years ago

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

jcward commented 6 years ago

@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... :)

Randonee commented 6 years ago

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.