Fork me on GitHub
#graphql
<
2020-06-02
>
shen15:06:50

is this a good place to ask lacinia questions?

gklijs15:06:58

Yes, it's a shame history only goes so far, otherwise you could see about 50% of this channel is exactly that.

shen16:06:16

I've implemented field preview in a resolver using executor/selects-field?. That seems to work well. My question is, how do I test that resolver by itself, outside of the context of a full query? I see that the lacinia unit tests use parse-query and parse-query->context here https://github.com/walmartlabs/lacinia/blob/b3c8d18e8c1dc30953fafa471927ee62238a3bba/test/com/walmartlabs/lacinia/selections_tests.clj#L28-L33 . Is there no simpler way to create a mock context?

chrisulloa18:06:31

> My question is, how do I test that resolver by itself, outside of the context of a full query? You can pass in a context map to your resolver with the fields listed in the context, right?

chrisulloa18:06:49

Like for example (defn resolver [context args parent] …)

hlship17:06:22

I don't encourage people to do this, as the internals and structure could change at any time. What I'd appreciate would be, if you go down this path, to report back so that we can address it properly in the framework somehow, perhaps functions to assemble a context reflecting the state you wish to test.

👍 4
hlship17:06:11

That being said, when we test our GraphQL we essentially pass full and correct queries in and assess the result map. We often mock out databases and external services in some way, but generally exercise the resolvers as-is.

hlship17:06:04

That leverages lacinia to, for example, validate that the raw value returned from the resolver is valid, and deals with cases of a resolver returning a wrapped result, or an asynchronous resolver result promise, etc.

hlship17:06:55

Effectively, we don't unit test resolvers per-se, we integration test queries into our schema.

hlship17:06:04

In fact, I prefer to override things and actually send the request in via HTTP to truly see if it is working end-to-end. This can still be amazingly fast within a test suite, especially if your component system can persist between test functions.

👍 4
chrisulloa18:06:23

This is what we usually do too.. we’ll stub out the selects-field? and then test conditional logic of the resolver (rather than building out the context with lacinia internals) and instead run a pedestal test servlet to test end-to-end thru HTTP calls. This is good information though to avoid doing this in the future.

chrisulloa18:06:53

You could build out a context with this in it to test out any conditional behavior around selects-field? if you needed to, not sure if there’s a better way

{:com.walmartlabs.lacinia.constants/parsed-query {:selections [{:field-definition {:qualified-name :Something/something}}]}}