-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImprintQuery.php
More file actions
107 lines (98 loc) · 2.72 KB
/
ImprintQuery.php
File metadata and controls
107 lines (98 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace ThothApi\GraphQL\Queries;
class ImprintQuery extends AbstractQuery
{
public function getQuery(): string
{
return $this->buildQueryWithRestrictedFields(
<<<'GQL'
query($imprintId: Uuid!) {
imprint(imprintId: $imprintId) {
...imprintFields
}
}
GQL,
true
);
}
public function getManyQuery(): string
{
return $this->getManyQueryWithRestrictedFields(false);
}
public function getManyQueryWithRestrictedFields(bool $includeRestrictedFields = false): string
{
return $this->buildQueryWithRestrictedFields(
<<<'GQL'
query(
$limit: Int = 100
$offset: Int = 0
$filter: String = ""
$field: ImprintField = IMPRINT_NAME
$direction: Direction = ASC
$publishers: [Uuid!] = []
) {
imprints(
limit: $limit
offset: $offset
filter: $filter
order: {
field: $field
direction: $direction
}
publishers: $publishers
) {
...imprintFields
}
}
GQL,
$includeRestrictedFields
);
}
public function getCountQuery(): string
{
return <<<GQL
query(
\$filter: String = ""
\$publishers: [Uuid!] = []
) {
imprintCount(
filter: \$filter
publishers: \$publishers
)
}
GQL;
}
protected function getFieldsFragment(): string
{
return $this->getFieldsFragmentWithRestrictedFields(true);
}
protected function getFieldsFragmentWithRestrictedFields(bool $includeRestrictedFields = false): string
{
$restrictedFields = $includeRestrictedFields ? <<<GQL
s3Bucket
cdnDomain
cloudfrontDistId
GQL : '';
return <<<GQL
fragment imprintFields on Imprint {
imprintId
publisherId
imprintName
imprintUrl
crossmarkDoi
{$restrictedFields}
defaultCurrency
defaultPlace
defaultLocale
}
GQL;
}
private function buildQueryWithRestrictedFields(string $queryBody, bool $includeRestrictedFields): string
{
$fragment = $this->getFieldsFragmentWithRestrictedFields($includeRestrictedFields);
return <<<GQL
{$queryBody}
{$fragment}
GQL;
}
}