Giter VIP home page Giter VIP logo

classsed-graphql-mern-apollo's People

Contributors

hidjou 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

classsed-graphql-mern-apollo's Issues

userData?

I can't seem to find out where to define this or pass into my login file and it keeps returning undefined

Unhandled Rejection (Error): Cannot read property 'req' of undefined

When deleting a comment in singlePost view i ll get this error my code looks like this :

`

const [deletePostOrMutation] = useMutation(mutation, {
     update(proxy, result) {
          setModalShow(false);
           if (!commentId) {
                const data = proxy.readQuery({
                    query: FETCH_POSTS_QUERY
               });

            let newData = [...data.getPosts];
            newData = data.getPosts.filter((p) => p.id !== postId);

            proxy.writeQuery({ 
                query: FETCH_POSTS_QUERY, 
                data: {
                    ...data.getPosts,
                    getPosts: {
                        newData
                    }
                }
            });
        }   
        if (callback) callback();
    },
    variables: {
        postId,
        commentId
    }
})`

What am i missing here ? Thanks

2 Issues

I'm getting a couple errors. 1. Is when you click post with an empty body I get Unhandled Rejection (Error): GraphQL error: Post body must not be empty. The 2. is when I add more than 1 like I get Unhandled Rejection (Error): GraphQL error: user is not defined.

Getting error on register form "Cannot read property 'username' of undefined.

45 | name="username"
46 | type="text"
47 | value={values.username}

48 | error={errors.username ? true : false}
49 | onChange={onChange}
50 | />
51 | <Form.Input

so I know 'errors' is undefined.

const [addUser, {loading}] = useMutation(REGISTER_USER, { update(_, result){ console.log(result) props.history.push('/') }, onError(err){ console.log(err.graphQLErrors[0].extensions.exception.errors) setErrors(err.graphQLErrors[0].extensions.exception.errors) }, variables: values })
this is where we set the error property, right? Is it not setting it correctly? is there an updated way for graphql to set errors?

Server deployment error

I'm getting 404 error in the deploy server. Heroku log:

2021-02-20T03:40:07.767548+00:00 heroku[router]: at=info method=GET path="/" host=salty-bastion-35598.herokuapp.com request_id=62288037-601a-40da-b052-edd7c54235d3 fwd="201.237.16.163" dyno=web.1 connect=1ms service=51ms status=404 bytes=984 protocol=https

'data' is not defined

- Issue located in: /client/src/pages/Home

const {
    loading,
    data: { getPosts: posts }
  } = useQuery(FETCH_POSTS_QUERY);

-Issue description: 'data' is not defined (twice) 😢

-Context: I think the problem is due to the migration to @apollo/client 3.0 (they've discussed something about some changes regarding loading / data)

-How I solved it: :

const{
    loading,
    data={}
  } = useQuery(FETCH_POSTS_QUERY);

const posts = data.getPosts;

useMutation response changes after reloading

I have successfully added another key named 'isAdmin: Boolean' to typeDefs's user and I return it, and to mongoose User Model as well.
When I query user using useMutation like so:

    const [loginUser, { loading }] = useMutation(LOGIN_USER, {
        update(_, { data: { login: userData }}) {
            context.login(userData)
        },
        variables: values,
    });

userData becomes:

{
    "__typename": "User",
    "id": "6295c18152e384a8ee61ee0f",
    "username": "admin",
    "email": "[email protected]",
    "createdAt": "2022-05-31T07:19:29.647Z",
    "isAdmin": true,
    "token": "token-xxx"
}

i pass it to context and I see it in AuthContext.Provider component as long as I don't reload the page
but when I refresh the page it becomes:

{
    "id": "6295c18152e384a8ee61ee0f",
    "email": "[email protected]",
    "username": "admin",
    "iat": 1654054329,
    "exp": 1654057929
}

is there anyway to keep isAdmin:value in context after reloading?

Single Post Type Error

Hey @hidjou, for some reason the code in the singlePost.js is not working properly. I think the data shouldn't be restructured as the code is synchronous and the values are undefined unless you refresh the page.

deleteComment Mutation Bug

I found a bug in the deleteComment Mutation.

When I tried to detete a non existing comment, an exception error was not caught. That is because the findIndex function returns -1 if the entry is not found. When you try to access the index in the if condition statement, the exception is thrown.

To catch this error, I introduced a new if block to check if commentIndex is >= 0 before executing the delete command and throw a new UserInputError if not. That fixed the issue.

Thanks a lot for your tutorial, it's doing wonders for me.

Single Post Error

×
TypeError: Cannot read property 'getPost' of undefined

const {
data: { getPost }
} = useQuery(FETCH_POST_QUERY, {
variables: {
postId

Delete button issue

image
the delete button does not automatically update the render, I have to reload, and in the single post page i doesn't redirec me to home either.
Any Idea?

cache update

In PostForm the code is written so when you make a new post it shold update the apollo cache and render the new post live,
The cache is updated but I still have to reload the page in order to view the post
image
I added some console.logs in order tocheck if the data is correct and everithing is ok

TypeError: Cannot read property 'getPosts' of undefined

Home
C:/Users/Agon Misini/Desktop/merng/client/src/pages/Home.js:14
11 | const { user } = useContext(AuthContext);
12 | const {
13 | loading,

14 | data: { getPosts: posts }
| ^ 15 | } = useQuery(FETCH_POSTS_QUERY);
16 |
17 | return (

Check authentication middleware change on firebase authorization have error: UnhandledPromiseRejectionWarning

Please help, any idea how to solve? thx

// @Dependencies
const { AuthenticationError } = require('apollo-server-express')
const admin = require("../Server/client")

module.exports = async (context) => {
// @Header
const header = context.req.headers.authorization

// @validate
if(!header)
    throw new Error('Musí sa uviesť hlavička overenia')

// @token
const token = header.split('Bearer ')[1]

// @validate
if(!token)
    throw new Error('Musí sa uviesť hlavička overenia')


try {
    // @auth
    const auth = await admin.auth().verifyIdToken(token)

    // @user
    const user = await admin.firestore()
        .collection('users')
        .where('id', '==', auth.uid)
        .limit(1)
        .get()

    return user.docs[0].data()
}
catch(error)
{
    throw new AuthenticationError(error)
}

}

"Cannot read property 'unshift' of undefined"

GRAPHQL > RESOLVERS > COMMENTS.JS

        if (post) {
        ** post.comments.unshift({ **
            body,
            username,
            createdAt: new Date().toISOString()
          });
          await post.save();
          return post;
        } else throw new UserInputError('Post not found');

Args not defined

When creating a new post i am getting an error "args not defined"
issue is with this line
if (args.body.trim() === "") {
throw new Error("Post body must not be empty");
}

But after removing args from that line , it is working fine.

Tab highlight issue

When we log out we should be redirected to the home page, where the tab highlight should also be changed to home. Currently, it stays in the login tab and shows home page posts.

Capture

TypeError: Object(...)(...) is undefined in AuthRoute

AuthRoute.js
`
import React, { useContext } from "react";
import { Route, Redirect } from "react-router-dom";

import { AuthContext } from "../context/auth";

function AuthRoute({ component: Component, ...rest }) {
const { user } = useContext({ AuthContext });

return (
<Route
{...rest}
render={(props) =>
user ? : <Component {...props} />
}
/>
);
}
export default AuthRoute;
`

Gets the following Error:

TypeError: Object(...)(...) is undefined

TypeError: Cannot convert undefined or null to object

this error of login and register page of errors.username errors.password are undefined
<Form.Input
label="Username"
placeholder="Username.."
name="username"
type="text"
value={values.username}
error={errors.username ? true : false}
onChange={onChange}
/>

Unable to get Single Post in graphql server

My typeDefs for getting single post

  1. getPost(postId: ID!): Post

Code for getPost

async getPost(_, { postId }) {
try {
const post = await Post.findById(postId);
if (post) {
return post;
} else {
throw new Error("Post not found");
}
} catch (err) {
throw new Error(err);
}
}

GraphQL Query in playground

query {
getPost(postId: "6128c4afc3f58e75065d3a2e"){
id
body
createdAt
username
}
}

it is returning null.

TypeError: (destructured parameter).post is undefined ?

This tutorial was put up on https://www.youtube.com/watch?v=n1mdAPFq2Os only 3 weeks ago but a lot of the code is broken.

I'm getting the following error

TypeError: (destructured parameter).post is undefined

2020-11-06_20-58

import React from "react";
import { Button, Form } from "semantic-ui-react";
import gql from "graphql-tag";
import { useForm } from "../util/hooks";
import { useMutation } from "@apollo/react-hooks";

function PostForm() {
const { values, onChange, onSubmit } = useForm(createPostCallback, {
body: "",
});

const [createPost, { error }] = useMutation(CREATE_POST_MUTATION, {
variables: values,
update(_, result) {
console.log(result);
values.body = "";
},
});
function createPostCallback() {
createPost();
}
return (


Create a post


<Form.Field>
<Form.Input
placeholder="Hello World"
name="body"
onChange={onChange}
value={values.body}
/>

Submit

</Form.Field>

);
}

const CREATE_POST_MUTATION = gqlmutation createPost($body: String!) { createPost(body: $body) { id body createdAt username likes { id username createdAt } likeCount comments { id body username createdAt } commentCount } };
export default PostForm;

args not defined for react class 6 adding posts

Hi! I am having an error with regards to the adding of posts on react class 6 with Unhandled Rejection (Error): GraphQL error: args is not defined.

Unhandled Rejection (Error): GraphQL error: args is not defined

This happens even after removing the args

Solving: Cast to ObjectId failed for value "" at path "_id" Error

Few months ago when I was following the tutorial, I was stuck at 1:18:00 because of this problem, after I found a fix, I don't remember where, I have created a gist with a solution and I have commented on the video telling people what causes the issue and a link to gist I've created. but I totaly forgot to put it here. so, here we go: Solving: Cast to ObjectId failed for value "" at path "_id" Error
in this Gist I am explaining the error and how to fix it

I am also working on another gist fixing another error that is happening because of the difference between the old apollo-client 2.6 and the new version 3.6 which I am using.

Invalid/Expired token

I was typing the mutation of createPost. I first registered a new user and then logged it in. I copypasted the token on the Authorization headers however it is giving me the error Invalid/Expired Token

This is the register mutation-
mutation($registerInput: RegisterInput!) { register(registerInput: $registerInput) { username token } }

This is the login mutation-
mutation($username: String!, $password: String!){ login(username: $username, password: $password) { username token } }

and this is the createPost mutation-
mutation($body: String!){ createPost(body: $body) { body username } }
The photo of the error is below-
Explorer _ Sandbox _ Studio - Google Chrome 27-01-2023 21_03_32

The github code is also below
https://github.com/Feanor96/social-media-website

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.