# GraphQL GraphQL 元件對 [thecodingmachine/graphqlite](https://github.com/thecodingmachine/graphqlite) 進行抽象。 ## 安裝 ```bash composer require hyperf/graphql ``` ## 快速開始 ### 簡單查詢 ```php getBody()->getContents(); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; return GraphQL::executeQuery($this->schema, $query, null, null, $variableValues)->toArray(); } #[Query] public function hello(string $name): string { return $name; } } ``` 查詢: ```graphql { hello(name: "graphql") } ``` 響應: ```json { "data": { "hello": "graphql" } } ``` ### 型別對映 ```php name = $name; $this->price = $price; } #[Field] public function getName(): string { return $this->name; } #[Field] public function getPrice(): ?float { return $this->price; } } ``` 在 `GraphQLController` 中加入 ```php