Giter VIP home page Giter VIP logo

adrianhajdin / project_graphql_blog Goto Github PK

View Code? Open in Web Editor NEW
1.5K 1.5K 347.0 3.39 MB

With featured and recent posts, categories. full markdown articles, author information, comments, and much more, this fully responsive CMS Blog App is the best Blog Application that you can currently find on YouTube. And what's best of all is that you and your clients can manage the blog from a dedicated Content Management System.

Home Page: https://jsmastery.pro

JavaScript 97.06% SCSS 2.94%
blog graphcms graphql headless

project_graphql_blog's Introduction

GraphCMS Headless Blog

GraphCMS Headless Blog

Stay up to date with new projects

New major projects coming soon, subscribe to the mailing list to stay up to date https://resource.jsmasterypro.com/newsletter

Introduction

This is a code repository for the corresponding video tutorial.

With featured and recent posts, categories. full markdown articles, author information, comments, and much more, this fully responsive CMS Blog App is the best Blog Application that you can currently find on YouTube. And what's best of all is that you and your clients can manage the blog from a dedicated Content Management System.

You'll also learn how to work with GraphCMS. GraphCMS is a headless content management system based on GraphQL technology enabling seamless integration with any application.

project_graphql_blog's People

Contributors

adrianhajdin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

project_graphql_blog's Issues

New posts show 404 on deployment

I set fallback to true and used a loader just like in the video, but on deployment new posts returns 404.

Captura1
Captura2

I test it on production locally using
npm run build npm run start
and it works, new posts shows successfully. So why on deployment it doesn't work? Could this be a vercel thing?

Easier way to display content from GraphCMS to your website

In /services/index.js file, let change the raw in content of getPostDetails function to html (line 76):

Detail:
from

export const getPostDetails = async (slug) => {
  const query = gql`
    query GetPostDetails($slug : String!) {
      post(where: {slug: $slug}) {
        title
        excerpt
        featuredImage {
          url
        }
        author{
          name
          bio
          photo {
            url
          }
        }
        createdAt
        slug
        content {
          raw                  //change this line
        }
        categories {
          name
          slug
        }
      }
    }
  `;

  const result = await request(graphqlAPI, query, { slug });

  return result.post;
};

to

export const getPostDetails = async (slug) => {
  const query = gql`
    query GetPostDetails($slug : String!) {
      post(where: {slug: $slug}) {
        title
        excerpt
        featuredImage {
          url
        }
        author{
          name
          bio
          photo {
            url
          }
        }
        createdAt
        slug
        content {
          html                             //to this
        }
        categories {
          name
          slug
        }
      }
    }
  `;

  const result = await request(graphqlAPI, query, { slug });

  return result.post;
};

Next, let's import this to the file /components/PostDetail:

import parse from "html-react-parser";

Next, let's remove getContentFragment function and replace this code from line 71:

{post.content.raw.children.map((typeObj, index) => {
  const children = typeObj.children.map((item, itemindex) => getContentFragment(itemindex, item.text, item));

  return getContentFragment(index, children, typeObj, typeObj.type);
})}

to this code:

{parse(post.content.html)}

And it's done! You don't need to hand code with those mess. Just one line, everything has been solved!
Detail:
In PostDetail:
from this code:

import React from 'react';

import moment from 'moment';

const PostDetail = ({ post }) => {
  const getContentFragment = (index, text, obj, type) => {       // remove this function
    let modifiedText = text;

    if (obj) {
      if (obj.bold) {
        modifiedText = (<b key={index}>{text}</b>);
      }

      if (obj.italic) {
        modifiedText = (<em key={index}>{text}</em>);
      }

      if (obj.underline) {
        modifiedText = (<u key={index}>{text}</u>);
      }
    }

    switch (type) {
      case 'heading-three':
        return <h3 key={index} className="text-xl font-semibold mb-4">{modifiedText.map((item, i) => <React.Fragment key={i}>{item}</React.Fragment>)}</h3>;
      case 'paragraph':
        return <p key={index} className="mb-8">{modifiedText.map((item, i) => <React.Fragment key={i}>{item}</React.Fragment>)}</p>;
      case 'heading-four':
        return <h4 key={index} className="text-md font-semibold mb-4">{modifiedText.map((item, i) => <React.Fragment key={i}>{item}</React.Fragment>)}</h4>;
      case 'image':
        return (
          <img
            key={index}
            alt={obj.title}
            height={obj.height}
            width={obj.width}
            src={obj.src}
          />
        );
      default:
        return modifiedText;
    }
  };

  return (
    <>
      <div className="bg-white shadow-lg rounded-lg lg:p-8 pb-12 mb-8">
        <div className="relative overflow-hidden shadow-md mb-6">
          <img src={post.featuredImage.url} alt="" className="object-top h-full w-full object-cover  shadow-lg rounded-t-lg lg:rounded-lg" />
        </div>
        <div className="px-4 lg:px-0">
          <div className="flex items-center mb-8 w-full">
            <div className="hidden md:flex items-center justify-center lg:mb-0 lg:w-auto mr-8 items-center">
              <img
                alt={post.author.name}
                height="30px"
                width="30px"
                className="align-middle rounded-full"
                src={post.author.photo.url}
              />
              <p className="inline align-middle text-gray-700 ml-2 font-medium text-lg">{post.author.name}</p>
            </div>
            <div className="font-medium text-gray-700">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 inline mr-2 text-pink-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
              </svg>
              <span className="align-middle">{moment(post.createdAt).format('MMM DD, YYYY')}</span>
            </div>
          </div>
          <h1 className="mb-8 text-3xl font-semibold">{post.title}</h1>
          {post.content.raw.children.map((typeObj, index) => { 
            const children = typeObj.children.map((item, itemindex) => getContentFragment(itemindex, item.text, item));

            return getContentFragment(index, children, typeObj, typeObj.type);
          })}                               // replace this code
        </div>
      </div>

    </>
  );
};

export default PostDetail;

into this code

import React from 'react';
import parse from 'html-react-parser';         // add this import
import moment from 'moment';

const PostDetail = ({ post }) => {
  return (
    <>
      <div className="bg-white shadow-lg rounded-lg lg:p-8 pb-12 mb-8">
        <div className="relative overflow-hidden shadow-md mb-6">
          <img src={post.featuredImage.url} alt="" className="object-top h-full w-full object-cover  shadow-lg rounded-t-lg lg:rounded-lg" />
        </div>
        <div className="px-4 lg:px-0">
          <div className="flex items-center mb-8 w-full">
            <div className="hidden md:flex items-center justify-center lg:mb-0 lg:w-auto mr-8 items-center">
              <img
                alt={post.author.name}
                height="30px"
                width="30px"
                className="align-middle rounded-full"
                src={post.author.photo.url}
              />
              <p className="inline align-middle text-gray-700 ml-2 font-medium text-lg">{post.author.name}</p>
            </div>
            <div className="font-medium text-gray-700">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 inline mr-2 text-pink-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
              </svg>
              <span className="align-middle">{moment(post.createdAt).format('MMM DD, YYYY')}</span>
            </div>
          </div>
          <h1 className="mb-8 text-3xl font-semibold">{post.title}</h1>
          {parse(post.content.html)}        //to this code
        </div>
      </div>

    </>
  );
};

export default PostDetail;

Hope you'll success!

Email Required Problem & Post Page Pagination & Author Image Can Not Center Issues

Hi everyone. I have 3 different problem in this project.

First of all, I would like to express my sincere thanks to @adrianhajdin for this beautiful project he has prepared. Thanks Adrian. <3

Now, if I come to my problems, first of all, when someone wants to send a comment, they can send me their post for approval by simply typing "blabla" without typing "blabla**@xyz.com**" in the email field in the message they send. How can I solve this?

Secondly, after there are 10 posts on the main page, I want the 11th post to be displayed on the second page. How do I provide this?

Third and finally, author image is not centered even though I write the following codes in Author section. What could be causing this and how can I fix it?

image

In addition, although the height values are entered as "100px" in the video, when I do the same, I get the following error. For this reason, I have to write without px in curly brackets. Is this due to version differences or is there a way I can do this? Frankly, Image component of Next JS is tiring me a lot, unfortunately.

Error: Image with src ["https://media.graphassets.com/myphotoaddress"](https://media.graphassets.com/myphotoaddress) has invalid "height" property. Expected a numeric value in pixels but received "100px".

Unhandled Runtime Error - please, help out

Error: [line: 8] field 'featureImage' is not defined in 'Post': {"response":{"errors":[{"message":"[line: 8] field 'featureImage' is not defined in 'Post'"}],"data":null,"extensions":{"requestId":"ckzmminzk338p0b31so1l8s7k"},"status":400,"headers":{"map":{"cache-control":"private, no-store","content-length":"149","content-type":"application/json"}}},"request":{"query":"\n query GetPostDetails() {\n posts(\n orderBy: createdAt_ASC\n last: 3\n ) {\n title\n featureImage {\n url\n }\n createAt\n slug\n }\n }\n "}}

I'm facing this error whenever i go to the website.. although it still working
and this is what it shows in the browser's inspect mode..

Uncaught (in promise) Error: [line: 8] field 'featureImage' is not defined in 'Post': {"response":{"errors":[{"message":"[line: 8] field 'featureImage' is not defined in 'Post'"}],"data":null,"extensions":{"requestId":"ckzmminzk338p0b31so1l8s7k"},"status":400,"headers":{"map":{"cache-control":"private, no-store","content-length":"149","content-type":"application/json"}}},"request":{"query":"\n query GetPostDetails() {\n posts(\n orderBy: createdAt_ASC\n last: 3\n ) {\n title\n featureImage {\n url\n }\n createAt\n slug\n }\n }\n "}} ClientError types.js:27 makeRequest index.js:352 step index.js:63 verb index.js:44 fulfilled index.js:35

Slug must be defined

'slug' must be defined, why is this still happening even though i have added is empty from lodash ?
Screenshot_4
Screenshot_5
Screenshot_6

How to implement pagination in this project?

Hi everyone,

I started learning Next JS and GraphQL with this project so I'm a beginner. I wanted to implement pagination a few days ago and still to this day, I'm lost.

Did someone manage to achieve that?

Blog posts aren't updating

I seem to have everything set up correctly, no error messages etc, and it really is a great Blog app.
One issue that I notice is that once I publish a post in GraphCMS, I don't seem to be able to update it - it just stays as it was on the first publish.

Say I want to go back to the post content and correct a spelling, add to it, or change it in any way, the latest changes never show up on the live site, despite Graph CMS saying that the updates have been saved and published.

The only way these changes show on the live site, is if I make a change to the files in VS Code, and then push the changes to github, and redeploy to Vercel

TypeError: Only absolute URLs are supported

During the tutorial on minute 54:52, I get this error when refreshing my localhost

I've looked into the code again many times yet I have found no errors or any difference between my code and the GitHub one.

Skärmbild 2022-01-01 181155

400 error on GQL request for getComments()

Unhandled Runtime Error

Error: input:1: Field "post" is not defined by type CommentWhereInput. Did you mean NOT?
: {"response":{"errors":[{"message":"input:1: Field \"post\" is not defined by type CommentWhereInput. Did you mean NOT?\n"}],"data":null,"extensions":{"requestId":"ckxi37prcpivc0b69etjss2ns"},"status":400,"headers":{"map":{"cache-control":"private, no-store","content-length":"179","content-type":"application/json"}}},"request":{"query":"\n    query GetComments($slug:String!) {\n      comments(where: {post: {slug:$slug}}){\n        name\n        createdAt\n        comment\n      }\n    }\n  ","variables":{"slug":"test-post-2"}}}

Appears to happen due to the post object as input to the gql query on the where clause.
Still debugging, seems to happen when i pull down the gql project from github and change the .env to my token and cms url.

Wondering if i am missing a part of the setup for comments?

Thanks in advance.

Unhandled Runtime Error when trying to pass PostWidget and Caregories component into index.js

I am running into an error on video timestamp 33:50 when adding the postwidget and categories into my index.js file. my code is as follows. I am not sure what the issue is because when i just implement PostCard component everything works fine.

import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
import {PostCard, PostWidget, Categories} from '../components'

const posts = [
  { title: 'React Testing', excerpt: 'learn react testing'},
  { title: 'React with tailwind', excerpt: 'learn react with tailwind'}
]
export default function Home() {
  return (
    <div className="container mx-auto px-10 mb-8">
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <div className="grid grid-cols-1 lg:grid-cols-12 gap-12">
        <div className="clg:col-span-8 col-span-1">
          {posts.map((post, index) =><PostCard post={post} key={post.title}/>)}
        </div>
        <div className="lg:col-span-4 col-span-1">
          <div className="lg:sticky relative top-8">
            <PostWidget/>
            <Categories/>
          </div>
        </div>
      </div>
    </div>
  )
}

The error I am running into is

Unhandled Runtime Error
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of Home.

Fetch Code snippets and Image in a Post

I'm trying to create a new post on my blog with code snippets and a couple of images to it. What configuration should I do on my graphQL queries to fetch those data? I'm thinking of adding queries to enable RichText, Markdown, or HTML to it. An answer would be so much appreciated.

Error token verification failed: token contains an invalid number of segments

ClientError: GraphQL Error (Code: 401): {"response":{"error":"{"errors":[{"message":"token verification failed: token contains an invalid number of segments"}],"data":null}","status":401,"headers":{}},"request":{"query":"\n mutation CreateComment($name: String!, $comment: String!, $slug: String!) {\n createComment(data: {name: $name, comment: $comment, post: {connect: {slug: $slug}}}) { id }\n }\n ","variables":{"name":"ksad","comment":"adasd","slug":"pemdas"}}}

how to fix - Error: error:0308010C:digital envelope routines::unsupported - command(npm run dev)

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Loaded env from D:\coding projects\project_graphql_blog.env
info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:133:10)
at BulkUpdateDecorator.hashFactory (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
at BulkUpdateDecorator.update (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
at OriginalSource.updateHash (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
at NormalModule._initBuildHash (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
at handleParseResult (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
at D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
at processResult (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
at D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:133:10)
at BulkUpdateDecorator.hashFactory (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
at BulkUpdateDecorator.update (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
at OriginalSource.updateHash (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
at NormalModule._initBuildHash (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
at handleParseResult (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
at D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
at processResult (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
at D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
node:internal/crypto/hash:71
this[kHandle] = new _Hash(algorithm, xofLen);
^

Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:133:10)
at BulkUpdateDecorator.hashFactory (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
at BulkUpdateDecorator.update (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
at OriginalSource.updateHash (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
at NormalModule._initBuildHash (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
at handleParseResult (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
at D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
at processResult (D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
at D:\coding projects\project_graphql_blog\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5 {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v18.13.0

ClientError: Mutation failed due to permission errors

'''error - ClientError: Mutation failed due to permission errors: {"response":{"errors":[{"message":"Mutation failed due to permission errors","extensions":{"code":"403","failedActions":[{"action":"create","model":"Comment","stage":"DRAFT"},{"action":"update","model":"Post","stage":"DRAFT"}]}}],"data":null,"extensions":{"requestId":"cl87cg1f45rwc0ezs00jhmkep"},"status":403,"headers":{}},"request":{"query":"\n mutation CreateComment($name: String!, $email: String!, $comment: String!, $slug: String!) {\n createComment(data: {name: $name, email: $email, comment: $comment, post: {connect: {slug: $slug}}}) { id }\n }\n ","variables":{"name":"Trần Khánh Thành","email":"[email protected]","comment":"test comment","slug":"twg-la-gi"}}}
at D:\test-blog\project_graphql_blog\node_modules\graphql-request\dist\index.js:254:31
at step (D:\test-blog\project_graphql_blog\node_modules\graphql-request\dist\index.js:63:23)
at Object.next (D:\test-blog\project_graphql_blog\node_modules\graphql-request\dist\index.js:44:53)
at fulfilled (D:\test-blog\project_graphql_blog\node_modules\graphql-request\dist\index.js:35:58)'''

I clone project and follow the video at 2:47:00 . How to fix this error. I'm trying to fix this bug

TypeError: Cannot read properties of undefined (reading 'map')

Unhandled Runtime Error
TypeError: Cannot read properties of undefined (reading 'map')

Source
sections\FeaturedPosts.jsx (57:37) @ FeaturedPosts

<div className="mb-8">
<Carousel infinite customLeftArrow={customLeftArrow} customRightArrow={customRightArrow} responsive={responsive} itemClass="px-4">
 {dataLoaded && featuredPosts.map((post, index) => (
                    ^
<FeaturedPostCard key={index} post={post} />
)}
 </Carousel>

Error: input:1: Field "post" is not defined by type CommentWhereInput. Did you mean NOT?

Unhandled Runtime Error
Error: input:1: Field "post" is not defined by type CommentWhereInput. Did you mean NOT?
: {"response":{"errors":[{"message":"input:1: Field "post" is not defined by type CommentWhereInput. Did you mean NOT?\n"}],"data":null,"extensions":{"requestId":"ckxry0cko0slc0b793i100kyf"},"status":400,"headers":{"map":{"cache-control":"private, no-store","content-length":"179","content-type":"application/json"}}},"request":{"query":"\n query GetComments($slug:String!) {\n comments(where: {post: {slug:$slug}}){\n name\n createdAt\n comment\n }\n }\n ","variables":{"slug":"goalofthisblogconstructionfoundations"}}}

Source
.next\static\chunks\pages_app.js (254:0) @

252 | else {
253 | errorResult = typeof result === 'string' ? { error: result } : result;

254 | throw new types_1.ClientError(__assign(__assign({}, errorResult), { status: response.status, headers: response.headers }), { query: query, variables: variables });
255 | }
256 | return [2 /return/];
257 | }

By clicking on a post this error pops up. It appears to be referring to the where clause in GetComments graphql query. Submiting comments also do not work.

[{message: "Mutation failed due to permission errors",…}]

{response: {errors: [{message: "Mutation failed due to permission errors",…}], data: null,…},…}
request
:
{,…}
response
:
{errors: [{message: "Mutation failed due to permission errors",…}], data: null,…}

someone help me out please. i have added all permissions but yet still getting this error

Not displaying Related posts

there are no errors, i do see the Recent post on the home page but while I click on any post the division of Related posts is shown but without any data in it(e.g. image and title of a post). please suggest something

Unhandled runtime error. Help!

Unhandled Runtime Error
Error: [line: 5] field 'name' is not defined in 'PostAuthor': {"response":{"errors":[{"message":"[line: 5] field 'name' is not defined in 'PostAuthor'"}],"data":null,"extensions":{"requestId":"cl6q906fv1ekg0b1ba0bv1437"},"status":400,"headers":{"map":{"cache-control":"private, no-store","content-length":"147","content-type":"application/json"}}},"request":{"query":"\n query GetCategoryPost() {\n posts(where: {featuredPost: true}) {\n author {\n name\n photo {\n url\n }\n }\n featuredImage {\n url\n }\n title\n slug\n createdAt\n }\n } \n "}}

Comment doesn't display with correct slug

In components/Comments.jsx line 14:
If we don't add slug to [], the comments won't display until we refresh the page.
Solution:
add slug to [] like this:
from

 useEffect(() => {
    getComments(slug).then((result) => {
      setComments(result);
    });
  }, []);

to

 useEffect(() => {
    getComments(slug).then((result) => {
      setComments(result);
    });
  }, [slug]);

Hope this will behelpful!

TypeError: urlOrOptions is undefined

TypeError: urlOrOptions is undefined
72 | } 73 | ;

74 | const result = await request(graphqlAPI, query);
| ^
75 |
76 | return result.posts;
77 | };`

TypeError: Cannot read properties of undefined (reading 'document')

TypeError: Cannot read properties of undefined (reading 'document')

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
services\index.js (144:9) @ getPosts

142 | const result = await request(graphqlAPI, query, { slug, createdAt });
143 |

144 | return { next: result.next[0], previous: result.previous[0] };
| ^
145 | };
146 |
147 | export const getCategoryPost = async (slug) => {
Call Stack
getStaticProps
pages\index.js (30:31)

Can't Post comments on a deployed live site

I can only submit comments in the comment section on localhost, but when I deployed my site on vercel and it's already live, I can't Post a Comment. Should I use webhooks? or is there any configuration I need to do?

how to build schema using TS?

I'm going through the tutorial but implementing using TypeScript and tsx instead of Javascript. I'm stuck at the services/index.ts

import { request, gql, GraphQLClient } from 'graphql-request';

const graphqlAPI = process.env.GRAPHCMS_SECRET;

export const getPosts = async () => {

    const query = gql `
        query MyQuery {
            postsConnection {
                edges {
                    node {
                        author {
                            bio
                            name
                            id
                            image {
                                url
                            }
                        }
                        createdAt
                        slug
                        title
                        excerpt
                        featuredImage {
                            url
                        }
                        categories {
                            name
                            slug
                        }
                    }
                }
            }
        }
    `
    const result = await request(graphqlAPI, query);
    return result.postConnection.edges;
}

All of the fields return this error:
Unknown field "postsConnection": The parent selection or operation does not resolve to a valid schema type

and the graphqlAPI param in the return throws this error:
S2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.   Type 'undefined' is not assignable to type 'string'.

I don't know where to assign the string datatype or how to make this schema valid, it's exactly like the one in the video but this one throws error for some reason

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.