0
我正在嘗試graphQL時遇到問題。我想我在模式或解析器上做錯了什麼。根據文檔的一切,但仍然無法獲得數據。nodejs與Graphql
我需要什麼是非常簡單的用戶模型來在graphiql中運行它的查詢。
這裏是我的代碼:Download code (zip file)(節點-7.5代碼) 然後只需運行NPM安裝和NPM運行建立。
主要文件:server.js,schema.js,models/user.js和resolvers/user.js。
型號/ user.js的
const typeDefinitions = `
type User {
id: String!
name: String
type: Int
isActive: Boolean
clients: [String]
}
schema {
query: User
}
`;
export default [typeDefinitions]
解析器/ user.js的: -
const resolverMap = {
User: {},
};
export default resolverMap
schema.js
import { makeExecutableSchema } from 'graphql-tools';
import resolver from '../resolvers/user'
import User from './user';
export default makeExecutableSchema({
typeDefs: User,
resolvers: resolver,
});
server.js: -
import express from 'express';
import bodyParser from 'body-parser';
import routes from './app/routers/index';
import { graphqlExpress } from 'graphql-server-express';
import schema from './app/models/schema'
var app = express(); // create our app w/ express
var database = require('./app/configs/database');
var port = process.env.PORT || 8888; // set the port
app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({ 'extended': 'true' })); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use('/graphql', bodyParser.json(), graphqlExpress({
graphiql: true,
pretty: true,
schema: schema
}));
app.listen(port);
console.log("App listening on port : " + port);
什麼樣的錯誤你好嗎,你能請提及 –
這是說「Get query missing。」。並沒有圖形用戶界面。帶一條消息的簡單空白頁面。 – user1893034