title: Go: How to disable CORS using gqlgen graphql implementation?
body: <p>I am using <a href="https://gqlgen.com/" rel="nofollow noreferrer">gqlgen</a> as GraphQL server. I connect to this server from the front end application using <a href="https://www.apollographql.com/docs/react/" rel="nofollow noreferrer">Apollo client</a>. </p>
  
  <p>Everything works correctly if I compile the front end code and serve it as static content by the GraphQL server.</p>
  
  <p><strong>Problem:</strong> </p>
  
  <p>During development I have my Go-based GraphQL API running on <code>http://localhost:8080</code> and I have the front end code on a separate server runing on <code>http://localhost:3000</code>. This way I get CORS errors.</p>
  
  <p>I managed to fix the issue on the front end side by specifying <code>no-cors</code> option while creating the client, but the back end still gives 400s to my requests.</p>
  
  <p><strong>Question:</strong> </p>
  
  <p>How to disable CORS in a gqlgen-based GraphQL API?</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>config := gql.Config{Resolvers: &amp;gql.Resolver{}}
  handler := handler.GraphQL(gql.NewExecutableSchema(config))
  http.Handle("/query", handler)
  http.ListenAndServe(":8080", nil)
  </code></pre>
  
  <p>The full server side code is available <a href="https://github.com/Shpota/skmz/blob/master/server/server.go" rel="nofollow noreferrer">on GitHub</a>.</p>
  
  <p><strong>What I've tried</strong>: </p>
  
  <p>I followed <a href="https://gqlgen.com/recipes/cors/" rel="nofollow noreferrer">the solution from the documentation</a> which didn't work. I checked a couple of solutions on StackOverflow, like <a href="https://stackoverflow.com/questions/39507065/enable-cors-in-golang">this one</a>, however they give a library specific solutions which don't feet in my case.</p>