Giter VIP home page Giter VIP logo

Comments (11)

joanrodriguez avatar joanrodriguez commented on May 3, 2024 16

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.

leebyron avatar leebyron commented on May 3, 2024 10

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.

dh94 avatar dh94 commented on May 3, 2024 6

@AvraamMavridis @ghost try adding

app.use(bodyParser.text({ type: 'application/graphql' }));

fixed it for me

from express-graphql.

AvraamMavridis avatar AvraamMavridis commented on May 3, 2024 3

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:

screen shot 2017-08-06 at 11 30 16

Any help?

from express-graphql.

eric-burel avatar eric-burel commented on May 3, 2024 2

@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.

kuminra avatar kuminra commented on May 3, 2024 1

https://www.npmjs.com/package/body-parser-graphql

fixed it for me

from express-graphql.

philostler avatar philostler commented on May 3, 2024

+1 I'm experiencing exactly the same issue as @aj1310 describes

from express-graphql.

leebyron avatar leebyron commented on May 3, 2024

This is now fixed and will go out with the next release.

from express-graphql.

joanrodriguez avatar joanrodriguez commented on May 3, 2024

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.

SyedAman avatar SyedAman commented on May 3, 2024

@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.

AvraamMavridis avatar AvraamMavridis commented on May 3, 2024

@SyedAman see https://stackoverflow.com/questions/45530623/graphql-must-provide-query-string

from express-graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.