30
30
trait GraphQLQueryBuilder
31
31
{
32
32
private array $ selectedFields = [];
33
+
34
+ /**
35
+ * Get available query fields
36
+ *
37
+ * @return array Array of available field names
38
+ */
33
39
abstract protected function getQueryFields (): array ;
40
+
41
+ /**
42
+ * Get the GraphQL query name
43
+ *
44
+ * @return string The query name
45
+ */
34
46
abstract protected function getQueryName (): string ;
47
+
48
+ /**
49
+ * Get the GraphQL operation name
50
+ *
51
+ * @return string The operation name
52
+ */
35
53
abstract protected function getOperationName (): string ;
36
54
55
+ /**
56
+ * Select specific fields for the GraphQL query
57
+ *
58
+ * @param string ...$fields The field names to select
59
+ *
60
+ * @return self Returns the current instance for method chaining
61
+ *
62
+ * @throws ParameterException When invalid fields are provided
63
+ */
37
64
public function select (string ...$ fields ): self
38
65
{
39
66
$ queryFields = $ this ->getQueryFields ();
@@ -50,6 +77,11 @@ public function select(string ...$fields): self
50
77
return $ this ;
51
78
}
52
79
80
+ /**
81
+ * Convert the query to a GraphQL query string
82
+ *
83
+ * @return string The formatted GraphQL query string
84
+ */
53
85
public function toGraphQLQueryString (): string
54
86
{
55
87
$ fields = empty ($ this ->selectedFields )
@@ -67,8 +99,13 @@ public function toGraphQLQueryString(): string
67
99
);
68
100
}
69
101
102
+ /**
103
+ * Get selected properties as GraphQL fields
104
+ *
105
+ * @return array Array of field names
106
+ */
70
107
private function getSelectedPropertiesAsFields (): array
71
108
{
72
109
return $ this ->getQueryFields ();
73
110
}
74
- }
111
+ }
0 commit comments