Defining graphql types with syntax from the spec

I’ve been thinking about writing yet another graphql library to better understand it, and wondered if there is any downside (or if it is even possible) to defining types in .graphql files (similar to gettext .po) like this

# a person
type Person {
  name: String
  age: Int
  picture: Url
  relationship: Person
}

instead of Absinthe’s macros

@desc "a person"
object :person do
  field :name, :string
  field :age, :int
  field :picture, :url
  field :relationship, :person
end

These .graphql files would then be parsed and compiled into functions at compile time.

I started thinking about this approach after working with apollo-ios where queries and mutations are defined in .graphql files. I think this is also the approach some js libraries took judging by this https://github.com/apollographql/starwars-server/blob/master/data/swapiSchema.js

Hey! We hope to have support for that style very soon, it’s just pending some internal changes to how schemas get built in Absinthe.

The main downside that there are fewer tools available to handle boilerplate. For example the Relay connection pattern requires several “auxiliary” object types which can be succinctly generated as connection field :users via Absinthe macros. However the explicitness may be a desired trade off for people, so as I said we hope to have this feature soon.

Other than schema building, is there some other set of features you’d like to see out of a GraphQL implementation that is at odds with Absinthe’s approach?

Building a GraphQL implementation is a relatively significant undertaking and, while of course I’m biased, I feel like the energies of someone who is interested in implementing GraphQL would be better aimed at improving existing solutions, at least until some intractable difference of opinion was reached.

4 Likes

It’s mostly an experiment for me. I can’t really understand anything until I try recreating it.

1 Like

Fair enough!

The Absinthe parser does support parsing these types, and we even have the “internal representation” structs for them, it’s just a matter at the moment of re-writing the schema macros to produce the same internal types, and then compiling them all into the schema itself.

1 Like

Does it have to be GraphQL? What about Falcor: One Model Everywhere

I know you want to do it as a learning exercise but since the already excellent Absinthe exists and there isn’t a Falcor equivalent, could doing that be equally valuable to you as a learning exercise? No problem if not :lol:

1 Like

Hi !

Could you point me to the docs for the type parser ? I would like to implement user-defined types for some app, and decided I would go with the graphql syntax (though I will not provide a graphql API yet, I will just use that as a well known standard).

I found some parse functions in the docs but it does not seem to be what I want, i.e. parse(binary) :: types_ast()

Thank you :slight_smile:

As @benwilson512 is back here I’ll allow myself a little bumpup!

Hi @benwilson512 , I’m still interested if you are around !