Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full graph generators not working on nested objects: Assert failed: Second arg to fmap must be a generator (generator? gen) #10

Open
priyatam opened this issue Feb 1, 2019 · 7 comments

Comments

@priyatam
Copy link

priyatam commented Feb 1, 2019

I have a working schema that compiles successfully with lacinia. However lacinia-gen throws multiple errors for both full graph and query result apis, for simple objects and objects with nested and input objects. It's not apparent from the test-check errors what's missing.

(:require [lacinia-gen.core :as lg]
              [lacinia-gen.query :as lg-query]
              [clojure.test.check.generators :as g])

 (def schema (-> "schema.edn" io/resource slurp edn/read-string))

  (let [gen (lg/generator schema)]
    (g/sample (gen :LenderReferral) 1))

Assert failed: Second arg to fmap must be a generator (generator? gen)

         generators.cljc:  100  clojure.test.check.generators$fmap/invokeStatic
         generators.cljc:   91  clojure.test.check.generators$fmap/invoke
                core.clj:   42  lacinia-gen.core/object/fn/fn
                core.clj: 7341  clojure.core/keep/fn

For most objects, I get a NullpointerException.

 java.lang.NullPointerException
 core.clj:   95  lacinia-gen.core/generator/fn
 

It is also not clear whether the 'schema' passed to lacinia-gen is a raw edn schema, or a compiled schema from lacinia (see load-schema)

(defn load-schema
  [component]
  (-> (io/resource "schema.edn"
      slurp
      edn/read-string
      (util/attach-scalar-transformers
        {:parse-datetime parse-datetime
         :serialize-datetime serialize-datetime})
      (util/attach-resolvers (resolve-schema component))
      schema/compile))

I've used both variations and get NPEs with a compiled schema.

With queries, I always get the same error:

{
:objects {

  :Countries
    {:description "List of countries"
     :fields {:countries {:type (list String)}}}
  }

:queries
 {:get_countries {:type :Countries
                  :description "List of countries"
                  :args {:query_str {:type (non-null String)}}
                  :resolve :query/get-countries}}
}
 (let [f (lg-query/generate-fn schema {})]
    (f "query { get_countries { countries } }" {:query_str "IN"}))

Cannot query field get_countries on type QueryRoot ... :extensions {:field get_countries, :type :QueryRoot}

The above query works fine on graphiql.

Any suggestions debugging these errors is much appreciated. I'm also using your re-graph library.

@priyatam priyatam changed the title Full graph generators not working on working schema: Assert failed: Second arg to fmap must be a generator (generator? gen) Full graph generators not working on compiled schema: Assert failed: Second arg to fmap must be a generator (generator? gen) Feb 1, 2019
@priyatam priyatam changed the title Full graph generators not working on compiled schema: Assert failed: Second arg to fmap must be a generator (generator? gen) Full graph generators not working on nested objects: Assert failed: Second arg to fmap must be a generator (generator? gen) Feb 4, 2019
@oliyh
Copy link
Owner

oliyh commented Feb 8, 2019

Hi,

The schema should be the uncompiled schema. It looks like your schema has custom scalars, so are you supplying generators for those custom scalars to lacinia-gen?

The example on the readme shows how to use it if you have custom generators: https://github.com/oliyh/lacinia-gen#custom-scalars

Hope this helps.

@oliyh
Copy link
Owner

oliyh commented Feb 8, 2019

Additionally is your query here correct? Your schema declares that get_countries has a query_str parameter that you are providing as arguments but not supplying in the query, I would expect it to look like this (in it's simplest form):

 (let [f (lg-query/generate-fn schema {})]
    (f "query { get_countries(query_str: \"IN\") { countries } }"))

@priyatam
Copy link
Author

priyatam commented Feb 8, 2019

Yes, I'm passing scalars, like so, and still get an error:


(let [gen (gen/generator schema {:scalars {:Datetime (local-date-time)}})]
    (g/sample (gen :LenderReferral) 1))

> Resolver specified in schema not provided.
   {:reference :mutation/save-application-data,
    :callbacks (:query/get-lender-options
                :query/get-validation-edits
                :query/get-countries
                :query/get-application-details
                :query/get-profile-lists
                :query/get-drop-downs
                :query/get-member-by-id
                :query/get-profile-options)}

@oliyh
Copy link
Owner

oliyh commented Feb 8, 2019

Hmm, that last error comes from Lacinia, not lacinia-gen. I guess you have :mutations in your schema? I think the issue might be that lacinia-gen is not mocking mutation resolvers and Lacinia is throwing the error. (This is only with lacinia-gen.query, lacinia-gen.core should be ok).

@priyatam
Copy link
Author

priyatam commented Feb 8, 2019

I removed :mutations :input-objects :enums from the raw schema, and yet get this error:

 Assert failed: Second arg to fmap must be a generator (generator? gen)

           generators.cljc:  100  clojure.test.check.generators$fmap/invokeStatic
           generators.cljc:   91  clojure.test.check.generators$fmap/invoke

To take a step back, I'd be happy just relying on generating object graphs, instead of query api. What do you think is required to provide this support with a working schema.edn? I'd be happy to contribute if you can point to the code.

@oliyh
Copy link
Owner

oliyh commented Feb 9, 2019

Hi,

Can you share a minimum failing schema and I can have a look? Is it your get_countries one in your first post?

Thanks

@priyatam
Copy link
Author

Sure, I'll provide this soon ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants