Я новичок в graphql-compose
Я пытаюсь запустить первый сервис на простой схеме mongoose:
graphql.js:
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
Теперь в моем коде сервера у меня есть это:
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, когда я пытаюсь выполнить следующий запрос:
{
folderOne(filter: {}, sort: _ID_ASC) {
name
}
}
Я получаю следующую ошибку:
{
"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)"
]
}
]
}
Чего мне не хватать ???
ps: извините, я попытался пометить вопрос с помощью graphql-compose-mongoose, но этот тег не существует, поэтому я пометил его с помощью graphql-js