Skip to content

Subscription issue #229

@revskill10

Description

@revskill10

I'm following tutorial at howtographql.com, here's my subscription for newLink:

function newLinkSubscribe (parent, args, context, info) {
  return context.db.subscription.link(
    { where: { mutation_in: ['CREATED'] } },
    info,
  )
}

const newLink = {
  subscribe: newLinkSubscribe
}

module.exports = {
  newLink,
}

My subscription query is:

subscription RealTimeFeed {
    newLink {
      mutation
      node{
        url
      }
    }
  }

But when i post a mutation to create new link

mutation {
  post(
    url: "fdsfdsdsdf.graphqlweesfsdfkly.com"
    description: "Curated GraphQL content coming to your email inbox every Friday"
  ) {
    id
  }
}

, i got error :

{
  "error": {
    "name": "TypeError",
    "message": "Cannot read property 'link' of undefined"
  }
}

But if i go to database, schema, i got correct subscription:

{
  "data": {
    "link": {
      "mutation": "CREATED",
      "node": {
        "url": "fdsfdsdsdf.graphqlweesfsdfkly.com"
      }
    }
  }
}

This is killing me hardly. Any magic for subscription only work for database, but not on app ?.

My schema.graphql is:

# import Link, LinkSubscriptionPayload  from "./src/generated/prisma.graphql"

type Query {
  info: String!
  feed: [Link!]!

  # Fetch a single link by its `id`
  link(id: ID!): Link
  user: User
}

type Mutation {
  post(url: String!, description: String!): Link!
  signup(email: String!, password: String!, name: String!): AuthPayload
  signinUser(email: String!, password: String!): AuthPayload
}

type AuthPayload {
  token: String
  user: User
}

type User {
  id: ID!
  name: String!
  email: String!
  links: [Link!]!
}

type Subscription {
  newLink: LinkSubscriptionPayload
}

My package.json:

{
  "name": "hackernews-node",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "graphql-yoga": "^1.16.0",
    "jsonwebtoken": "^8.3.0",
    "prisma-binding": "^2.1.4"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions