jcward / haxe-graphql

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

TypeDef to Schema? #36

Open hoseyjoe opened 5 years ago

hoseyjoe commented 5 years ago

Using a lot of typedefs in code already. Would it be easy to convert typedef to a schema?

jcward commented 5 years ago

Hey, sorry I missed this note. Yeah, the Haxe typedef representation is really similar to the GQL type definition -- well, at least for simple-ish types. For example, if you enter this schema into the online demo:

type Rating {
  author:String!
  srats:Int!
}

type FilmData {
  id:ID!
  title:String!
  director:String
  ratings:[Rating]
}

You'll get this Haxe output:

/* - - - - Haxe / GraphQL compatibility types - - - - */
abstract ID(String) to String from String { }

typedef Rating = {
  author : String,
  srats : Int,
}

typedef FilmData = {
  id : ID,
  title : String,
  ?director : String,
  ?ratings : Array<Rating>,
}

It might not be difficult to convert by hand, or with a simple script.

Now, representing Haxe types in GQL introduces build complexity and more limited capabilities (in GQL than Haxe), so you need to have a reason to do it. e.g. some other part of your application wants those GQL definitions.