Skip to content

Commit

Permalink
Drop @apollo/client
Browse files Browse the repository at this point in the history
  • Loading branch information
elmeister committed Aug 22, 2023
1 parent 6089580 commit a3478a2
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 192 deletions.
4 changes: 4 additions & 0 deletions app/chapter/[chapterNumber]/verse/[verseNumber]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ const Verse = async ({ params: { chapterNumber, verseNumber } }: Props) => {
languageSettings.translationAuthor.name
);

if (!verseData) {
return <h1>Not found</h1>;
}

return (
<article>
<script
Expand Down
13 changes: 11 additions & 2 deletions app/verse-of-the-day/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { getDailyVerse } from "../../lib/getDailyVerse";
import { getVerseId } from "../../lib/getVerseData";
import { VerseOfTheDay } from "./verse-of-the-day";
import { Metadata } from "next";

export async function generateMetadata(): Promise<Metadata> {
const { chapter_number, verse_number } = await getDailyVerse();
const gitaVerse = await getDailyVerse();

if (!gitaVerse) {
return {};
}

const { chapter_number, verse_number } = gitaVerse;

return {
title: `Bhagavad Gita Chapter ${chapter_number} Verse ${verse_number} - BhagavadGita.io`,
Expand Down Expand Up @@ -48,6 +53,10 @@ export async function generateMetadata(): Promise<Metadata> {
const Page = async () => {
const dailyVerse = await getDailyVerse();

if (!dailyVerse) {
return <h1>Not found</h1>;
}

return <VerseOfTheDay dailyVerse={dailyVerse} />;
};

Expand Down
26 changes: 0 additions & 26 deletions lib/apolloClient.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lib/getDailyVerse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getDailyVerse = () =>
})?.[0];

if (!gitaVerse) {
throw new Error("Gita verse of the day not found");
return null;
}

return {
Expand Down
99 changes: 55 additions & 44 deletions lib/getVerseData.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,66 @@
import { ApolloQueryResult, gql } from "@apollo/client";
import apolloClient from "./apolloClient";
import { query, resolved } from "src/gqty-client";

interface GitaVerseIds {
gita_verses: { chapter_number: number; verse_number: number }[];
}

export async function getVerseId(): Promise<GitaVerseIds> {
const { data }: ApolloQueryResult<GitaVerseIds> = await apolloClient.query({
query: gql`
query MyQuery {
gita_verses {
chapter_number
verse_number
}
}
`,
});

return data;
}
export const getVerseId = () =>
resolved(() =>
query.gita_verses().map((gitaVerse) => ({
chapter_number: gitaVerse.chapter_number!,
verse_number: gitaVerse.verse_number!,
}))
);

export async function getVerseData(
export const getVerseData = (
chapterNumber,
verseNumber,
commentariesAuthor = "Swami Sivananda",
translationsAuthor = "Swami Sivananda"
): Promise<GitaVerse> {
// todo: add translation to the query and pass transation data to Translation and Commentary component
const { data }: ApolloQueryResult<Verse> = await apolloClient.query({
query: gql`
query MyQuery {
gita_verses(where: {chapter_number: {_eq: ${chapterNumber}}, verse_number: {_eq: ${verseNumber}}}) {
chapter_number
id
text
transliteration
verse_number
word_meanings
gita_chapter {
verses_count
}
gita_commentaries(where: {author_name: {_eq: "${commentariesAuthor}"}}) {
description
}
gita_translations(where: {author_name: {_eq: "${translationsAuthor}"}}) {
description
}
}
}
`,
});
) =>
resolved(() => {
const [gitaVerse] = query.gita_verses({
where: {
chapter_number: {
_eq: chapterNumber,
},
verse_number: {
_eq: verseNumber,
},
},
});

return data.gita_verses[0];
}
if (!gitaVerse) {
return null;
}

return {
chapter_number: gitaVerse.chapter_number!,
id: gitaVerse.id!,
text: gitaVerse.text!,
transliteration: gitaVerse.transliteration!,
verse_number: gitaVerse.verse_number!,
word_meanings: gitaVerse.word_meanings!,
gita_chapter: {
verses_count: gitaVerse.gita_chapter?.verses_count || 0,
},
gita_commentaries: gitaVerse
.gita_commentaries({
where: {
author_name: {
_eq: commentariesAuthor,
},
},
})
.map(({ description }) => ({ description: description! })),
gita_translations: gitaVerse
.gita_translations({
where: {
author_name: {
_eq: translationsAuthor,
},
},
})
.map(({ description }) => ({ description: description! })),
};
});
31 changes: 10 additions & 21 deletions lib/subscribeUser.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { gql } from "@apollo/client";
import apolloClient from "./apolloClient";
import { mutation, resolved } from "src/gqty-client";

export const subscribeUser = async (
name: string,
email: string
): Promise<void> => {
await apolloClient.mutate({
mutation: gql`
mutation MyMutation {
insert_newsletter_subscriptions_one(
object: {
user_name: "${name}"
user_email: "${email}"
}
) {
user_name
user_email
}
}
`,
});
export const subscribeUser = async (name: string, email: string) => {
return resolved(() =>
mutation.insert_newsletter_subscriptions_one({
object: {
user_name: name,
user_email: email,
},
})
);
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"prettier"
],
"dependencies": {
"@apollo/client": "^3.5.5",
"@headlessui/react": "^1.4.1",
"@heroicons/react": "v1",
"@popperjs/core": "2.9.1",
Expand Down
98 changes: 1 addition & 97 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@
"@jridgewell/gen-mapping" "^0.3.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@apollo/client@^3.5.5":
version "3.7.17"
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.7.17.tgz#1d2538729fd8ef138aa301a7cf62704474e57b72"
integrity sha512-0EErSHEtKPNl5wgWikHJbKFAzJ/k11O0WO2QyqZSHpdxdAnw7UWHY4YiLbHCFG7lhrD+NTQ3Z/H9Jn4rcikoJA==
dependencies:
"@graphql-typed-document-node/core" "^3.1.1"
"@wry/context" "^0.7.0"
"@wry/equality" "^0.5.0"
"@wry/trie" "^0.4.0"
graphql-tag "^2.12.6"
hoist-non-react-statics "^3.3.2"
optimism "^0.16.2"
prop-types "^15.7.2"
response-iterator "^0.2.6"
symbol-observable "^4.0.0"
ts-invariant "^0.10.3"
tslib "^2.3.0"
zen-observable-ts "^1.2.5"

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.22.5":
version "7.22.5"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.22.5.tgz#234d98e1551960604f1246e6475891a570ad5658"
Expand Down Expand Up @@ -272,11 +253,6 @@
resolved "https://registry.yarnpkg.com/@gqty/utils/-/utils-1.0.0.tgz#5f954c95721244aa1e59534695a1c1e8d3877225"
integrity sha512-QJMlzts//d0H5mlekOZgx1a4KsTYXfxmRhhx8g/8mvzdaNVPxhFzCsv3+ljTOzbW3A08qy4jXQPWAMoTefSJDQ==

"@graphql-typed-document-node/core@^3.1.1":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.2.0.tgz#5f3d96ec6b2354ad6d8a28bf216a1d97b5426861"
integrity sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==

"@headlessui/react@^1.4.1":
version "1.7.15"
resolved "https://registry.yarnpkg.com/@headlessui/react/-/react-1.7.15.tgz#53ef6ae132af81b8f188414767b6e79ebf8dc73f"
Expand Down Expand Up @@ -947,34 +923,6 @@
resolved "https://registry.yarnpkg.com/@vercel/node-bridge/-/node-bridge-2.2.2.tgz#f63466ab6a2588afdc6262c2d060289bfe8baa6b"
integrity sha512-haGBC8noyA5BfjCRXRH+VIkHCDVW5iD5UX24P2nOdilwUxI4qWsattS/co8QBGq64XsNLRAMdM5pQUE3zxkF9Q==

"@wry/context@^0.7.0":
version "0.7.3"
resolved "https://registry.yarnpkg.com/@wry/context/-/context-0.7.3.tgz#240f6dfd4db5ef54f81f6597f6714e58d4f476a1"
integrity sha512-Nl8WTesHp89RF803Se9X3IiHjdmLBrIvPMaJkl+rKVJAYyPsz1TEUbu89943HpvujtSJgDUx9W4vZw3K1Mr3sA==
dependencies:
tslib "^2.3.0"

"@wry/equality@^0.5.0":
version "0.5.6"
resolved "https://registry.yarnpkg.com/@wry/equality/-/equality-0.5.6.tgz#cd4a533c72c3752993ab8cbf682d3d20e3cb601e"
integrity sha512-D46sfMTngaYlrH+OspKf8mIJETntFnf6Hsjb0V41jAXJ7Bx2kB8Rv8RCUujuVWYttFtHkUNp7g+FwxNQAr6mXA==
dependencies:
tslib "^2.3.0"

"@wry/trie@^0.3.0":
version "0.3.2"
resolved "https://registry.yarnpkg.com/@wry/trie/-/trie-0.3.2.tgz#a06f235dc184bd26396ba456711f69f8c35097e6"
integrity sha512-yRTyhWSls2OY/pYLfwff867r8ekooZ4UI+/gxot5Wj8EFwSf2rG+n+Mo/6LoLQm1TKA4GRj2+LCpbfS937dClQ==
dependencies:
tslib "^2.3.0"

"@wry/trie@^0.4.0":
version "0.4.3"
resolved "https://registry.yarnpkg.com/@wry/trie/-/trie-0.4.3.tgz#077d52c22365871bf3ffcbab8e95cb8bc5689af4"
integrity sha512-I6bHwH0fSf6RqQcnnXLJKhkSXG45MFral3GxPaY4uAl0LYDZM+YDVDAiU9bYwjTuysy1S0IeecWtmq1SZA3M1w==
dependencies:
tslib "^2.3.0"

acorn-jsx@^5.3.2:
version "5.3.2"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"
Expand Down Expand Up @@ -2496,13 +2444,6 @@ graphemer@^1.4.0:
resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6"
integrity sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==

graphql-tag@^2.12.6:
version "2.12.6"
resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.12.6.tgz#d441a569c1d2537ef10ca3d1633b48725329b5f1"
integrity sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==
dependencies:
tslib "^2.1.0"

graphql@^16.0.1:
version "16.7.1"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.7.1.tgz#11475b74a7bff2aefd4691df52a0eca0abd9b642"
Expand Down Expand Up @@ -3465,14 +3406,6 @@ open@^9.1.0:
is-inside-container "^1.0.0"
is-wsl "^2.2.0"

optimism@^0.16.2:
version "0.16.2"
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.16.2.tgz#519b0c78b3b30954baed0defe5143de7776bf081"
integrity sha512-zWNbgWj+3vLEjZNIh/okkY2EUfX+vB9TJopzIZwT1xxaMqC5hRLLraePod4c5n4He08xuXNH+zhKFFCu390wiQ==
dependencies:
"@wry/context" "^0.7.0"
"@wry/trie" "^0.3.0"

optionator@^0.9.3:
version "0.9.3"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.3.tgz#007397d44ed1872fdc6ed31360190f81814e2c64"
Expand Down Expand Up @@ -3957,11 +3890,6 @@ resolve@^2.0.0-next.4:
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

response-iterator@^0.2.6:
version "0.2.6"
resolved "https://registry.yarnpkg.com/response-iterator/-/response-iterator-0.2.6.tgz#249005fb14d2e4eeb478a3f735a28fd8b4c9f3da"
integrity sha512-pVzEEzrsg23Sh053rmDUvLSkGXluZio0qu8VT6ukrYuvtjVfCbDZH9d6PGXb8HZfzdNZt8feXv/jvUzlhRgLnw==

reusify@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
Expand Down Expand Up @@ -4306,11 +4234,6 @@ svgo@^2.8.0:
picocolors "^1.0.0"
stable "^0.1.8"

symbol-observable@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-4.0.0.tgz#5b425f192279e87f2f9b937ac8540d1984b39205"
integrity sha512-b19dMThMV4HVFynSAM1++gBHAbk2Tc/osgLIBZMKsyqh34jb2e8Os7T6ZW/Bt3pJFdBTd2JwAnAAEQV7rSNvcQ==

synckit@^0.8.5:
version "0.8.5"
resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.8.5.tgz#b7f4358f9bb559437f9f167eb6bc46b3c9818fa3"
Expand Down Expand Up @@ -4443,13 +4366,6 @@ tr46@~0.0.3:
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

ts-invariant@^0.10.3:
version "0.10.3"
resolved "https://registry.yarnpkg.com/ts-invariant/-/ts-invariant-0.10.3.tgz#3e048ff96e91459ffca01304dbc7f61c1f642f6c"
integrity sha512-uivwYcQaxAucv1CzRp2n/QdYPo4ILf9VXgH19zEIjFx2EJufV16P0JtJVpYHy89DItG6Kwj2oIUjrcK5au+4tQ==
dependencies:
tslib "^2.1.0"

tsconfig-paths@^3.14.1:
version "3.14.2"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz#6e32f1f79412decd261f92d633a9dc1cfa99f088"
Expand All @@ -4465,7 +4381,7 @@ tslib@^1.8.1:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.1.0, tslib@^2.3.0, tslib@^2.4.0, tslib@^2.5.0, tslib@^2.6.0:
tslib@^2.4.0, tslib@^2.5.0, tslib@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.0.tgz#b295854684dbda164e181d259a22cd779dcd7bc3"
integrity sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==
Expand Down Expand Up @@ -4751,18 +4667,6 @@ yocto-queue@^0.1.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

zen-observable-ts@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/zen-observable-ts/-/zen-observable-ts-1.2.5.tgz#6c6d9ea3d3a842812c6e9519209365a122ba8b58"
integrity sha512-QZWQekv6iB72Naeake9hS1KxHlotfRpe+WGNbNx5/ta+R3DNjVO2bswf63gXlWDcs+EMd7XY8HfVQyP1X6T4Zg==
dependencies:
zen-observable "0.8.15"

[email protected]:
version "0.8.15"
resolved "https://registry.yarnpkg.com/zen-observable/-/zen-observable-0.8.15.tgz#96415c512d8e3ffd920afd3889604e30b9eaac15"
integrity sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==

[email protected]:
version "3.21.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db"
Expand Down

0 comments on commit a3478a2

Please sign in to comment.