Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS problem ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH #2

Open
JeremyGreaux opened this issue Dec 20, 2017 · 8 comments
Open

CORS problem ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH #2

JeremyGreaux opened this issue Dec 20, 2017 · 8 comments

Comments

@JeremyGreaux
Copy link

Hi,
I use adonis-apollo-server(^1.0.2) extension to create my own graphQL api.
Query request works fine, but when I use Mutation query, I have got this request error:

POST http://localhost:3333/graphql net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH ApolloError.js:34 Uncaught (in promise) Error: Network error: Failed to fetch at new ApolloError (ApolloError.js:34) at Object.error (QueryManager.js:122) at SubscriptionObserver.error (zen-observable.js:174) at httpLink.js:147 at

I tryed to change cors configs, but no changes.
With another graphQL API (express), I have not this error.

Thx for helping

@ammezie
Copy link
Owner

ammezie commented Dec 20, 2017

Hey,

I use both queries and mutation without any errors. Do you mind sharing how to reproduce this error so I can take a closer look at it?

@JeremyGreaux
Copy link
Author

Hi,

With graphiQL it's work well, but in my react APP, it's not working.

My schema is :

  type Mutation {
    login (email: String!, password: String!): String
    createUser (username: String!, email: String!, password: String!): User
  }

In my resolver :

...
  Mutation: {
    async login(_, { email, password }, { auth }) {
      const { token } = await auth.attempt(email, password)
      return token
    },
...

My server running on 127.0.0..1:3333/graphql and my react APP on 127.0.0.1:3000

@ammezie
Copy link
Owner

ammezie commented Dec 20, 2017

You will have to enable CORS on the GraphQL server. Set origin to true in config/cors.js.

@JeremyGreaux
Copy link
Author

Hi have recreate demo project if you want reproduce my bug :
https://github.com/JeremyGreaux/adonis-graphql-test
https://github.com/JeremyGreaux/react-graphql-test

my origin is set to true

@ammezie
Copy link
Owner

ammezie commented Dec 20, 2017

Hey,

I just tried my own graphql server with a Vue app using Apollo client. Everything works fine both queries and mutations. All I had to do was enable CORS.

I will take a look at your code but I'm not that confident with React.

@JeremyGreaux
Copy link
Author

Humm I tryed with express and express-apollo-server and it's worked.

@pikitgb
Copy link

pikitgb commented Jan 22, 2018

Having same issue here. The queries work fine but mutations are failing. The mutation actually works when i run it in:

http://host:port/graphiql

But the POST method seems to be is failing from the apollo client in the React Component .

I'm using Adonis4 my origin is in true in the cors.js file.

Route.route('/graphql', ({ request, response }) => {
return ApolloServer.graphql({ schema }, request, response)
}, ['GET', 'POST'])

best regards.

@pikitgb
Copy link

pikitgb commented Jan 22, 2018

Uhmm weird, ok I think i see what's causing this, @JeremyGreaux maybe this helps you.

I have this mutation that create notes:
const NOTE_MUTATION = gqlmutation note($title: String, $note: String, user_id: Int) { note(title: $title, note: $note, user_id: Int) { id } }
export default graphql(NOTE_MUTATION, { name: 'note' })(Notes);

But in my Mutation (schema) definition i have this, (schemas.js)
note(title: String, note: String): Note
(Check here that the user_id is not included in the Schema definition for the mutation... )

Once i changed my React code and removed my user_id the code started working again.

const NOTE_MUTATION = gqlmutation note($title: String, $note: String) { note(title: $title, note: $note) { id } }
export default graphql(NOTE_MUTATION, { name: 'note' })(Notes);

Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants