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
Is application/graphql supported? #48
Comments
As far as I know, |
I was playing around w/ a few modules, one of which expected it to be supported (graphql-tester) |
Yeah, that seems super weird to be honest. I don't think it's to anyone's advantage to introduce new MIME types? It's nowhere in the spec or any implementations that I'm aware of. |
|
@nevir Which version of apollo-server did you use? The current release uses express-graphql under the hood, so I find it hard to believe that it wouldn't work. The release candidate doesn't parse queries automatically, so you'd have to do that yourself by telling body-parser to parse application/graphql. |
I was on |
Hm, that's strange. It should definitely work because 0.1.5 passes the same tests as express-graphql. |
Hmm. I didn't find any reference to @helfer I can confirm that
$ curl -X POST http://localhost:8080/graphql -d '{"query": "query test { posts { title } }" }' -H 'Content-Type: application/json'
{"data":{"posts":[{"title":"Introduction to GraphQL"},{"title":"GraphQL Rocks"},{"title":"Advanced GraphQL"}]}}% but not $ curl -X POST http://localhost:8080/graphql -d '{ posts { title } }' -H 'Content-Type: application/graphql'
{"errors":[{"message":"Cannot read property 'definitions' of undefined"}]}% It was an easy switch to |
Content type application/graphql isn't great because it doesn't support variables. I would suggest just not using it. |
@stubailo Can you clarify? Variables work for me. |
How do you pass them, as query parameters? |
Sorry, I misunderstood what GraphQL variables were until I read the docs. |
Right - variables are a critical part of the GraphQL specification, so it's really surprising that the "official" HTTP server middleware supports a transport that doesn't have any ability to use them. |
|
@sveinburne I would find it interesting to know why they recommend supporting those two use-cases. If there's a good reason for it, I wouldn't be opposed to adding the same functionality in graphql-server. Right now I think it was a mistake to come up with "application/graphql", thus I don't think graphql-server should support it. After all, Lee Byron said himself that when you're thinking of adding something but you're not sure you'll need it, then "you ain't gonna need it". So far I haven't heard a convincing argument for why anybody needs "application/graphql". I'd like to be enlightened though, so if someone knows, please tell me! |
Yeah there was a discussion on some graphql.org issue about removing that recommendation and I didn't find any concrete arguments for why it exists. |
Would really appreciate this somehow being sought through. Personally, I think it's better if they just pick one... Only reason I suppose this is a value use case - is for |
@helfer maybe need is a strong word for describe('Server', () => {
it('has GraphQL middleware mounted at /graphql', async () => {
let server = new Server()
let response = await request(server)
.post('/graphql')
.set('Content-Type', 'application/graphql; charset=utf-8')
.send(`{ hello }`)
expect(response.status).toEqual(200)
})
}) and curl: curl -v -H "Content-Type: application/graphql" -d "{ hello }" "localhost:3000/graphql" JSON is clunky for those simple cases and readability suffers. This obviously isn't a big thing, but it's still nice to have IMO. |
If you want to run a GraphQL proxy, or handle requests in the middleware chain, multiple ways to send queries can be a big downside. You pretty much need both GET and POST, but the application/graphql method is more optional. You could always add an extra middleware to the chain to attach stuff to the request body to add support for other transports. |
I have just released an Express body-parser that supports the application/graphql MIME type. It can be used as a drop-in replacement for the JSON body-parser. https://www.npmjs.com/package/body-parser-graphql 🎉 |
Shouldn't the content type be something like |
I'm guessing that I'm doing something dumb here, but I can't see it :( Would appreciate some pointers!
Requesting via the JSON protocol works great:
But when I attempt to use the
application/graphql
protocol, I get:The text was updated successfully, but these errors were encountered: