Open jBernavaPrah opened 1 year ago
+1
For now we use https://the-guild.dev/graphql/codegen/plugins/typescript/typed-document-node and created a helper function like:
export function getLaikaMatcher<D, V>(query: ComponentDocument<D, V>): Matcher {
return {operationName: (query.definitions[0] as OperationDefinitionNode).name.value};
}
and then use the generated typed document (GetAllAccountsDocument in this case):
laika.intercept(getLaikaMatcher(GetAllAccountsDocument)).mockResult(() => {
const result: Data<typeof GetAllAccountsDocument> = {allAccounts: accounts};
return {
result: {data: result},
};
});
This provides at least type safety when our API changes etc.
It would be nice when Laika could add the generics to the API so we can use typed-document-node without custom helper functions etc.
Good suggestion! PRs welcome.
Adding one more suggestion: it would be nice if we could provide the operation document itself as the argument, i.e.:
laika.intercept({operation: QueryDocument})
Hi! Thanks for sharing this package!
It's possible to use Types during mocking?
I'm using
graphql-codegen
to generate all the Types for my graphQL endpoint.So this will be more easy create the mocked response, knowing what is required and what is not.
Thank!