We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
graphql-codegen
export type ReturnDataQuery = { __typename?: 'Query', something?: string | null }; const intercept = laika.intercept({operationName: 'getUsers'}); // something like this: intercept.mockResult<ReturnDataQuery>( { result: { data: { something: "ABC" // typescript checked } } );
So this will be more easy create the mocked response, knowing what is required and what is not.
Thank!
The text was updated successfully, but these errors were encountered:
+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.
Sorry, something went wrong.
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})
No branches or pull requests
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!
The text was updated successfully, but these errors were encountered: