0

i want to see graphql options in swagger docs, so i added this to config/packages/api_platform.yaml:

api_platform:
  formats:
    graphql: [ 'application/graphql' ]

but now when i load the docs page i get this:

{
   "type":"https:\/\/tools.ietf.org\/html\/rfc2616#section-10",
   "title":"An error occurred",
   "detail":"Serialization for the format \u0022graphql\u0022 is not supported.",
   "trace":[
      {
         "namespace":"",
         "short_class":"",
         "class":"",
         "type":"",
         "function":"",
         "file":"\/app\/vendor\/symfony\/serializer\/Serializer.php",
         "line":127,
         "args":[
            
         ]
      },
      {
         "namespace":"Symfony\\Component\\Serializer",
         "short_class":"Serializer",
         "class":"Symfony\\Component\\Serializer\\Serializer",
         "type":"-\u003E",
         "function":"serialize",
         "file":"\/app\/vendor\/api-platform\/core\/src\/Symfony\/EventListener\/SerializeListener.php",
         "line":121,
         "args":[
            [
               "object",
               "ApiPlatform\\Api\\Entrypoint"
            ],
            [
               "string",
               "graphql"
            ],
            [
               "array",
               [
                  
               ]
            ]
         ]
      },
      {
         "namespace":"ApiPlatform\\Symfony\\EventListener",
         "short_class":"SerializeListener",
         "class":"ApiPlatform\\Symfony\\EventListener\\SerializeListener",
         "type":"-\u003E",
         "function":"serializeRawData",
         "file":"\/app\/vendor\/api-platform\/core\/src\/Symfony\/EventListener\/SerializeListener.php",
         "line":72,
         "args":[
            [
               "object",
               "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
            ],
            [
               "object",
               "Symfony\\Component\\HttpFoundation\\Request"
            ],
            [
               "object",
               "ApiPlatform\\Api\\Entrypoint"
            ]
         ]
      },
      {
         "namespace":"ApiPlatform\\Symfony\\EventListener",
         "short_class":"SerializeListener",
         "class":"ApiPlatform\\Symfony\\EventListener\\SerializeListener",
         "type":"-\u003E",
         "function":"onKernelView",
         "file":"\/app\/vendor\/symfony\/event-dispatcher\/Debug\/WrappedListener.php",
         "line":115,
         "args":[
            [
               "object",
               "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
            ],
            [
               "string",
               "kernel.view"
            ],
            [
               "object",
               "Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
            ]
         ]
      },
      {
         "namespace":"Symfony\\Component\\EventDispatcher\\Debug",
         "short_class":"WrappedListener",
         "class":"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener",
         "type":"-\u003E",
         "function":"__invoke",
         "file":"\/app\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php",
         "line":206,
         "args":[
            [
               "object",
               "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
            ],
            [
               "string",
               "kernel.view"
            ],
            [
               "object",
               "Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
            ]
         ]
      },
      {
         "namespace":"Symfony\\Component\\EventDispatcher",
         "short_class":"EventDispatcher",
         "class":"Symfony\\Component\\EventDispatcher\\EventDispatcher",
         "type":"-\u003E",
         "function":"callListeners",
         "file":"\/app\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php",
         "line":56,
         "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"
                  ]
               ]
            ],
            [
               "string",
               "kernel.view"
            ],
            [
               "object",
               "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
            ]
         ]
      },
      {
         "namespace":"Symfony\\Component\\EventDispatcher",
         "short_class":"EventDispatcher",
         "class":"Symfony\\Component\\EventDispatcher\\EventDispatcher",
         "type":"-\u003E",
         "function":"dispatch",
         "file":"\/app\/vendor\/symfony\/event-dispatcher\/Debug\/TraceableEventDispatcher.php",
         "line":127,
         "args":[
            [
               "object",
               "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
            ],
            [
               "string",
               "kernel.view"
            ]
         ]
      },
      {
         "namespace":"Symfony\\Component\\EventDispatcher\\Debug",
         "short_class":"TraceableEventDispatcher",
         "class":"Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher",
         "type":"-\u003E",
         "function":"dispatch",
         "file":"\/app\/vendor\/symfony\/http-kernel\/HttpKernel.php",
         "line":168,
         "args":[
            [
               "object",
               "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
            ],
            [
               "string",
               "kernel.view"
            ]
         ]
      },
      {
         "namespace":"Symfony\\Component\\HttpKernel",
         "short_class":"HttpKernel",
         "class":"Symfony\\Component\\HttpKernel\\HttpKernel",
         "type":"-\u003E",
         "function":"handleRaw",
         "file":"\/app\/vendor\/symfony\/http-kernel\/HttpKernel.php",
         "line":74,
         "args":[
            [
               "object",
               "Symfony\\Component\\HttpFoundation\\Request"
            ],
            [
               "integer",
               1
            ]
         ]
      },
      {
         "namespace":"Symfony\\Component\\HttpKernel",
         "short_class":"HttpKernel",
         "class":"Symfony\\Component\\HttpKernel\\HttpKernel",
         "type":"-\u003E",
         "function":"handle",
         "file":"\/app\/vendor\/symfony\/http-kernel\/Kernel.php",
         "line":184,
         "args":[
            [
               "object",
               "Symfony\\Component\\HttpFoundation\\Request"
            ],
            [
               "integer",
               1
            ],
            [
               "boolean",
               true
            ]
         ]
      },
      {
         "namespace":"Symfony\\Component\\HttpKernel",
         "short_class":"Kernel",
         "class":"Symfony\\Component\\HttpKernel\\Kernel",
         "type":"-\u003E",
         "function":"handle",
         "file":"\/app\/vendor\/symfony\/runtime\/Runner\/Symfony\/HttpKernelRunner.php",
         "line":35,
         "args":[
            [
               "object",
               "Symfony\\Component\\HttpFoundation\\Request"
            ]
         ]
      },
      {
         "namespace":"Symfony\\Component\\Runtime\\Runner\\Symfony",
         "short_class":"HttpKernelRunner",
         "class":"Symfony\\Component\\Runtime\\Runner\\Symfony\\HttpKernelRunner",
         "type":"-\u003E",
         "function":"run",
         "file":"\/app\/vendor\/autoload_runtime.php",
         "line":29,
         "args":[
            
         ]
      },
      {
         "namespace":"",
         "short_class":"",
         "class":"",
         "type":"",
         "function":"require_once",
         "file":"\/app\/public\/index.php",
         "line":5,
         "args":[
            [
               "string",
               "\/app\/vendor\/autoload_runtime.php"
            ]
         ]
      }
   ]
}

Symfony serializer doesnt support graphql out of the box and their docs say that api platform comes bundled with one

ddruganov
  • 1,263
  • 13
  • 15

1 Answers1

1

Try this list of formats:

formats:
    jsonld: [ 'application/ld+json' ]
    graphql: ['application/graphql']
    jsonhal: [ 'application/hal+json' ]
    jsonapi: [ 'application/vnd.api+json' ]
    json: [ 'application/json' ]
    html: [ 'text/html' ]
    

patch_formats:
    json: [ 'application/merge-patch+json' ]
    jsonapi: [ 'application/vnd.api+json' ]

error_formats:
    jsonproblem: [ 'application/problem+json' ]
    jsonld: [ 'application/ld+json' ]      # Hydra error formats
    jsonapi: [ 'application/vnd.api+json' ]