jcward / haxe-graphql

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

Query and resolvers #39

Closed francescoagati closed 5 years ago

francescoagati commented 5 years ago

Hi, There Is a example of query and resolvers?

jcward commented 5 years ago

Hi @francescoagati,

Just to be clear, this project is not a graphql client or server. It generates Haxe type definitions based on Graphql schema definitions. It does support queries -- if you see the live demo, you'll see a query called GetFilmsByDirector. The graphql looks like this:

query GetFilmsByDirector($director: String) {
  film(director: $director) {
    title
    director
    releaseDate
  }
}

And the resulting Haxe type defintions look like this:

typedef OP_GetFilmsByDirector_Vars = {
  ?director : String,
}

typedef OP_GetFilmsByDirector_Result = {
  ?film : Array<OP_GetFilmsByDirector_InnerResult>,
}

typedef OP_GetFilmsByDirector_InnerResult = {
  title : String,
  ?director : String,
  ?releaseDate : Date,
}

How you use those types is up to you, but in our project, we generate helper functions for each query, such as:

class GraphQL {
  public static function GetFilmsByDirector(vars:OP_GetFilmsByDirector_Vars):Promise<OP_GetFilmsByDirector_Result>
  {
    // e.g. call http graphql route
  }
}

The point is that the vars input object and the return object are strongly typed. (Interestingly, the result type is not Array<FilmData>, because each query can specify a specific set of fields to fetch.)

I may, at some point, also generate that helper class, so that this project can be used out-of-the-box as a graphql client.

Does that answer your question?

francescoagati commented 5 years ago

yes answered thanks :-)