Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/tax/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
schema:
- apps/tax/graphql/taxSchema.graphql
documents: apps/tax/screens/queries/*.{ts,tsx}
generates:
apps/tax/graphql/schema.ts:
plugins:
- typescript
- typescript-operations
config:
exportFragmentSpreadSubTypes: true
scalars:
DateTime: Date
JSON: '{ [key: string]: any }'
namingConvention:
typeNames: change-case#pascalCase
apps/tax/graphql/fragmentTypes.json:
plugins:
- fragment-matcher
config:
module: commonjs
apolloClientVersion: 3
hooks:
afterAllFileWrite:
- prettier --write
75 changes: 75 additions & 0 deletions apps/tax/components/Example/QueryExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
useMutation,
useLazyQuery,
} from "@apollo/client";

import {GetUserByPhoneQuery} from '../../graphql/schema'
import { withApollo } from "../../graphql/withApollo";
import {
GET_USER_BY_PHONE_QUERY,
CREATE_TAX_RETURN_MUTATION,
CREATE_ASSET_MUTATION,
CREATE_INCOME_MUTATION,
CREATE_LIABILITY_MUTATION,
} from "../../screens/queries";



const QueryExample = () => {
const [fetchUser, { data, loading, error, refetch }] = useLazyQuery<GetUserByPhoneQuery>(GET_USER_BY_PHONE_QUERY);

const [createTaxReturn] = useMutation(CREATE_TAX_RETURN_MUTATION);
const [createAsset] = useMutation(CREATE_ASSET_MUTATION);
const [createIncome] = useMutation(CREATE_INCOME_MUTATION);
const [createLiability] = useMutation(CREATE_LIABILITY_MUTATION);

console.log(data);

const onFetchUserByPhone = async () => {
await fetchUser({
variables: {
phone: "772-8391",
},
});
}

const onCreateTaxReturn = async () => {
if (data) {
await createTaxReturn({ variables: { taxReturn: {userId: Number(data.userByPhone.id), year: 2025, status: 'draft' }}});
refetch();
}
}

const onCreateAsset = async () => {
if (data) {
await createAsset({ variables: { asset: {taxReturnId: 3, value: 10000, type: 'vehicle', assetId: '123', address: 'street' }}});
refetch();
}
}

const onCreateIncome = async () => {
if (data) {
await createIncome({ variables: { income: {taxReturnId: 3, source: 'employment', amount: 2000, type: 'salary' }}});
refetch();
}
}

const onCreateLiability = async () => {
if (data) {
await createLiability({ variables: { liability: {taxReturnId: 3, type: 'mortgage', interestPaid: 400, remainingBalance: 300000 }}});
refetch();
}
}

return (
<div>
<button onClick={onFetchUserByPhone}>onFetchUserByPhone</button><br />
<button onClick={onCreateTaxReturn}>onCreateTaxReturn</button><br />
<button onClick={onCreateAsset}>onCreateAsset</button><br />
<button onClick={onCreateIncome}>onCreateIncome</button><br />
<button onClick={onCreateLiability}>onCreateLiability</button><br />
</div>
);
}

export default withApollo(QueryExample);
32 changes: 32 additions & 0 deletions apps/tax/graphql/apolloClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ApolloClient, ApolloLink,HttpLink, InMemoryCache, NormalizedCacheObject } from "@apollo/client";
import { onError } from "@apollo/client/link/error";

// TODO: Move this to env files
const NEXT_PUBLIC_GRAPHQL_ENDPOINT = "https://7d5113d3dba5034.qaack.1xinter.net/graphql";

const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
for (const err of graphQLErrors) {
console.error(`[GraphQL error]: Message: ${err.message}, Location: ${err.locations}, Path: ${err.path}`);
}
}
if (networkError) {
console.error(`[Network error]: ${networkError}`);
}
});

const httpLink = new HttpLink({
uri: NEXT_PUBLIC_GRAPHQL_ENDPOINT,
credentials: "omit",
});

const cache = new InMemoryCache({});

export const createApolloClient= (): ApolloClient<NormalizedCacheObject> => {
return new ApolloClient({
ssrMode: typeof window === 'undefined',
link: ApolloLink.from([errorLink, httpLink]),
cache,
connectToDevTools: process.env.NODE_ENV === "development",
});
}
77 changes: 0 additions & 77 deletions apps/tax/graphql/client.ts

This file was deleted.

4 changes: 3 additions & 1 deletion apps/tax/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default as client } from './client'
export * from './apolloClient';
export * from './withApollo';
export * from './schema';
Loading
Loading