Skip to content

Commit

Permalink
fix(symfony): force json format with GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 17, 2023
1 parent dbd4f64 commit 05363d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public function load(array $configs, ContainerBuilder $container): void
$errorFormats['json'] = ['application/problem+json', 'application/json'];
}

if ($this->isConfigEnabled($container, $config['graphql']) && !isset($formats['json'])) {
trigger_deprecation('api-platform/core', '3.2', 'Add the "json" format to the configuration to use GraphQL.');
$formats['json'] = ['application/json'];
}

// Backward Compatibility layer
if (isset($formats['jsonapi']) && !isset($patchFormats['jsonapi'])) {
$patchFormats['jsonapi'] = ['application/vnd.api+json'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ApiPlatformExtensionTest extends TestCase
'description' => 'description',
'version' => 'version',
'formats' => [
'json' => ['mime_types' => ['json']],
'jsonld' => ['mime_types' => ['application/ld+json']],
'jsonhal' => ['mime_types' => ['application/hal+json']],
],
Expand Down Expand Up @@ -1260,4 +1261,17 @@ public function testHasClassMetadataCache(): void

$this->assertFalse($this->container->hasDefinition('api_platform.serializer.mapping.cache_class_metadata_factory'));
}

/**
* @group legacy
*/
public function testLegacyGraphQlConfigurationWithoutJsonFormat(): void
{
$this->expectDeprecation('Since api-platform/core 3.2: Add the "json" format to the configuration to use GraphQL.');
$config = self::DEFAULT_CONFIG;
unset($config['api_platform']['formats']['json']);

(new ApiPlatformExtension())->load($config, $this->container);
$this->assertArrayHasKey('json', $this->container->getParameter('api_platform.formats'));
}
}

0 comments on commit 05363d9

Please sign in to comment.