我是靠谱客的博主 害羞蜜粉,最近开发中收集的这篇文章主要介绍nodejs mysql graphql,带有Graphql的nodejs,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I am facing an issue, while trying graphQL. I guess I am doing something wrong at schema or resolver. Everything according to docs but still not able to get the data.

What Do I need is very simple user model to run its queries in graphiql.

Here is my code: Download code (zip file) (code for node-7.5)

and then just run npm install and npm run build.

Main files: server.js, schema.js, models/user.js and resolvers/user.js.

models/user.js

const typeDefinitions = `

type User {

id: String!

name: String

type: Int

isActive: Boolean

clients: [String]

}

schema {

query: User

}

`;

export default [typeDefinitions]

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);

解决方案import { graphiqlExpress } from 'graphql-server-express';

app.use('/graphiql', graphiqlExpress({

endpointURL: '/graphql',

}));

You need to use above code,

graphiql: true is not supported anymore I guess,

You need to import a graphiql method and pass an endpoint for the same

最后

以上就是害羞蜜粉为你收集整理的nodejs mysql graphql,带有Graphql的nodejs的全部内容,希望文章能够帮你解决nodejs mysql graphql,带有Graphql的nodejs所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部