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

TypeDef to Schema?

Open hoseyjoe opened this issue 6 years ago • 1 comments

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

hoseyjoe avatar Dec 07 '18 18:12 hoseyjoe

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.

jcward avatar May 07 '19 15:05 jcward