Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Argument id for data.postedBy.connect.id must not be null. Please use undefined instead. #1217

Open
willwang888 opened this issue Dec 7, 2020 · 24 comments

Comments

@willwang888
Copy link

Hi!

I'm attempting to run the two GraphQL mutations specified at the end of the this article: https://www.howtographql.com/react-apollo/1-getting-started/, but after following every step in the above, I'm getting this error that Googling has turned up blank for.

Does anyone know what's going on here?

Screen Shot 2020-12-06 at 9 52 13 PM

@jorgeruvalcaba
Copy link
Contributor

I'm experiencing the same issue.

@nataliegirard
Copy link

I was able to get them to run by signing up and logging in.

To sign up (fill in your email, password, and name):

mutation SignUp {
    signup(
        email: ""
        password: ""
        name: ""
    ) {
        token
    }
}

Take that token and put it into the HTTP Headers section at the bottom like:

{
    "authorization": "Bearer <paste token here>"
}

@vzla0094
Copy link

I was having the same issue, @nataliegirard solution solved it, thanks!

@B4bharat
Copy link

Thanks @nataliegirard for the solution.

@andrewmelnyk
Copy link

@samuel-mota
Copy link

I did what @nataliegirard said but when I put the authorization on HTTP header I got server error 500, if I delete from the HTTP header the server come back instantly but with the very same first error.

image

any suggestions?

@samuel-mota
Copy link

I did what @nataliegirard said but when I put the authorization on HTTP header I got server error 500, if I delete from the HTTP header the server come back instantly but with the very same first error.

image

any suggestions?

I found the issue, I forget to delete the "<" and ">" from the token, now it works properly, thank you.

@afizsavage
Copy link

I solved this issue by directly changing the the 'null' option at the ternary operator in the index.js file of the server folder to 'Undefined'. However it throws another error when i did the post mutation for creating new links.

Screenshot from 2021-02-19 10-59-24

andrew-mak added a commit to andrew-mak/hackernews-react-apollo-gql that referenced this issue Feb 24, 2021
install prisma package instead @prisma/cli in devDependencies
manually create prisma back client
manually migrate db
avoid problems  in tutorial:
howtographql/howtographql#1217 (comment)
howtographql/react-apollo#110
@vovkvlad
Copy link

vovkvlad commented Apr 8, 2021

I'm having the same issue, and the answer of @nataliegirard worked for me.
But it would be nice to either include it into the docs themself or make the required changes so that it should not be done, as for now, it's kinda confusing.

Thanks in advance!

@Melford-D
Copy link

I was able to get them to run by signing up and logging in.

To sign up (fill in your email, password, and name):

mutation SignUp {
    signup(
        email: ""
        password: ""
        name: ""
    ) {
        token
    }
}

Take that token and put it into the HTTP Headers section at the bottom like:

{
    "authorization": "Bearer <paste token here>"
}

Thank you very much!!!! @nataliegirard

@Urigo
Copy link
Contributor

Urigo commented May 24, 2021

would anyone be willing to try out a draft PR to update the docs to make it clear for learners?

@Melford-D
Copy link

would anyone be willing to try out a draft PR to update the docs to make it clear for learners?

They really need to update the code because there are lots of issues with it.

@StevenDRiggs
Copy link

StevenDRiggs commented May 29, 2021

Unfortunately, this issue remains, and the fix from @nataliegirard does not have an effect

@kobeydon
Copy link

kobeydon commented Jun 4, 2021

I had the same issue when going through mutation chapter. I solved it by changing index.js like

// ...
const httpLink = createHttpLink({
  uri: 'http://localhost:4000'
});

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      authorization: '<your token>',
    }
  }
});

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
});
//...

reference

@RaimondsKazuss
Copy link

I had the same issue when going through mutation chapter. I solved it by changing index.js like

// ...
const httpLink = createHttpLink({
  uri: 'http://localhost:4000'
});

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      authorization: '<your token>',
    }
  }
});

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
});
//...

reference

Perfect. Fixed the issue when going trough https://www.howtographql.com/react-apollo/3-mutations-creating-links/. Thank you!

@bigkrp
Copy link

bigkrp commented Jul 14, 2021

I had the same issue when going through mutation chapter. I solved it by changing index.js like

// ...
const httpLink = createHttpLink({
  uri: 'http://localhost:4000'
});

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      authorization: '<your token>',
    }
  }
});

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
});
//...

reference

helps me

@surya687
Copy link

I had the same issue when going through mutation chapter. I solved it by changing index.js like

// ...
const httpLink = createHttpLink({
  uri: 'http://localhost:4000'
});

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      authorization: '<your token>',
    }
  }
});

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
});
//...

reference

This solved my problem.Thank you

@whal-e3
Copy link

whal-e3 commented Jul 24, 2021

I got the same error while doing graphQL client-side tutorial.
The exact page link is graphQL creating Links.

And I think I found a problem and temporal solution from here which is experiencing server error while I'm currently writing this.

  • Problem (guessing)
    Since the server-side code is made by someone else, I think there was an update on server-side. Probably on src/resolvers/Mutation.js file.

  • Solution (Temporarily)
    Find this code snippet in the server/src/resolvers/Mutation.js file.

async function post(parent, args, context, info) {
  const { userId } = context;

  const newLink = await context.prisma.link.create({
    data: {
      url: args.url,
      description: args.description,
      postedBy: { connect: { id: userId } },
    },
  });
  context.pubsub.publish('NEW_LINK', newLink);

  return newLink;
}

And update like this.

async function post(parent, args, context, info) {
  let { userId } = context;
  if (!userId) {
    userId = 3;
  }

...

  return newLink;
}

As I said this is a temporal solution. I hope for an update asap!

@AshNaz87
Copy link

AshNaz87 commented Jul 25, 2021

When using the answer provided by @kobeydon, remember to import the setContext function at the top of your file :)

import { setContext } from '@apollo/client/link/context'

@gavindang2911
Copy link

gavindang2911 commented Oct 14, 2021

I had the same issue when going through mutation chapter. I solved it by changing index.js like

// ...
const httpLink = createHttpLink({
  uri: 'http://localhost:4000'
});

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      authorization: '<your token>',
    }
  }
});

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
});
//...

reference

How to get your token?

  1. If you already sign up, on the playground, type
    mutation { login(email:"alice@prisma.com", password: "graphql") { token } }
  2. Or if you haven't signed up yet, type
    mutation { signup(name: "Alice", email:"alice@prisma.com", password: "graphql") { token } }
  3. Copy and paste token to @kobeydon code :)

@gachuigachui
Copy link

When using the answer provided by @kobeydon, remember to import the setContext function at the top of your file :)

import { setContext } from '@apollo/client/link/context'

This is what I was missing! I had imported the function from 'react' but that didn't work.
Thanks!

@giovannipds
Copy link
Contributor

Is there any PR to fix that in the tutorials already?

Thanks everyone, specially @kobeydon.

giovannipds added a commit to giovannipds/howtographql that referenced this issue Nov 16, 2021
People doing that tutorial section can't go forward due an error, see howtographql#1217. This adds information to continue.
TasinIshmam pushed a commit that referenced this issue Nov 17, 2021
People doing that tutorial section can't go forward due an error, see #1217. This adds information to continue.
@giovannipds
Copy link
Contributor

@eric8979 could you please explain me why are you setting a static user id value? userId = 3; - this doesn't seem like an interesting temporarily solution...

@whal-e3
Copy link

whal-e3 commented Nov 19, 2021

@giovannipds I have missed that information(“why 3?”) and the answer is “no particular reason, just setting arbitrary number”. Sorry about that. But I don't quite agree with

"this doesn't seem like an interesting temporarily solution".

First of all, I don’t remember clearly but I think my post was for people(mostly for beginners) who just wanted their code to run first to check other things are functioning correctly. That's why I called it "temporal" solution.
Also, I think there can’t be an interesting temporal solution because the code is meant to be(and have to be) erased at some point(with real solution).
Comment like yours (no suggestions or technical reasons to criticize/upgrade my suggestion) seems unhealthy for me or anybody to learn communication and learn an open source.
If you had any suggestions or healthy reason that you didn't mention, please leave a comment again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests