Fork me on GitHub
#graphql
<
2018-12-26
>
Joe R. Smith00:12:06

Lacinia usage question: I've been writing specs for input objects in order to: 1. specify more precise constaints than expressible w/ GraphQL's types and 2. to generate input data for tests. This is suboptimal though b/c I end up validating input twice and, since I'm using the specs as input generators I end up duplicating the graphql schema in the spec definitions completely. Due to the inevitable cyclic dependency, I cannot reference the compiled lacinia schema from the spec namespace that is need in the resolvers (for conforming/validating input). How do others generate input and add additional input constraints?

gklijs11:12:20

@solussd I used Kafka with avro schema's for the input, using specific generated Java classes. So I didn't need additional constraints on the input.

domkm15:12:34

@solussd Serene (https://github.com/paren-com/serene) will generate specs for your schema (including input types) and allows extension. I think it will solve the issues you're facing.

Joe R. Smith15:12:16

Thanks Dom, I’ll check it out.

👍 4
pre17:12:07

how do you debug this error from a lacinia spec ?

Introspection must provide output type for fields.
    at invariant ()
    at getOutputType ()
    at 
    at 
    at Array.reduce (<anonymous>)
    at keyValMap ()
    at buildFieldDefMap ()
    at fields ()
    at resolveThunk ()
    at defineFieldMap ()
Given (partial spec):
....

{:objects
  :ApplicationDataOutput
  {:description ""
   :fields {:application_id {:type ID}
            :app_transaction_id {:type ID}
            :borrower_loan_person_id {:type ID}
            :cosigner_loan_person_id {:type ID}
            :student_loan_person_id {:type ID}
            :fulfillment_application_id {:type ID}
            :data_save_completed {:type Boolean}
            :borrower_is_age_of_majority {:type Boolean}
            :cosigner_is_age_of_majority {:type Boolean}
            :is_no_ssn {:type Boolean}
            :is_assigned_admin_id {:type Boolean}}}
 
:input-objects
 {:ApplicationDataInput
  {:description ""
   :fields {:application_started_user_type {:type String}
            :request_user_type {:type String}
            :validation_group_list {:type (list String)}}}

 :mutations
 {:save_application_data {:type :ApplicationDataOutput
                          :description "Save application data"
                          :args {:data {:type :ApplicationDataInput}}
                          :resolve :mutation/save-application-data}}
}
Rootcause seems to be save_application_data mutation

pre20:12:05

I was able to resolve this: part of the schema included an object with a field of input type; turns out you can’t reuse input types in objects (output type).

hlship18:12:31

This is something we should probably have Lacinia validate during schema compilation.

pre19:12:23

That would be great, yes.