Graphqlbundle: Endpoint GraphQL Not support Method POST

Created on 19 Mar 2020  路  17Comments  路  Source: overblog/GraphQLBundle

Hello
For 3 Days, my project which worked perfectly locally, once put on the production server.
GraphQl requests are a failure with the error "[Error: Network error: JSON Parse error: Unrecognized token '<']" and after log analysis it is a 404 error because the route was not found.

After investigation via the GraphQl Atlair client for chrome by changing the method to GET to make my GrasphQl requests, the error everything works.

my question is how to work the POST method?

### EDIT

the stack Error complete
{
"type": "https://tools.ietf.org/html/rfc2616#section-10",
"title": "An error occurred",
"status": 404,
"detail": "No route found for "POST /overblog/graphql"",
"class": "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/http-kernel/EventListener/RouterListener.php",
"line": 136,
"args": []
},
{
"namespace": "Symfony\Component\HttpKernel\EventListener",
"short_class": "RouterListener",
"class": "Symfony\Component\HttpKernel\EventListener\RouterListener",
"type": "->",
"function": "onKernelRequest",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/event-dispatcher/Debug/WrappedListener.php",
"line": 126,
"args": [
[
"object",
"Symfony\Component\HttpKernel\Event\RequestEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher\Debug",
"short_class": "WrappedListener",
"class": "Symfony\Component\EventDispatcher\Debug\WrappedListener",
"type": "->",
"function": "__invoke",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 264,
"args": [
[
"object",
"Symfony\Component\HttpKernel\Event\RequestEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\Component\EventDispatcher\EventDispatcher",
"type": "->",
"function": "doDispatch",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 239,
"args": [
[
"array",
[
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
]
]
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\Component\HttpKernel\Event\RequestEvent"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\Component\EventDispatcher\EventDispatcher",
"type": "->",
"function": "callListeners",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 73,
"args": [
[
"array",
[
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
],
[
"object",
"Symfony\Component\EventDispatcher\Debug\WrappedListener"
]
]
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\Component\HttpKernel\Event\RequestEvent"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\Component\EventDispatcher\EventDispatcher",
"type": "->",
"function": "dispatch",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php",
"line": 168,
"args": [
[
"object",
"Symfony\Component\HttpKernel\Event\RequestEvent"
],
[
"string",
"kernel.request"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher\Debug",
"short_class": "TraceableEventDispatcher",
"class": "Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher",
"type": "->",
"function": "dispatch",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/http-kernel/HttpKernel.php",
"line": 122,
"args": [
[
"object",
"Symfony\Component\HttpKernel\Event\RequestEvent"
],
[
"string",
"kernel.request"
]
]
},
{
"namespace": "Symfony\Component\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\Component\HttpKernel\HttpKernel",
"type": "->",
"function": "handleRaw",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/http-kernel/HttpKernel.php",
"line": 68,
"args": [
[
"object",
"Symfony\Component\HttpFoundation\Request"
],
[
"integer",
1
]
]
},
{
"namespace": "Symfony\Component\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\Component\HttpKernel\HttpKernel",
"type": "->",
"function": "handle",
"file": "/home/foongon/website/yamo-mobile-backend/vendor/symfony/http-kernel/Kernel.php",
"line": 201,
"args": [
[
"object",
"Symfony\Component\HttpFoundation\Request"
],
[
"integer",
1
],
[
"boolean",
true
]
]
},
{
"namespace": "Symfony\Component\HttpKernel",
"short_class": "Kernel",
"class": "Symfony\Component\HttpKernel\Kernel",
"type": "->",
"function": "handle",
"file": "/home/foongon/website/yamo-mobile-backend/public/index.php",
"line": 25,
"args": [
[
"object",
"Symfony\Component\HttpFoundation\Request"
]
]
}
]
}

the route endpoint with the POST (/overblog/graphql) method refuses to work but with the GET method all is Okay. I don't know how to solve this problem

I really need to use the METHOD POST for mutations
Thanks everyone
Very cordially

Most helpful comment

@ththugues44

Try to make a POST request to this address /overblog/graphql/ (with a slash at the end)

All 17 comments

Hi, @ththugues44.

Unfortunately I am not familiar with this error. Could you provide minimal steps to reproduce the error? Or, as another option, you could upload your project to github repository (private or public), so that I could take a look at it myself.

You can provide the password to the repository directly to me in Slack or in Telegram. You can find my profile in the official channels.

Hello

@murtukov Thank you for your reply. my major problem is that my GraphQL server does not accept requests and transfers to Method POST.
All my requests or MUTATION in method POST return the error (Error: Network error: JSON Parse error: Unrecognized token '<'])
Its same requests or mutation works very well in Method GET .
I don't know if anyone else had this problem if so how did you manage this. ?

@ththugues44

When you make a request, your backend returns html in the response instead of json. Html code always starts with '<' symbol and your client tries to parse it as json, thats why you get this error message: JSON Parse error: Unrecognized token '<'. This error does NOT happen inside resolvers, because resolvers always catch any exceptions and serialize them into a json response.

What client do you use to make requests?

Hello

@murtukov Thank you for your reply.

You understand exactly the problem, the server returns HTML and not Json.
My question is how to configure Overblog / GraphQl so that it accepts requests and Mutation with the Method POST.
because my requests and mutation works perfectly well with the GET method.
I use the following clients:

  • GraphiQl for Development
  • Appolo Client on my React Native app
  • HasQ GraphQl Online Client

on its different clients the request and transfer with the POST method does not work, how to configure Overblog / GraphQl so that it accepts requests and Mutation with the POST Method.

@murtukov i update post

@ththugues44 Obviously you didn't configure your route properly. Show me your config/routes/graphql.yaml file

@murtukov my config/routes/graphql.yaml

overblog_graphql_single_endpoint:
    resource: "@OverblogGraphQLBundle/Resources/config/routing/single.yaml"
    prefix: /overblog/graphql

what is problem ?

Show me result of the command php bin/console de:ro

@murtukov result command php bin/console de:ro


Name Method Scheme Host Path


_preview_error ANY ANY ANY /_error/{code}.{_format}
overblog_graphiql_endpoint ANY ANY ANY /graphiql
overblog_graphiql_endpoint_multiple ANY ANY ANY /graphiql/{schemaName}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
fos_user_security_login GET|POST ANY ANY /login
fos_user_security_check POST ANY ANY /login_check
fos_user_security_logout GET|POST ANY ANY /logout
fos_user_profile_show GET ANY ANY /profile/
fos_user_profile_edit GET|POST ANY ANY /profile/edit
fos_user_registration_register GET|POST ANY ANY /register/
fos_user_registration_check_email GET ANY ANY /register/check-email
fos_user_registration_confirm GET ANY ANY /register/confirm/{token}
fos_user_registration_confirmed GET ANY ANY /register/confirmed
fos_user_resetting_request GET ANY ANY /resetting/request
fos_user_resetting_send_email POST ANY ANY /resetting/send-email
fos_user_resetting_check_email GET ANY ANY /resetting/check-email
fos_user_resetting_reset GET|POST ANY ANY /resetting/reset/{token}
fos_user_change_password GET|POST ANY ANY /profile/change-password
overblog_graphql_endpoint ANY ANY ANY /overblog/graphql/
overblog_graphql_batch_endpoint ANY ANY ANY /overblog/graphql/batch


@ththugues44

Try to make a POST request to this address /overblog/graphql/ (with a slash at the end)

@murtukov really thank you very much the addition of the slash (/) at the end solved the problem

@ththugues44 This is a typical mistake, that happens to everyone. It happened many times to me. I guess we need to fix it. I will add it to my list.

@murtukov thank you, i close the ticket

Hello!
Actually, I don't understand why the graphql endpoint route can't be without a trailing slash?
@murtukov , could you explain, please?

Hi @scion4581

https://symfony.com/doc/4.1/routing.html#routing-trailing-slash-redirection

Yeah, I saw that doc, but it explains only redirections depends on does route has a trailing slash or not
But I want a route /graphql without trailing slash, like this one below

overblog_graphql_endpoint ANY ANY ANY /graphql
overblog_graphql_batch_endpoint ANY ANY ANY /graphql/batch
overblog_graphql_multiple_endpoint ANY ANY ANY /graphql/{schemaName}
overblog_graphql_batch_multiple_endpoint ANY ANY ANY /graphql/{schemaName}/batch

So, I tied to trailing slash because of it here
overblog_graphql_endpoint:
path: /
defaults:
_controller: OverblogGraphQLBundleControllerGraphController::endpointAction
_format: "json"

To do it in my way I don't have to import
overblog_graphql_endpoint:
resource: "@OverblogGraphQLBundle/Resources/config/routing/graphql.yml"

But just copy all routes from the bundle and make a correction

If you configure your routes without the trailing slash and you don't have the redirection enabled, then you need to ensure your client also requests the proper URL (without trailing slash)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apoberez picture apoberez  路  3Comments

AliceMakk picture AliceMakk  路  4Comments

VincentClair picture VincentClair  路  4Comments

VincentClair picture VincentClair  路  5Comments

paoloposo picture paoloposo  路  3Comments