0

I'm playing around with GraphQL by following the tutorial here https://www.howtographql.com/graphql-js/0-introduction/

However, I cannot get the nested object working, it always has null value

Below are snapshot of the mutation and the schema

Link must be linked to a User through postedBy

The source code is in this public repo https://github.com/cuongchau93/hello-graphql-express

I have been stuck at this for 2 days, so I decided to ask here. Any help would be appreciated.

enter image description here enter image description here

Ryan_Chau
  • 233
  • 2
  • 19

1 Answers1

0

It is difficult to answer your specific question, although if it helps removing the postedBy part of the info object (what to return) will likely resolve the error message.

This may not solve your issue, but it may expose a deeper issue that you can then work your way through up to this one.

mutation {
  post(
    url: "www.graphqlconf.org"
    description: "An awesome GraphQL conference!"
  ) {
    id
  }
}

Not much help I know, although it may get you further down the path.

Generating the GraphQL Schema may also greatly assist, as it will allow you to walk through the inputs, connections and the like for each node.

Adding the following to your prisma.yml file will enable the schema to be generated by Prisma:

generate:
  - generator: graphql-schema
    output: ./generated/prisma.graphql

You have a fairly complicated relationship in my view (between users and links), this may be clarified when you generate the graphql schema.

Asciant
  • 2,130
  • 1
  • 15
  • 26
  • Thanks for your answer, actually i did notice that removing the postedBy will give successful response. However, the question is why no connection is made even when i have the user to be linked to the Link, (the user is linked through the Bearer token in header) but the newly created Link also have User as null ( which returns error when trying to get postedBy) – Ryan_Chau Dec 30 '19 at 07:16
  • Just so I understand, is the `userId` set by this line `const userId = getUserId(context)` null, or the response back from the prisma `createLink` function is null? – Asciant Dec 30 '19 at 19:46
  • Sorry for late response, getUserId does return expected value the problem is the postedBy does not get linked to that User object event though I follow the prisma syntax, which is let temp = context.prisma.createLink({ url: args.url, description: args.description, postedBy: { connect: { id: userId } }, }, info) as in this [file](https://github.com/cuongchau93/hello-graphql-express/blob/master/src/resolvers/Mutation.js) – Ryan_Chau Jan 07 '20 at 02:03