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

Missing content type with invalid json as query #519

Closed
vektah opened this issue Jan 30, 2019 · 1 comment
Closed

Missing content type with invalid json as query #519

vektah opened this issue Jan 30, 2019 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers v0.8 For release in v0.8

Comments

@vektah
Copy link
Collaborator

vektah commented Jan 30, 2019

Expected Behaviour

curl --header "Content-Type: application/json" --request POST --data 'fff' http://localhost:8080/graphql

should return Content-Type application/json

Actual Behavior

Isn't setting the content type.

@vektah vektah added bug Something isn't working good first issue Good for newcomers labels Jan 30, 2019
@Sonna
Copy link
Contributor

Sonna commented Jan 30, 2019

Is it not being set within the GraphQL handler ServeHTTP (might need to just move it up to occur earlier before the bad responses; e.g. before switch r.Method)?

w.Header().Set("Content-Type", "application/json")

UPDATE: Turns outs apply the following second suggestion blocks/breaks the Websocket connection within the handler.GraphQL function 😐

connectWs(gh.exec, w, r, gh.cfg)

Or would you want the generated server template prefix with a response writer to fix the headers?

http.Handle("/query", handler.GraphQL({{ lookupImport .ExecPackageName }}.NewExecutableSchema({{ lookupImport .ExecPackageName}}.Config{Resolvers: &{{ lookupImport .ResolverPackageName}}.Resolver{}})))

        http.With(func(i http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("Content-Type", "application/json")
		})
	}).Handle("/query", handler.GraphQL({{ lookupImport .ExecPackageName }}.NewExecutableSchema({{ lookupImport .ExecPackageName}}.Config{Resolvers: &{{ lookupImport .ResolverPackageName}}.Resolver{}})))

Sonna added a commit that referenced this issue Feb 5, 2019
Update the GraphQL handler to set the Response Header to JSON ealier for
error messages to be returned as JSON and not text/html.

Fixes #519
Sonna added a commit that referenced this issue Feb 5, 2019
Update the GraphQL handler to set the Response Header to JSON ealier for
error messages to be returned as JSON and not text/html.

Fixes #519

== Notes:
- Add checks for JSON Content-Type checks in decode bad queries tests
Sonna added a commit that referenced this issue Feb 5, 2019
Update the GraphQL handler to set the Response Header to JSON earlier for
error messages to be returned as JSON and not text/html.

Fixes #519

== Notes:
- Add checks for JSON Content-Type checks in decode bad queries tests
Sonna added a commit that referenced this issue Feb 5, 2019
Update the GraphQL handler to set the Response Header to JSON earlier for
error messages to be returned as JSON and not text/html.

Fixes #519

== Notes:
- Add checks for JSON Content-Type checks in decode bad queries tests
Sonna added a commit that referenced this issue Feb 5, 2019
Update the GraphQL handler to set the Response Header to JSON earlier for
error messages to be returned as JSON and not text/html.

Fixes #519

== Notes:
- Add checks for JSON Content-Type checks in decode bad queries tests
Sonna added a commit that referenced this issue Feb 5, 2019
Fix set header to JSON earlier in GraphQL response

Update the GraphQL handler to set the Response Header to JSON earlier for
error messages to be returned as JSON and not text/html.

Fixes #519

## Notes:
- Add checks for JSON Content-Type checks in decode bad queries tests
@vektah vektah closed this as completed Feb 7, 2019
@vektah vektah added the v0.8 For release in v0.8 label Feb 7, 2019
cgxxv pushed a commit to cgxxv/gqlgen that referenced this issue Mar 25, 2022
Update the GraphQL handler to set the Response Header to JSON earlier for
error messages to be returned as JSON and not text/html.

Fixes 99designs#519

== Notes:
- Add checks for JSON Content-Type checks in decode bad queries tests
cgxxv pushed a commit to cgxxv/gqlgen that referenced this issue Mar 25, 2022
…ent-type

Fix set header to JSON earlier in GraphQL response

Update the GraphQL handler to set the Response Header to JSON earlier for
error messages to be returned as JSON and not text/html.

Fixes 99designs#519

## Notes:
- Add checks for JSON Content-Type checks in decode bad queries tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers v0.8 For release in v0.8
Projects
None yet
Development

No branches or pull requests

2 participants