首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GraphQL -复合-猫鼬生成错误:预期[对象对象]为GraphQL模式

GraphQL -复合-猫鼬生成错误:预期[对象对象]为GraphQL模式
EN

Stack Overflow用户
提问于 2018-05-30 14:32:11
回答 1查看 583关注 0票数 0

我是图‘m写作新手

我试图在一个简单的猫鼬模式上启动第一个服务:

graphql.js:

代码语言:javascript
复制
import mongoose from 'mongoose'
import { composeWithMongoose} from 'graphql-compose-mongoose'
import { schemaComposer } from 'graphql-compose'

const db = require( '../models/db' )
//const mongoose = require('mongoose');
const folderDAO = mongoose.model('folder');

const customizationOptions = {}; // left it empty for simplicity, described below
const folderTC = composeWithMongoose(folderDAO, customizationOptions);

schemaComposer.rootQuery().addFields({
    folderOne: folderTC.getResolver('findOne'),
})

const graphqlSchema = schemaComposer.buildSchema()

console.log("Schema built : ", graphqlSchema )

export default graphqlSchema

在我的服务器代码中,我有以下内容:

代码语言:javascript
复制
const express = require('express');
const graphqlHTTP = require('express-graphql')
const GraphQLSchema = require('./app_api/routes/graphql')
    app.use('/graphql', graphqlHTTP({
        schema: GraphQLSchema,
        graphiql: true,
        formatError: error => ({
            message: error.message,
            locations: error.locations,
            stack: error.stack ? error.stack.split('\n') : [],
            path: error.path
        })
    }));

在graphiql上,当我尝试以下查询时:

代码语言:javascript
复制
{
  folderOne(filter: {}, sort: _ID_ASC) {
    name
  }
}

我得到以下错误:

代码语言:javascript
复制
{
  "errors": [
    {
      "message": "Expected [object Object] to be a GraphQL schema.",
      "stack": [
        "Error: Expected [object Object] to be a GraphQL schema.",
        "    at invariant (/Users/zied/work/share_place/node_modules/graphql/jsutils/invariant.js:19:11)",
        "    at validateSchema (/Users/zied/work/share_place/node_modules/graphql/type/validate.js:55:60)",
        "    at assertValidSchema (/Users/zied/work/share_place/node_modules/graphql/type/validate.js:80:16)",
        "    at validate (/Users/zied/work/share_place/node_modules/graphql/validation/validate.js:58:35)",
        "    at /Users/zied/work/share_place/node_modules/express-graphql/dist/index.js:139:52",
        "    at <anonymous>",
        "    at process._tickDomainCallback (internal/process/next_tick.js:228:7)"
      ]
    }
  ]
}

我错过了什么?

对不起,我试图用graphql-合成-猫鼬标记这个问题,但是这个标签不存在,所以我用graphql标记它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-31 14:25:01

事实上,问题就在这里:

代码语言:javascript
复制
const GraphQLSchema = require('./app_api/routes/graphql')

必须用

代码语言:javascript
复制
const GraphQLSchema = require('./app_api/routes/graphql').default 

因为我们将其导出为默认值

更多信息可以在这里找到:https://github.com/graphql-compose/graphql-compose-mongoose/issues/103

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50607329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档