Comments (11)
I solved my problem doing the following:
// configure app to use bodyParser()
// this will let us get the data from a POST
// exclusing the route to graphql
app.use(/\/((?!graphql).)*/, bodyParser.urlencoded({ extended: true }));
app.use(/\/((?!graphql).)*/, bodyParser.json());
from express-graphql.
Yes this is fixed. However if you're also using body-parser, you must still ensure the output of body-parser is compatible with the express-graphql plugin.
The recommended use is still to use the express-graphql middleware before using any kind of body parser middleware you may be using for other routes.
from express-graphql.
@AvraamMavridis @ghost try adding
app.use(bodyParser.text({ type: 'application/graphql' }));
fixed it for me
from express-graphql.
I am experiencing the same issue using :
"body-parser": "^1.17.2",
"express": "^4.15.3",
"express-graphql": "^0.6.
My server:
const schema = require('./schema');
const express = require('express');
const graphqlHTTP = require('express-graphql');
const cors = require('cors')
const bodyParser = require('body-parser');
const app = express();
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/graphql', graphqlHTTP(req => {
return ({
schema,
pretty: true,
})
}));
const server = app.listen(9000, err => {
if (err) { return err; }
console.log(`GraphQL server running on http://localhost:${9000}/graphql`);
});
Request:
Any help?
from express-graphql.
@dh94 can you confirm that this need to be called after bodyParser.json()
? I had some issues with Apollo Server 2 in a Meteor app and writing
app.use(bodyParser.json())
app.use(bodyParser.text({ type: 'application/graphql' }));
seemed to fix it.
Edit: it was not sufficient, see body-parser-graphql package which works fine now
from express-graphql.
https://www.npmjs.com/package/body-parser-graphql
fixed it for me
from express-graphql.
+1 I'm experiencing exactly the same issue as @aj1310 describes
from express-graphql.
This is now fixed and will go out with the next release.
from express-graphql.
Are you sure this has been fixed? I'm running express-graphql 0.4.13
with body-parser 1.15.0
and doing a POST with headers set to Content-Type: application/graphql
I get
{
"errors": [
{
"message": "Must provide query string."
}
]
}
from express-graphql.
@AvraamMavridis you got this to work? I got a similar issue
Btw, you're using content-type: text/plain
it has to be application/json
from express-graphql.
@SyedAman see https://stackoverflow.com/questions/45530623/graphql-must-provide-query-string
from express-graphql.
Related Issues (20)
- depth-limit HOT 1
- Is there a way to customize a logger HOT 1
- Unhandled errors does not provide mutation or query name HOT 1
- Graphiql playground not displayed in the browser HOT 1
- UnhandledPromiseRejectionWarning: Unhandled promise rejection HOT 1
- Why isn't the callback of app.listen() called when using express-graphql middleware? HOT 4
- Build when installed from GitHub HOT 1
- throw new MiddlewareError(`Type ${type} exists in middleware but is missing in Schema.`);
- TypeScript - merge declarations for request and response types
- Cannot install with graphql 16.0.1 HOT 10
- Update GraphQL Schema at runtime HOT 4
- Graphql 16.2.0 support HOT 9
- Processing timeout HOT 1
- About compatible version for an old graphql and node
- Swallow GraphQL errors by Express HOT 6
- Peer dependency error on new installation of graphql HOT 8
- Unmet Peer version, need to update supported dependencies HOT 9
- revert revert "Allow custom handling of runtime query errors" HOT 1
- Unable to find Prisma Client in GraphQL context. Please provide it under the `context[\"prisma\"]` key. HOT 1
- Support for running method on every call
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-graphql.