Welcome! We're excited that you're interested in working with us, we hope you enjoy this challenge :)
- create a cloned version of this repo (don't fork it publicly)
- keep the original git history and only add new commits to your clone
- make sure to include all of the deliverables mentioned in challenge
yarn install
yarn test:watch
look inside of __tests__/pure.test.ts to see how to make ASTs with babel.
edit ./scripts/fixture.ts, and then run
yarn test:ast
then, look at the ./scripts/test-output.json for the result
Take the input and output below, and make a function that can generate this code using babel ASTs:
{
"Pools": {
"requestType": "QueryPoolsRequest",
"responseType": "QueryPoolsResponse"
}
}export interface UsePoolsQuery<TData> extends ReactQueryParams<QueryPoolsResponse, TData> {
request?: QueryPoolsRequest;
}
const usePools = <TData = QueryPoolsResponse,>({
request,
options
}: UsePoolsQuery<TData>) => {
return useQuery<QueryPoolsResponse, Error, TData>(["poolsQuery", request], () => {
if (!queryService) throw new Error("Query Service not initialized");
return queryService.pools(request);
}, options);
};You'll be writing a function to generate code, and we'll be writing a test as well as the code:
- create a new test, call it
ast-challenge.test.tsinside of__tests__folder - write code for the creation of the AST inside of
src/index.ts - write code for the converting AST into Typesript code inside of
__tests__/ast-challenge.test.ts - use
expect(resultingCode).toMatchSnapshot()to store output of code generation
After completing the function, parameterize (meaning make function arguments to make dynamic) the following properties, so that a developer can use this method to generate many of these hooks. Be sure to include parameterization of these fields:
- Query interface (
UsePoolsQuery) - hook name (
usePools) - request type (
QueryPoolsRequest) - response type (
QueryPoolsResponse) - queryService method name (
queryService.pools()) - key name (
poolsQuery)
- add a test case in a new test that uses all methods from
./example-methods.json - in the test case, use
expect(resultingCode).toMatchSnapshot()and save the snapshot for all the code