adonis-apollo-server
adonis-apollo-server copied to clipboard
CORS problem ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH
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
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?
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
You will have to enable CORS on the GraphQL server. Set origin
to true
in config/cors.js
.
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
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.
Humm I tryed with express and express-apollo-server and it's worked.
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.
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.