Skip to content

Commit 3fd08eb

Browse files
authored
Allow extending SchemaPrinter by making its methods protected (#671)
This opens up a much needed escape hatch for experimental features such as Apollo Federation, see #552
1 parent 4d7302c commit 3fd08eb

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/Utils/SchemaPrinter.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static function ($type) : bool {
6363
/**
6464
* @param array<string, bool> $options
6565
*/
66-
private static function printFilteredSchema(Schema $schema, callable $directiveFilter, callable $typeFilter, array $options) : string
66+
protected static function printFilteredSchema(Schema $schema, callable $directiveFilter, callable $typeFilter, array $options) : string
6767
{
6868
$directives = array_filter($schema->getDirectives(), $directiveFilter);
6969

@@ -96,7 +96,7 @@ static function ($type) use ($options) : string {
9696
);
9797
}
9898

99-
private static function printSchemaDefinition(Schema $schema) : string
99+
protected static function printSchemaDefinition(Schema $schema) : string
100100
{
101101
if (self::isSchemaOfCommonNames($schema)) {
102102
return '';
@@ -134,7 +134,7 @@ private static function printSchemaDefinition(Schema $schema) : string
134134
*
135135
* When using this naming convention, the schema description can be omitted.
136136
*/
137-
private static function isSchemaOfCommonNames(Schema $schema) : bool
137+
protected static function isSchemaOfCommonNames(Schema $schema) : bool
138138
{
139139
$queryType = $schema->getQueryType();
140140
if ($queryType !== null && $queryType->name !== 'Query') {
@@ -154,7 +154,7 @@ private static function isSchemaOfCommonNames(Schema $schema) : bool
154154
/**
155155
* @param array<string, bool> $options
156156
*/
157-
private static function printDirective(Directive $directive, array $options) : string
157+
protected static function printDirective(Directive $directive, array $options) : string
158158
{
159159
return self::printDescription($options, $directive)
160160
. 'directive @' . $directive->name
@@ -166,7 +166,7 @@ private static function printDirective(Directive $directive, array $options) : s
166166
/**
167167
* @param array<string, bool> $options
168168
*/
169-
private static function printDescription(array $options, $def, $indentation = '', $firstInBlock = true) : string
169+
protected static function printDescription(array $options, $def, $indentation = '', $firstInBlock = true) : string
170170
{
171171
if (! $def->description) {
172172
return '';
@@ -213,7 +213,7 @@ private static function printDescription(array $options, $def, $indentation = ''
213213
/**
214214
* @return string[]
215215
*/
216-
private static function descriptionLines(string $description, int $maxLen) : array
216+
protected static function descriptionLines(string $description, int $maxLen) : array
217217
{
218218
$lines = [];
219219
$rawLines = explode("\n", $description);
@@ -236,7 +236,7 @@ private static function descriptionLines(string $description, int $maxLen) : arr
236236
/**
237237
* @return string[]
238238
*/
239-
private static function breakLine(string $line, int $maxLen) : array
239+
protected static function breakLine(string $line, int $maxLen) : array
240240
{
241241
if (strlen($line) < $maxLen + 5) {
242242
return [$line];
@@ -247,7 +247,7 @@ private static function breakLine(string $line, int $maxLen) : array
247247
return array_map('trim', $parts);
248248
}
249249

250-
private static function printDescriptionWithComments($lines, $indentation, $firstInBlock) : string
250+
protected static function printDescriptionWithComments($lines, $indentation, $firstInBlock) : string
251251
{
252252
$description = $indentation && ! $firstInBlock ? "\n" : '';
253253
foreach ($lines as $line) {
@@ -261,15 +261,15 @@ private static function printDescriptionWithComments($lines, $indentation, $firs
261261
return $description;
262262
}
263263

264-
private static function escapeQuote($line) : string
264+
protected static function escapeQuote($line) : string
265265
{
266266
return str_replace('"""', '\\"""', $line);
267267
}
268268

269269
/**
270270
* @param array<string, bool> $options
271271
*/
272-
private static function printArgs(array $options, $args, $indentation = '') : string
272+
protected static function printArgs(array $options, $args, $indentation = '') : string
273273
{
274274
if (! $args) {
275275
return '';
@@ -302,7 +302,7 @@ static function ($arg, $i) use ($indentation, $options) : string {
302302
);
303303
}
304304

305-
private static function printInputValue($arg) : string
305+
protected static function printInputValue($arg) : string
306306
{
307307
$argDecl = $arg->name . ': ' . (string) $arg->getType();
308308
if ($arg->defaultValueExists()) {
@@ -347,15 +347,15 @@ public static function printType(Type $type, array $options = []) : string
347347
/**
348348
* @param array<string, bool> $options
349349
*/
350-
private static function printScalar(ScalarType $type, array $options) : string
350+
protected static function printScalar(ScalarType $type, array $options) : string
351351
{
352352
return sprintf('%sscalar %s', self::printDescription($options, $type), $type->name);
353353
}
354354

355355
/**
356356
* @param array<string, bool> $options
357357
*/
358-
private static function printObject(ObjectType $type, array $options) : string
358+
protected static function printObject(ObjectType $type, array $options) : string
359359
{
360360
$interfaces = $type->getInterfaces();
361361
$implementedInterfaces = ! empty($interfaces)
@@ -377,7 +377,7 @@ static function (InterfaceType $interface) : string {
377377
/**
378378
* @param array<string, bool> $options
379379
*/
380-
private static function printFields(array $options, $type) : string
380+
protected static function printFields(array $options, $type) : string
381381
{
382382
$fields = array_values($type->getFields());
383383

@@ -395,7 +395,7 @@ static function ($f, $i) use ($options) : string {
395395
);
396396
}
397397

398-
private static function printDeprecated($fieldOrEnumVal) : string
398+
protected static function printDeprecated($fieldOrEnumVal) : string
399399
{
400400
$reason = $fieldOrEnumVal->deprecationReason;
401401
if ($reason === null) {
@@ -412,7 +412,7 @@ private static function printDeprecated($fieldOrEnumVal) : string
412412
/**
413413
* @param array<string, bool> $options
414414
*/
415-
private static function printInterface(InterfaceType $type, array $options) : string
415+
protected static function printInterface(InterfaceType $type, array $options) : string
416416
{
417417
return self::printDescription($options, $type) .
418418
sprintf("interface %s {\n%s\n}", $type->name, self::printFields($options, $type));
@@ -421,7 +421,7 @@ private static function printInterface(InterfaceType $type, array $options) : st
421421
/**
422422
* @param array<string, bool> $options
423423
*/
424-
private static function printUnion(UnionType $type, array $options) : string
424+
protected static function printUnion(UnionType $type, array $options) : string
425425
{
426426
return self::printDescription($options, $type) .
427427
sprintf('union %s = %s', $type->name, implode(' | ', $type->getTypes()));
@@ -430,7 +430,7 @@ private static function printUnion(UnionType $type, array $options) : string
430430
/**
431431
* @param array<string, bool> $options
432432
*/
433-
private static function printEnum(EnumType $type, array $options) : string
433+
protected static function printEnum(EnumType $type, array $options) : string
434434
{
435435
return self::printDescription($options, $type) .
436436
sprintf("enum %s {\n%s\n}", $type->name, self::printEnumValues($type->getValues(), $options));
@@ -439,7 +439,7 @@ private static function printEnum(EnumType $type, array $options) : string
439439
/**
440440
* @param array<string, bool> $options
441441
*/
442-
private static function printEnumValues($values, array $options) : string
442+
protected static function printEnumValues($values, array $options) : string
443443
{
444444
return implode(
445445
"\n",
@@ -457,7 +457,7 @@ static function ($value, $i) use ($options) : string {
457457
/**
458458
* @param array<string, bool> $options
459459
*/
460-
private static function printInputObject(InputObjectType $type, array $options) : string
460+
protected static function printInputObject(InputObjectType $type, array $options) : string
461461
{
462462
$fields = array_values($type->getFields());
463463

0 commit comments

Comments
 (0)