将Apollo集成到流星应用程序

时间:2017-12-28 18:34:55

标签: meteor graphql apollo apollo-client apollo-server

当我尝试将apollo服务器集成到meteor应用程序时,我会在尝试打开graphiql时出现错误。如果我创建一个快速应用程序并将其与webapp.connectHandlers连接,并将apollo服务器放入其中一个快速应用程序的路由,那么它们可以工作,但它们不能以“流星方式”工作,我真的很想拥有因为我可以访问用户对象,授权等。

错误,我在加载时会在graphiql中看到错误:

Error: Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory

堆栈跟踪: at invariant (/Users/.../node_modules/graphql/jsutils/invariant.js:18:11)<br> &nbsp; &nbsp;at Object.validate (/Users/.../node_modules/graphql/validation/validate.js:59:72)<br> &nbsp; &nbsp;at doRunQuery (/Users/.../node_modules/apollo-server-core/dist/runQuery.js:88:38)<br> &nbsp; &nbsp;at /Users/.../node_modules/apollo-server-core/dist/runQuery.js:22:54<br> &nbsp; &nbsp;at /Users/.../.meteor/packages/promise/.0.10.0.borizy.o9z8++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40

服务器代码:

import {makeExecutableSchema} from 'graphql-tools';
import {typeDefs} from './schema';
import {resolvers} from './resolvers';
import { createApolloServer } from 'meteor/apollo';

export const schema = makeExecutableSchema({
  typeDefs,
  resolvers
});

createApolloServer({
  schema
});

一切似乎都是合法的,适用于快递,但不适用于流星。是什么原因?我该如何解决?

2 个答案:

答案 0 :(得分:0)

当前版本的meteor/apollo与最新的apollo npm软件包已过期。 https://github.com/Swydo/ddp-apollo是最新的,并以“流星方式”进行整合

答案 1 :(得分:0)

  

还要确保node_modules目录中没有安装多个GraphQL版本

如果这是问题,可以通过

解决
rm -rf node_modules/*
npm install