-
Notifications
You must be signed in to change notification settings - Fork 14
How to test Yoga2 (with an entity layer?) #110
Comments
But all of that will be generated right? Any edits will still generate new stuff. Is there any chance that people will need to write that themselves. |
All derived fields such as |
Personally, I do not see too much overhead as long as the structure is stable and properly documented. Once that is done actual structure may become part of the user API - it is being given to the user and they need to accept this format to be compatible with future generated stuff. Proposed layout is clear and must say I really like it as it will separate responsibilities and make things much cleaner with the way that applications are written. While the initial proposal is done to enable testing there are many other benefits from doing things this way. |
I, personally, have already created a similar structure to the Nexus example (multiple "data-sources" in Context that abstract away business logic and Prisma usage from resolvers). Having said that, I think something like this makes sense. Would the " It appears, to me, that I can simply create myself a Either way, Yoga2 is opinionated and I think your proposal has traction. No need to bike shed over it when an average user will simply copy and paste from the example tests in the boilerplates. |
@Weakky How do I test my resolvers for example take the How do I write a unit-test for it? |
@Weakky Preconfigure |
Hey everyone 👋, The main reason why we haven't been active during the past weeks on Yoga2 is because we've been working on the entity topic. It's now living in its own repository at https://github.com/prisma/ent. I just wrote a quick README for you to read and maybe provide feedback. The write part wasn't yet thought at all, only the read part. Feel free to chime-in and help us design it 🙏 If it turns out to be powerful/useful enough, that entity layer will probably become the default way to build graphql apis with Yoga2, by providing great integration/code-generation/tests for everything Thanks 🙌 |
Motivation
I see 4 ways to test a GraphQL API with Yoga:
Using graphql-tools (not possible without ejecting atm because we do not expose the
GraphQLSchema
object)On each test, spawn a new custom-seeded db + spawn a graphql server + run queries against it (mostly for integration test)
Mock the
prisma-client
or any other data-access layerWith an entity layer?
Description
When raising the question of tests with Yoga2, the question mostly refers to:
When looking at the nexus documentation for testing, here's what we can read:
You can find some examples with nexus here.
Separating the domain logic from the actual resolvers is not something new. Facebook is using the same concept as part of their "Ent layer", which enables quite a lot of advantages:
type-graphql is another great example that takes advantage of that pattern by actually generating a
GraphQLSchema
from these classes.What could it look like with Yoga + Prisma (and an entity layer)
Given the following datamodel:
The scaffold command could generate the following:
BaseEntity
. That part should never be edited manually.Overall, the tree structure could look like this:
Scaffolding a type would result in generating:
/entites
/graphql
/tests
(addressing [Suggestion] Add unit tests for commands #38)Biggest concerns
By abstracting away most of the resolvers logic, we introduce another layer that might cause boilerplate overhead
That additional layer now needs to be synced with the GraphQL schema. Meaning that everytime we add a derived field, we also need to update the schema.
One way to solve that problem would be to derive the schema from the classes themselves, but then we solve the very same problem
type-graphql
is trying to solve, and we'd rather just provide an integration for itOpen questions
We're very curious to hear your thoughts on that perspective 🙌
The text was updated successfully, but these errors were encountered: