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

Cannot generate values for interface types #13

Open
colinphill-mdsol opened this issue Sep 13, 2024 · 2 comments
Open

Cannot generate values for interface types #13

colinphill-mdsol opened this issue Sep 13, 2024 · 2 comments

Comments

@colinphill-mdsol
Copy link

I think this might explain some of the other reported issues. The library appears to simply not support the concept of an interface. In this schema, you can generate values of Person, but not of NameHolder, because the latter has a field whose type is an interface.

Schema:

type NameHolder {
    named: Named
}

interface Named {
    name: String
}

type Person implements Named {
    name: String,
    age: Int
}

type Query {
    nameHolder: NameHolder
}

schema {
    query: Query
}

Code:

(ns repro
  (:require [clojure.java.io :as io]
            [clojure.test.check.generators :as gen]
            [com.walmartlabs.lacinia.parser.schema :as parser]
            [lacinia-gen.core :as lgen]))

(def ^:private schema
  (-> (io/resource "repro.graphql")
      slurp
      parser/parse-schema))

(gen/sample ((lgen/generator schema) :NameHolder))

Result:

Execution error (AssertionError) at clojure.test.check.generators/fmap (generators.cljc:103).
Assert failed: Second arg to fmap must be a generator
(generator? gen)
Evaluation of file repro.clj failed: class clojure.lang.Compiler$CompilerException
@colinphill-mdsol
Copy link
Author

colinphill-mdsol commented Sep 13, 2024

Ah, appears the same issue happens with unions.

type StrBox {
    value: String
}
type IntBox {
    value: Integer
}
union StrIntBox = StrBox | IntBox
type StrIntBoxBox {
    value: StrIntBox
}
(gen/sample ((lgen/generator schema) :StrIntBoxBox))
Execution error (AssertionError) at clojure.test.check.generators/fmap (generators.cljc:103).
Assert failed: Second arg to fmap must be a generator
(generator? gen)

@oliyh
Copy link
Owner

oliyh commented Sep 15, 2024

Hi,

Thanks for reporting this, and the reproduction. I'm not sure when I'll be able to get around to looking at this but in the meantime PRs are welcome.

Cheers

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