admin管理员组文章数量:1393880
UPDATE: apollo has updated code and docs so issue is irrelevant now
Intended oute
start apollo-server-express using the following snippet from .
import express from 'express';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import bodyParser from 'body-parser';
import schema from './data/schema';
const GRAPHQL_PORT = 3000;
const graphQLServer = express();
graphQLServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
graphQLServer.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(`GraphiQL is now running on http://localhost:${GRAPHQL_PORT}/graphiql`));
Actual Oute:
In any implementation of apollo-server-express, using docs, using , etc. I receive the follow stack trace over and over again:
Error: Must provide document
at invariant (~/node_modules/graphql/jsutils/invariant.js:18:11)
at Object.validate (~/node_modules/graphql/validation/validate.js:58:34)
at doRunQuery (~/node_modules/apollo-server-core/dist/runQuery.js:80:38)
at ~/node_modules/apollo-server-core/dist/runQuery.js:20:54
at <anonymous>
How to reproduce the issue:
git clone .git
cd apollo-tutorial-kit
yarn/npm i
npm start
UPDATE: apollo has updated code and docs so issue is irrelevant now
Intended oute
start apollo-server-express using the following snippet from https://github./apollographql/apollo-tutorial-kit.
import express from 'express';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import bodyParser from 'body-parser';
import schema from './data/schema';
const GRAPHQL_PORT = 3000;
const graphQLServer = express();
graphQLServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
graphQLServer.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(`GraphiQL is now running on http://localhost:${GRAPHQL_PORT}/graphiql`));
Actual Oute:
In any implementation of apollo-server-express, using docs, using https://github./apollographql/apollo-tutorial-kit, etc. I receive the follow stack trace over and over again:
Error: Must provide document
at invariant (~/node_modules/graphql/jsutils/invariant.js:18:11)
at Object.validate (~/node_modules/graphql/validation/validate.js:58:34)
at doRunQuery (~/node_modules/apollo-server-core/dist/runQuery.js:80:38)
at ~/node_modules/apollo-server-core/dist/runQuery.js:20:54
at <anonymous>
How to reproduce the issue:
git clone https://github./apollographql/apollo-tutorial-kit.git
cd apollo-tutorial-kit
yarn/npm i
npm start
Share
Improve this question
edited Apr 5, 2018 at 10:12
martin8768
asked Oct 20, 2017 at 12:36
martin8768martin8768
5765 silver badges22 bronze badges
3
- 1 4 months ago, i thinks is very old for apollo, that keep changing – stackdave Commented Oct 21, 2017 at 14:44
-
1
The starter kit works fine. That sounds like an error you are getting in response to a request you're making. Usually that error is thrown when the request body is malformed or the
Content-Type: application/json
header is missing. You should update your question to include how you're attempting to make the request to the server. – Daniel Rearden Commented Oct 22, 2017 at 18:00 - 1 After clearing my npm cache && node_modules, I got it to work! Thanks guys – martin8768 Commented Oct 23, 2017 at 11:50
2 Answers
Reset to default 9In my case I was getting this error because I wasn't using the correct key in my request to the graphql server.
I was sending a mutation
request and I thought the key in the object needed to be "mutation"
but it turns out both query and mutation requests use the key "query"
.
xhr.open('POST', '/graphql');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({
query: mutationString,
}));
I was using JQuery Ajax for HTTP Post Request to graphql server (apollo-server-express) and getting this error while querying for mutation. The reason was same as described by spencer.sm. To help other googlers, I am pasting here plete method-
(function() {
globals.makeGraphQLRequest('graphql', {
query: `query($email: String!) {
profile(email: $email) {
id mobile name email dob gender
}
}`,
variables: {
email: '[email protected]'
}
}, function successCallback(response) {
console.log(response);
});
globals.makeGraphQLRequest('graphql', {
query: `mutation($email: String!) {
updateUser(email: $email) {
email
}
}`,
variables: {
email: '[email protected]'
}
}, function successCallback(response) {
console.log(response);
});
}());
makeGraphQLRequest-
globals.makeGraphQLRequest = function(url, params, successCallback) {
$.ajax({
url: url,
method: 'post',
data: params,
dataType: 'json',
success: function(response) {
successCallback(response);
},
error: globals.ajaxErrorHandler
});
}
本文标签: javascriptGraphQL Error Must provide DocumentStack Overflow
版权声明:本文标题:javascript - GraphQL: Error: Must provide Document - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744083801a2588139.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论