tendant / graphql-clj

A Clojure library that provides GraphQL implementation.
Eclipse Public License 1.0
285 stars 22 forks source link

spec/format for "Transformed Map" #35

Closed tendant closed 7 years ago

tendant commented 7 years ago

Ideally, the flow for graphql engine could be:

Query/Schema String -- Parser --> Parsed AST -- Transformation --> Transformed Map -- Validator --> Validation Error or Validated Map -- Executor --> Executor Error or Result

"Transformed Map" will be used by Validator and Executor for further processing. And also it will make validation and execution pluggable.

xsc commented 7 years ago

So, I played around with some ideas regarding validation and execution and I came to the conclusion that the format being fed into the executor should be different from the one passed to the validator; for two reasons, that is:

Otherwise, the executor is surely pluggable but you still need to implement fragment and variable resolution in each variant. (Plus, stuff like line numbers may have fulfilled its duty already during validation and could be stripped.)

I thus propose a further step between validation and executor, converting the "Validated Map" to a format more suited for execution. Opinions?

tendant commented 7 years ago

You are right. The transformed map should have different format from validated map.

The differences come from a few places:

  1. Transformed map is direct result of parsing. Validated map is a result of validation and for the convenience of execution.
  2. Validation can provide additional information for execution.
  3. Some data in transformed map can be further simplified during validation.

There is a pending pull request (https://github.com/tendant/graphql-clj/pull/40) created by @aew, he introduced the validator using clojure.spec. We are on track to have this soon.