Schema mocking #1368
aaronadamsCA
started this conversation in
Ideas
Schema mocking
#1368
Replies: 1 comment
-
|
Thanks for sharing @aaronadamsCA! feel free to make feature requests to help your work along here. Don't have much time to dig in right now, but I will keep reading whatever you share at a minimum. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
@jasonkuhrt, schema mocking is something I've mentioned before; now that I have a working solution in place, I wanted to share it in case it gives you any ideas.
GraphQLClient.tsThis is the interface shared by real and mock clients.
HttpGraphQLClient.tsThis just delegates requests to
graphql-request.MockGraphQLClient.tsThis just delegates requests to an executable GraphQL schema.
The schema creation itself is garbage code right now. Once it's cleaned up, I can share some examples of that too.
What I've learned from creating the mock executable schemas:
@graphql-tools/mockis a very interesting library, but with a very steep learning curve, very weak TypeScript types (Type-safe mocks, resolvers, and store ardatan/graphql-tools#7480), and some very weird overlap betweenmocksandresolversthat means it's never entirely clear where something should be mocked.graphql-codegen, both to generate anintrospection.jsonfile for creating the executable schema, and to generate the TypeScript types to make the mocks and resolvers (somewhat) type-safe.To migrate this to Graffle, I think all that's needed is to understand how we can define one shared interface for our real (HTTP transport) and mock (memory transport) clients. I'm not sure if the exported types are "friendly" enough to do this yet, though I haven't looked at it in several months.
In the long term, it feels like Graffle could offer a substantially better mocking solution. I could easily imagine a "mock builder" that looks a lot like the document builder. This would be the last piece of the puzzle to fully drop
graphql-codegen,graphql-eslint, andgraphql-tools, which are consistently the most temperamental dependencies in our codebase.Beta Was this translation helpful? Give feedback.
All reactions