graphql-rxjs icon indicating copy to clipboard operation
graphql-rxjs copied to clipboard

TypeError: Cannot read property 'next' of undefined

Open harrypunk opened this issue 8 years ago • 3 comments

I tried the example in document,
which failed with error:

Error: Cannot find module 'graphql/validation/rules/ArgumentsOfCorrectType'
    at Function.Module._resolveFilename (module.js:542:15)
    at Function.Module._load (module.js:472:25)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/node_modules/graphql-rxjs/dist/bundle.js:1:27561)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)

And it's plain javascript, no typescript or flow.
This is the code I wrote:

const { Observable } = require("rxjs");
const { makeExecutableSchema } = require("graphql-tools");
const { prepareSchema, graphqlRx } = require("graphql-rxjs");

const clockSource = Observable.interval(1000)
    .map(() => new Date())
    .publishReplay(1)
    .refCount();

const typeDefs = `
# Root Query
type Query {
  someInt: Int
}
 
# Root Subscription
type Subscription {
  clock: String
}
`;

const resolvers = {
    Subscription: {
        clock(root, args, ctx) {
            return ctx.clockSource;
        }
    }
};

// Compose togather resolver and typeDefs.
const schema = makeExecutableSchema({
    typeDefs: typeDefs,
    resolvers: resolvers
});
prepareSchema(schema);

// subscribe the clock
const query = `
  subscription {
    clock
  }
`;
// Calling the reactive version of graphql
graphqlRx(schema, query, null, { clockSource }).subscribe(
    console.log.bind(console),
    console.error.bind(console)
);

And my package.json

{
  "name": "learngraphql",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "body-parser": "^1.18.2",
    "express": "^4.16.2",
    "express-graphql": "^0.6.11",
    "graphql": "^0.12.3",
    "graphql-rxjs": "^0.11.7-0",
    "graphql-tools": "^2.14.1",
    "rxjs": "^5.5.5"
  },
  "devDependencies": {
    "eslint": "^4.13.1"
  }
}

harrypunk avatar Dec 20 '17 15:12 harrypunk

graphql & graphql-rxjs versions should be always aligned. so if you use 0.11.7-0 you should use graphql 0.11.7 with it instead of 0.12.3

DxCx avatar Dec 28 '17 07:12 DxCx

A new error after using [email protected]:

TypeError: Cannot read property 'next' of undefined
    at Observable._subscribe (/learngraphql/node_modules/graphql-rxjs/dist/bundle.js:1:22565)
    at Observable._trySubscribe (/learngraphql/node_modules/rxjs/Observable.js:172:25)
    at Observable.subscribe (/learngraphql/node_modules/rxjs/Observable.js:160:93)
    at Object.subscribeToResult (/learngraphql/node_modules/rxjs/util/subscribeToResult.js:23:27)
    at MergeMapSubscriber._innerSub (/learngraphql/node_modules/rxjs/operators/mergeMap.js:132:38)
    at MergeMapSubscriber._tryNext (/learngraphql/node_modules/rxjs/operators/mergeMap.js:129:14)
    at MergeMapSubscriber._next (/learngraphql/node_modules/rxjs/operators/mergeMap.js:112:18)
    at MergeMapSubscriber.Subscriber.next (/learngraphql/node_modules/rxjs/Subscriber.js:90:18)
    at /learngraphql/node_modules/rxjs/observable/PromiseObservable.js:66:36
    at <anonymous>
/learngraphql/node_modules/rxjs/observable/PromiseObservable.js:76
                    root_1.root.setTimeout(function () { throw err; })

I've also started a completely new project with minimum dependencies, now package.json is:

{
  "name": "learngraphql",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "graphql": "0.11.7",
    "graphql-rxjs": "^0.11.7-0",
    "graphql-tools": "^2.14.1",
    "rxjs": "^5.4.3"
  }
}

harrypunk avatar Dec 29 '17 04:12 harrypunk

Same issue here:

​​Cannot read property 'next' of undefined​​
  at ​​​Observable._subscribe​​​ ​./node_modules/graphql-rxjs/dist/bundle.js:1​
  at ​​​Observable._2f1‍.r.Observable._trySubscribe​​​ ​./node_modules/rxjs/Observable.js:172​
  at ​​​Observable._2f1‍.r.Observable.subscribe​​​ ​./node_modules/rxjs/Observable.js:160​
  at ​​​Object.subscribeToResult​​​ ​./node_modules/rxjs/util/subscribeToResult.js:23​
  at ​​​MergeMapSubscriber._2f1‍.r.MergeMapSubscriber._innerSub​​​ ​./node_modules/rxjs/operators/mergeMap.js:132​
  at ​​​MergeMapSubscriber._2f1‍.r.MergeMapSubscriber._tryNext​​​ ​./node_modules/rxjs/operators/mergeMap.js:129​
  at ​​​MergeMapSubscriber._2f1‍.r.MergeMapSubscriber._next​​​ ​./node_modules/rxjs/operators/mergeMap.js:112​
  at ​​​MergeMapSubscriber._2f1‍.r.Subscriber.next​​​ ​./node_modules/rxjs/Subscriber.js:90​
  at ​./node_modules/rxjs/observable/PromiseObservable.js:66​
  at ​​​process._tickDomainCallback​​​ ​internal/process/next_tick.js:228​
  "dependencies": {
    "graphql": "0.11.7",
    "graphql-rxjs": "0.11.7-0",
    "graphql-tools": "2.21.0",
    "rxjs": "5.5.6"
  }

just copied and paste the examples on the README.

Fabs avatar Mar 11 '18 13:03 Fabs