mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 14:26:08 +03:00
Printer: created special function to add descriptions
This commit is contained in:
parent
ccb9486d21
commit
d9aee43129
@ -200,95 +200,68 @@ class Printer
|
||||
return $def->operation . ': ' . $def->type;
|
||||
},
|
||||
|
||||
NodeKind::SCALAR_TYPE_DEFINITION => function(ScalarTypeDefinitionNode $def) {
|
||||
NodeKind::SCALAR_TYPE_DEFINITION => $this->addDescription(function(ScalarTypeDefinitionNode $def) {
|
||||
return $this->join(['scalar', $def->name, $this->join($def->directives, ' ')], ' ');
|
||||
}),
|
||||
NodeKind::OBJECT_TYPE_DEFINITION => $this->addDescription(function(ObjectTypeDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$this->join(['scalar', $def->name, $this->join($def->directives, ' ')], ' ')
|
||||
], "\n");
|
||||
},
|
||||
NodeKind::OBJECT_TYPE_DEFINITION => function(ObjectTypeDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$this->join([
|
||||
'type',
|
||||
$def->name,
|
||||
$this->wrap('implements ', $this->join($def->interfaces, ' & ')),
|
||||
$this->join($def->directives, ' '),
|
||||
$this->block($def->fields)
|
||||
], ' ')
|
||||
], "\n");
|
||||
},
|
||||
NodeKind::FIELD_DEFINITION => function(FieldDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$def->name
|
||||
], ' ');
|
||||
}),
|
||||
NodeKind::FIELD_DEFINITION => $this->addDescription(function(FieldDefinitionNode $def) {
|
||||
return $def->name
|
||||
. $this->wrap('(', $this->join($def->arguments, ', '), ')')
|
||||
. ': ' . $def->type
|
||||
. $this->wrap(' ', $this->join($def->directives, ' '))
|
||||
], "\n");
|
||||
},
|
||||
NodeKind::INPUT_VALUE_DEFINITION => function(InputValueDefinitionNode $def) {
|
||||
. $this->wrap(' ', $this->join($def->directives, ' '));
|
||||
}),
|
||||
NodeKind::INPUT_VALUE_DEFINITION => $this->addDescription(function(InputValueDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$this->join([
|
||||
$def->name . ': ' . $def->type,
|
||||
$this->wrap('= ', $def->defaultValue),
|
||||
$this->join($def->directives, ' ')
|
||||
], ' ')
|
||||
], "\n");
|
||||
},
|
||||
NodeKind::INTERFACE_TYPE_DEFINITION => function(InterfaceTypeDefinitionNode $def) {
|
||||
], ' ');
|
||||
}),
|
||||
NodeKind::INTERFACE_TYPE_DEFINITION => $this->addDescription(function(InterfaceTypeDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$this->join([
|
||||
'interface',
|
||||
$def->name,
|
||||
$this->join($def->directives, ' '),
|
||||
$this->block($def->fields)
|
||||
], ' ')
|
||||
], "\n");
|
||||
},
|
||||
NodeKind::UNION_TYPE_DEFINITION => function(UnionTypeDefinitionNode $def) {
|
||||
], ' ');
|
||||
}),
|
||||
NodeKind::UNION_TYPE_DEFINITION => $this->addDescription(function(UnionTypeDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$this->join([
|
||||
'union',
|
||||
$def->name,
|
||||
$this->join($def->directives, ' '),
|
||||
$def->types
|
||||
? '= ' . $this->join($def->types, ' | ')
|
||||
: ''
|
||||
], ' ')
|
||||
], "\n");
|
||||
},
|
||||
NodeKind::ENUM_TYPE_DEFINITION => function(EnumTypeDefinitionNode $def) {
|
||||
], ' ');
|
||||
}),
|
||||
NodeKind::ENUM_TYPE_DEFINITION => $this->addDescription(function(EnumTypeDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$this->join([
|
||||
'enum',
|
||||
$def->name,
|
||||
$this->join($def->directives, ' '),
|
||||
$this->block($def->values)
|
||||
], ' ')
|
||||
], "\n");
|
||||
},
|
||||
NodeKind::ENUM_VALUE_DEFINITION => function(EnumValueDefinitionNode $def) {
|
||||
], ' ');
|
||||
}),
|
||||
NodeKind::ENUM_VALUE_DEFINITION => $this->addDescription(function(EnumValueDefinitionNode $def) {
|
||||
return $this->join([$def->name, $this->join($def->directives, ' ')], ' ');
|
||||
}),
|
||||
NodeKind::INPUT_OBJECT_TYPE_DEFINITION => $this->addDescription(function(InputObjectTypeDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$this->join([$def->name, $this->join($def->directives, ' ')], ' ')
|
||||
], "\n");
|
||||
},
|
||||
NodeKind::INPUT_OBJECT_TYPE_DEFINITION => function(InputObjectTypeDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
$this->join([
|
||||
'input',
|
||||
$def->name,
|
||||
$this->join($def->directives, ' '),
|
||||
$this->block($def->fields)
|
||||
], ' ')
|
||||
], "\n");
|
||||
},
|
||||
], ' ');
|
||||
}),
|
||||
NodeKind::SCALAR_TYPE_EXTENSION => function(ScalarTypeExtensionNode $def) {
|
||||
return $this->join([
|
||||
'extend scalar',
|
||||
@ -339,17 +312,23 @@ class Printer
|
||||
$this->block($def->fields),
|
||||
], ' ');
|
||||
},
|
||||
NodeKind::DIRECTIVE_DEFINITION => function(DirectiveDefinitionNode $def) {
|
||||
return $this->join([
|
||||
$def->description,
|
||||
'directive @' . $def->name . $this->wrap('(', $this->join($def->arguments, ', '), ')')
|
||||
. ' on ' . $this->join($def->locations, ' | ')
|
||||
], "\n");
|
||||
}
|
||||
NodeKind::DIRECTIVE_DEFINITION => $this->addDescription(function(DirectiveDefinitionNode $def) {
|
||||
return 'directive @'
|
||||
. $def->name
|
||||
. $this->wrap('(', $this->join($def->arguments, ', '), ')')
|
||||
. ' on ' . $this->join($def->locations, ' | ');
|
||||
})
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function addDescription(\Closure $cb)
|
||||
{
|
||||
return function ($node) use ($cb) {
|
||||
return $this->join([$node->description, $cb($node)]);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* If maybeString is not null or empty, then wrap with start and end, otherwise
|
||||
* print an empty string.
|
||||
|
Loading…
Reference in New Issue
Block a user