Skip to content

Commit a95f43e

Browse files
committed
Added code gen
1 parent aec01a2 commit a95f43e

File tree

8 files changed

+83
-7
lines changed

8 files changed

+83
-7
lines changed

dist/resolvers/user.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/resolvers/user.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/resolvers/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class UserResolver {
107107
return em.find(User,{})
108108
}
109109

110-
@Query(()=>User, {nullable:true})
110+
@Query(()=>User)
111111
async me(@Ctx(){req,em}:MyContex){
112112
if(!req.session.userId){
113113
return null;

with-chakra-ui-typescript-app/graphql.schema.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@
105105
"description": null,
106106
"args": [],
107107
"type": {
108-
"kind": "OBJECT",
109-
"name": "User",
110-
"ofType": null
108+
"kind": "NON_NULL",
109+
"name": null,
110+
"ofType": {
111+
"kind": "OBJECT",
112+
"name": "User",
113+
"ofType": null
114+
}
111115
},
112116
"isDeprecated": false,
113117
"deprecationReason": null
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Box, Button, Flex, Link } from '@chakra-ui/react'
2+
import React from 'react'
3+
import NextLink from 'next/link'
4+
import { useMeQuery } from '../generated/graphql'
5+
6+
interface NavbarProps {}
7+
export const Navbar:React.FC<NavbarProps> = ({}) =>{
8+
const [{data, fetching}] = useMeQuery()
9+
let body = null
10+
if(fetching){
11+
12+
}
13+
else if(data?.me){
14+
body =(
15+
<>
16+
<Box ml={4}>{data?.me.username}</Box>
17+
<Button colorScheme="teal"> LogOut</Button>
18+
</>
19+
)
20+
} else {
21+
body =(
22+
<>
23+
<NextLink href="/login">
24+
<Link> Login </Link>
25+
</NextLink>
26+
<NextLink href="/register">
27+
<Link> Register </Link>
28+
</NextLink>
29+
</>
30+
)
31+
}
32+
return (
33+
<Flex p={4}>
34+
<Box ml={"auto"}>
35+
{body}
36+
</Box>
37+
</Flex>
38+
)
39+
}

with-chakra-ui-typescript-app/src/generated/graphql.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type Query = {
2020
posts: Array<Post>;
2121
post?: Maybe<Post>;
2222
listUsers?: Maybe<Array<User>>;
23-
me?: Maybe<User>;
23+
me: User;
2424
};
2525

2626

@@ -117,6 +117,17 @@ export type LoginMutation = (
117117
) }
118118
);
119119

120+
export type MeQueryVariables = Exact<{ [key: string]: never; }>;
121+
122+
123+
export type MeQuery = (
124+
{ __typename?: 'Query' }
125+
& { me: (
126+
{ __typename?: 'User' }
127+
& Pick<User, 'id' | 'username' | 'createdAt'>
128+
) }
129+
);
130+
120131
export type RegisterMutationVariables = Exact<{
121132
username: Scalars['String'];
122133
password: Scalars['String'];
@@ -157,6 +168,19 @@ export const LoginDocument = gql`
157168
export function useLoginMutation() {
158169
return Urql.useMutation<LoginMutation, LoginMutationVariables>(LoginDocument);
159170
};
171+
export const MeDocument = gql`
172+
query Me {
173+
me {
174+
id
175+
username
176+
createdAt
177+
}
178+
}
179+
`;
180+
181+
export function useMeQuery(options: Omit<Urql.UseQueryArgs<MeQueryVariables>, 'query'> = {}) {
182+
return Urql.useQuery<MeQuery>({ query: MeDocument, ...options });
183+
};
160184
export const RegisterDocument = gql`
161185
mutation Register($username: String!, $password: String!) {
162186
register(options: {username: $username, password: $password}) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
query Me {
2+
me {
3+
id
4+
username
5+
createdAt
6+
}
7+
}

with-chakra-ui-typescript-app/src/pages/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { Container } from '../components/Container'
66
import { DarkModeSwitch } from '../components/DarkModeSwitch'
77
import { CTA } from '../components/CTA'
88
import { Footer } from '../components/Footer'
9+
import { Navbar } from '../components/Navbar'
910

1011
const Index = () => (
1112
<Container height="100vh">
13+
<Navbar />
1214
<DarkModeSwitch />
1315
<Footer>
1416
<Text>Built with ❤️ Ravilochan</Text>

0 commit comments

Comments
 (0)