2017-02-21 3 views
0

graphQL을 시도하는 중 문제가 발생했습니다. 나는 스키마 나 리졸버에서 뭔가 잘못하고있는 것 같아요. 모든 것이 문서에 따라 다르지만 여전히 데이터를 가져올 수 없습니다.Graphql을 사용하는 nodejs

필요한 것은 graphiql에서 쿼리를 실행하는 매우 간단한 사용자 모델입니다.

여기 내 코드입니다 : Download code (zip file) (노드 7.5 코드) 다음 단지 NPM은NPM 실행이를 빌드, 설치 실행합니다.

주 파일 : server.js, schema.js, models/user.js 및 resolvers/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); 

모델/

const typeDefinitions = ` 
type User { 
    id: String! 
    name: String 
    type: Int 
    isActive: Boolean 
    clients: [String] 
} 
    schema { 
    query: User 
} 
`; 
export default [typeDefinitions] 

리졸버 /의 user.js을의 user.js

+0

에 대한 엔드 포인트를 통과해야 내가 추측 더 이상 지원되지 않습니다 당신에게, 어떤 오류를 수지고있다 제발 언급 –

+1

그것은 "쿼리를 놓치지."라고 말하고있다. 그리고 graphiQl UI도 없습니다. 하나의 메시지가있는 단순한 빈 페이지. – user1893034

답변

0
당신은 위의 코드를 사용할 필요가

import { graphiqlExpress } from 'graphql-server-express'; 
app.use('/graphiql', graphiqlExpress({ 
    endpointURL: '/graphql', 
})); 
,

graphiql: true 당신은 graphiql 방법을 가져오고 같은

관련 문제