Skip to content

Commit bf4ec02

Browse files
committed
Allow extending SchemaPrinter by making its methods protected
This opens up a much needed escape hatch for experimental features such as Apollo Federation, see #552
1 parent a747575 commit bf4ec02

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
@@ -62,7 +62,7 @@ static function ($type) : bool {
6262
/**
6363
* @param array<string, bool> $options
6464
*/
65-
private static function printFilteredSchema(Schema $schema, callable $directiveFilter, callable $typeFilter, array $options) : string
65+
protected static function printFilteredSchema(Schema $schema, callable $directiveFilter, callable $typeFilter, array $options) : string
6666
{
6767
$directives = array_filter($schema->getDirectives(), $directiveFilter);
6868

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

98-
private static function printSchemaDefinition(Schema $schema) : string
98+
protected static function printSchemaDefinition(Schema $schema) : string
9999
{
100100
if (self::isSchemaOfCommonNames($schema)) {
101101
return '';
@@ -133,7 +133,7 @@ private static function printSchemaDefinition(Schema $schema) : string
133133
*
134134
* When using this naming convention, the schema description can be omitted.
135135
*/
136-
private static function isSchemaOfCommonNames(Schema $schema) : bool
136+
protected static function isSchemaOfCommonNames(Schema $schema) : bool
137137
{
138138
$queryType = $schema->getQueryType();
139139
if ($queryType !== null && $queryType->name !== 'Query') {
@@ -153,7 +153,7 @@ private static function isSchemaOfCommonNames(Schema $schema) : bool
153153
/**
154154
* @param array<string, bool> $options
155155
*/
156-
private static function printDirective(Directive $directive, array $options) : string
156+
protected static function printDirective(Directive $directive, array $options) : string
157157
{
158158
return self::printDescription($options, $directive)
159159
. 'directive @' . $directive->name
@@ -165,7 +165,7 @@ private static function printDirective(Directive $directive, array $options) : s
165165
/**
166166
* @param array<string, bool> $options
167167
*/
168-
private static function printDescription(array $options, $def, $indentation = '', $firstInBlock = true) : string
168+
protected static function printDescription(array $options, $def, $indentation = '', $firstInBlock = true) : string
169169
{
170170
if (! $def->description) {
171171
return '';
@@ -212,7 +212,7 @@ private static function printDescription(array $options, $def, $indentation = ''
212212
/**
213213
* @return string[]
214214
*/
215-
private static function descriptionLines(string $description, int $maxLen) : array
215+
protected static function descriptionLines(string $description, int $maxLen) : array
216216
{
217217
$lines = [];
218218
$rawLines = explode("\n", $description);
@@ -235,7 +235,7 @@ private static function descriptionLines(string $description, int $maxLen) : arr
235235
/**
236236
* @return string[]
237237
*/
238-
private static function breakLine(string $line, int $maxLen) : array
238+
protected static function breakLine(string $line, int $maxLen) : array
239239
{
240240
if (strlen($line) < $maxLen + 5) {
241241
return [$line];
@@ -246,7 +246,7 @@ private static function breakLine(string $line, int $maxLen) : array
246246
return array_map('trim', $parts);
247247
}
248248

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

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

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

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

354354
/**
355355
* @param array<string, bool> $options
356356
*/
357-
private static function printObject(ObjectType $type, array $options) : string
357+
protected static function printObject(ObjectType $type, array $options) : string
358358
{
359359
$interfaces = $type->getInterfaces();
360360
$implementedInterfaces = ! empty($interfaces)
@@ -376,7 +376,7 @@ static function (InterfaceType $interface) : string {
376376
/**
377377
* @param array<string, bool> $options
378378
*/
379-
private static function printFields(array $options, $type) : string
379+
protected static function printFields(array $options, $type) : string
380380
{
381381
$fields = array_values($type->getFields());
382382

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

397-
private static function printDeprecated($fieldOrEnumVal) : string
397+
protected static function printDeprecated($fieldOrEnumVal) : string
398398
{
399399
$reason = $fieldOrEnumVal->deprecationReason;
400400
if ($reason === null) {
@@ -411,7 +411,7 @@ private static function printDeprecated($fieldOrEnumVal) : string
411411
/**
412412
* @param array<string, bool> $options
413413
*/
414-
private static function printInterface(InterfaceType $type, array $options) : string
414+
protected static function printInterface(InterfaceType $type, array $options) : string
415415
{
416416
return self::printDescription($options, $type) .
417417
sprintf("interface %s {\n%s\n}", $type->name, self::printFields($options, $type));
@@ -420,7 +420,7 @@ private static function printInterface(InterfaceType $type, array $options) : st
420420
/**
421421
* @param array<string, bool> $options
422422
*/
423-
private static function printUnion(UnionType $type, array $options) : string
423+
protected static function printUnion(UnionType $type, array $options) : string
424424
{
425425
return self::printDescription($options, $type) .
426426
sprintf('union %s = %s', $type->name, implode(' | ', $type->getTypes()));
@@ -429,7 +429,7 @@ private static function printUnion(UnionType $type, array $options) : string
429429
/**
430430
* @param array<string, bool> $options
431431
*/
432-
private static function printEnum(EnumType $type, array $options) : string
432+
protected static function printEnum(EnumType $type, array $options) : string
433433
{
434434
return self::printDescription($options, $type) .
435435
sprintf("enum %s {\n%s\n}", $type->name, self::printEnumValues($type->getValues(), $options));
@@ -438,7 +438,7 @@ private static function printEnum(EnumType $type, array $options) : string
438438
/**
439439
* @param array<string, bool> $options
440440
*/
441-
private static function printEnumValues($values, array $options) : string
441+
protected static function printEnumValues($values, array $options) : string
442442
{
443443
return implode(
444444
"\n",
@@ -456,7 +456,7 @@ static function ($value, $i) use ($options) : string {
456456
/**
457457
* @param array<string, bool> $options
458458
*/
459-
private static function printInputObject(InputObjectType $type, array $options) : string
459+
protected static function printInputObject(InputObjectType $type, array $options) : string
460460
{
461461
$fields = array_values($type->getFields());
462462

0 commit comments

Comments
 (0)