Skip to content

Commit

Permalink
feat: adds GrapQL codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshnirmalya committed Jan 14, 2021
1 parent f330e8b commit f323425
Show file tree
Hide file tree
Showing 14 changed files with 17,375 additions and 125 deletions.
31 changes: 31 additions & 0 deletions frontend/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
schema:
- "http://localhost:8080/v1/graphql":
headers:
x-hasura-admin-secret: secret
documents:
- "./**/*.graphql"
watch: true
config:
scalars:
DateTime: Date
JSON: "{ [key: string]: any }"
timestamptz: string
numeric: number
overwrite: true
generates:
./generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
config:
maybeValue: T | undefined
withHooks: true
withComponent: true
withHOC: true
hooks:
afterOneFileWrite:
- prettier --write
./graphql.schema.json:
plugins:
- "introspection"
12 changes: 2 additions & 10 deletions frontend/components/pages/feeds/add-new-feed-form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { gql, useMutation } from "@apollo/client";
import {
Alert,
AlertIcon,
Expand All @@ -12,24 +11,17 @@ import {
Textarea,
} from "@chakra-ui/react";
import AccessDeniedIndicator from "components/access-denied-indicator";
import { useInsertFeedMutation } from "generated-graphql";
import { useSession } from "next-auth/client";
import React, { ChangeEvent, useState } from "react";

const insertFeedMutation = gql`
mutation insertFeed($author_id: uuid!, $body: String) {
insert_feeds_one(object: { author_id: $author_id, body: $body }) {
id
}
}
`;

const AddNewFeedForm = () => {
const [body, setBody] = useState("");
const [session] = useSession();
const [
insertFeed,
{ loading: insertFeedFetching, error: insertFeedError },
] = useMutation(insertFeedMutation);
] = useInsertFeedMutation();

if (!session) {
return (
Expand Down
19 changes: 2 additions & 17 deletions frontend/components/pages/feeds/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import { useSubscription, gql } from "@apollo/client";
import { Box, Stack } from "@chakra-ui/react";
import Loader from "components/loader";
import AddNewFeedForm from "components/pages/feeds/add-new-feed-form";
import Feed from "components/pages/feeds/feed";
import { useFetchFeedsSubscription } from "generated-graphql";
import React from "react";
import IFeed from "types/feed";

const feedsSubscription = gql`
subscription fetchFeeds {
feeds(order_by: { created_at: desc }) {
id
created_at
body
author {
id
name
image
}
}
}
`;

const FeedsPageComponent = () => {
const { data, loading } = useSubscription(feedsSubscription, {});
const { data, loading } = useFetchFeedsSubscription();

if (loading) {
return <Loader />;
Expand Down
15 changes: 2 additions & 13 deletions frontend/components/pages/my-account/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { gql, useMutation } from "@apollo/client";
import {
Alert,
AlertIcon,
Expand All @@ -12,27 +11,17 @@ import {
Input,
Stack,
} from "@chakra-ui/react";
import { useUpdateUserMutation } from "generated-graphql";
import { useSession } from "next-auth/client";
import React, { FormEvent, useState } from "react";

const updateUserMutation = gql`
mutation updateUser($userId: uuid!, $name: String) {
update_users(where: { id: { _eq: $userId } }, _set: { name: $name }) {
returning {
id
name
}
}
}
`;

const MyAccountPageComponent = ({ user }) => {
const [name, setName] = useState(user.name);
const [session] = useSession();
const [
updateUser,
{ loading: updateUserFetching, error: updateUserError },
] = useMutation(updateUserMutation);
] = useUpdateUserMutation();

const handleSubmit = () => {
updateUser({
Expand Down
Loading

0 comments on commit f323425

Please sign in to comment.