{"id":18486104,"url":"https://github.com/mathsgod/gql-query-builder-php","last_synced_at":"2025-07-07T13:36:46.115Z","repository":{"id":149998149,"uuid":"621761035","full_name":"mathsgod/gql-query-builder-php","owner":"mathsgod","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-19T03:15:18.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-18T07:18:40.571Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathsgod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-31T10:27:45.000Z","updated_at":"2023-04-03T08:55:07.000Z","dependencies_parsed_at":"2024-11-06T12:52:05.474Z","dependency_job_id":"7faebe13-e11d-4864-ab37-d4f3518249b0","html_url":"https://github.com/mathsgod/gql-query-builder-php","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fgql-query-builder-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fgql-query-builder-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fgql-query-builder-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fgql-query-builder-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathsgod","download_url":"https://codeload.github.com/mathsgod/gql-query-builder-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254036843,"owners_count":22003654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T12:47:52.206Z","updated_at":"2025-05-13T22:12:54.362Z","avatar_url":"https://github.com/mathsgod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL Query Builder for PHP\n\n[![PHP Composer](https://github.com/mathsgod/gql-query-builder-php/actions/workflows/php.yml/badge.svg)](https://github.com/mathsgod/gql-query-builder-php/actions/workflows/php.yml)\n\nA simple helper function to build GraphQL queries, mutations and subscriptions use PHP.\n\nThis project is based on [GraphQL Query Builder](https://www.npmjs.com/package/gql-query-builder) for Node.js.\n\n## Install\n\n`composer require mathsgod/gql-query-builder-php`\n\n## Usage\n\n```php\nuse function GQLQueryBuilder\\query;\nuse function GQLQueryBuilder\\mutation;\nuse function GQLQueryBuilder\\subscription;\n\n$query=query($options);\n$mutation=mutation($options);\n$subscription=subscription($options);\n```\n\n## Options\n   \n`options is [\"operation\",\"field\",\"variables\"] or an array of options`\n\n### Examples\n1. \u003ca href=\"#query\"\u003eQuery\u003c/a\u003e\n2. \u003ca href=\"#query-with-variables\"\u003eQuery (with variables)\u003c/a\u003e\n3. \u003ca href=\"#query-with-nested-fields-selection\"\u003eQuery (with nested fields selection)\u003c/a\u003e\n4. \u003ca href=\"#query-with-custom-argument-name\"\u003eQuery (with custom argument name)\u003c/a\u003e\n5. \u003ca href=#query-with-required-variables\u003eQuery (with required variables)\u003c/a\u003e\n6. \u003ca href=\"#query-with-empty-fields\"\u003eQuery (with empty fields)\u003c/a\u003e\n7. \u003ca href=\"#mutation\"\u003eMutation\u003c/a\u003e\n8. \u003ca href=\"#mutation-with-required-variables\"\u003eMutation (with required variables)\u003c/a\u003e\n9. \u003ca href=\"#subscription\"\u003eSubscription\u003c/a\u003e\n\n#### Query:\n\n```php\n$query=query([\n    \"operation\"=\u003e\"thoughts\",\n    \"fields\"=\u003e['id', 'name', 'thought']\n]);\n\nprint_r($query);\n\n// output:\n/*\nArray\n(\n    [query] =\u003e query { thoughts { id name thought } }\n    [variables] =\u003e Array\n        (\n        )\n)\n*/\n```\n\n\n\n#### Query (with variables):\n\n```php\n$query=query([\n    \"operation\"=\u003e\"thoughts\",\n    \"fields\"=\u003e['id', 'name', 'thought'],\n    \"variables\"=\u003e[\n        \"id\"=\u003e1,\n    ]\n]);\n\nprint_r($query);\n\n// output:\n/*\nArray\n(\n    [query] =\u003e query ($id: Int) { thoughts(id: $id) { id name thought } }\n    [variables] =\u003e Array\n        (\n            [id] =\u003e 1\n        )\n)\n*/\n```\n\n#### Query (with nested fields selection):\n    \n```php\n$query = query([\n    \"operation\" =\u003e \"orders\",\n    \"fields\" =\u003e [\n        \"id\",\n        \"amount\",\n        \"user\" =\u003e [\n            \"id\",\n            \"name\",\n            \"email\",\n            \"address\" =\u003e [\n                \"city\",\n                \"country\",\n            ]\n        ]\n    ]\n]);\n\n// output:\n/*\nArray\n(\n    [query] =\u003e query { orders { id, amount, user { id, name, email, address { city, country } } } }\n    [variables] =\u003e Array\n        (\n        )\n\n)\n*/\n```\n\n#### Query (with custom argument name):\n\n```php\n$query = query([\n    \"operation\" =\u003e \"someoperation\",\n    \"fields\" =\u003e [\n        [\n            \"operation\" =\u003e \"nestedoperation\",\n            \"fields\" =\u003e ['field1'],\n            \"variables\" =\u003e [\n                \"id2\" =\u003e [\n                    \"name\" =\u003e \"id\",\n                    \"type\" =\u003e \"ID\",\n                    \"value\" =\u003e 123\n                ]\n            ],\n        ]\n    ],\n    \"variables\" =\u003e [\n        \"id\" =\u003e [\n            \"name\" =\u003e \"id\",\n            \"type\" =\u003e \"ID\",\n            \"value\" =\u003e 456\n        ]\n    ]\n]);\n\n/*\nArray\n(\n    [query] =\u003e query($id: ID, $id2: ID) { someoperation(id: $id) { nestedoperation (id: $id2)  { field1 }  } }\n    [variables] =\u003e Array\n        (\n            [id] =\u003e 456\n            [id2] =\u003e 123\n        )\n\n)\n*/\n```\n\n#### Query (with required variables)\n```php\n\n$query=query([\n    \"operation\"=\u003e\"userLogin\",\n    \"variables\"=\u003e[\n        \"email\"=\u003e[\n            \"value\"=\u003e\"jon.doe@example.com\",\n            \"required\"=\u003etrue\n        ],\n        \"password\"=\u003e[\n            \"value\"=\u003e\"123456\",\n            \"required\"=\u003etrue\n        ]\n    ],\n    \"fields\"=\u003e[\"userId\",\"token\"]\n]);\n\n/*\n\nArray\n(\n    [query] =\u003e query($email: String!, $password: String!) { userLogin(email: $email, password: $password) { userId, token } }\n    [variables] =\u003e Array\n        (\n            [email] =\u003e jon.doe@example.com\n            [password] =\u003e 123456\n        )\n\n)\n\n*/\n```\n\n\n\n#### Query (with empty fields):\n\n```php\n$query = query([\n    [\n        \"operation\" =\u003e \"getFilteredUsersCount\",\n    ],\n    [\n        \"operation\" =\u003e \"getAllUsersCount\",\n        \"fields\" =\u003e []\n    ],\n    [\n        \"operation\" =\u003e \"getFilteredUsers\",\n        \"fields\" =\u003e [\n            \"count\" =\u003e []\n        ]\n    ]\n]);\n\nprint_r($query);\n\n/*\nArray\n(\n    [query] =\u003e query { getFilteredUsersCount getAllUsersCount getFilteredUsers { count } }\n    [variables] =\u003e Array\n        (\n        )\n\n)\n*/\n```\n\n#### Mutation:\n\n```php\n\n$mutation=mutation([\n    \"operation\"=\u003e\"createThought\",\n    \"variables\"=\u003e[\n        \"name\"=\u003e\"John Doe\",\n        \"thought\"=\u003e\"Hello World\"\n    ],\n    \"fields\"=\u003e[\"id\",\"name\",\"thought\"]\n]);\n\nprint_r($mutation);\n\n/*\n\nArray\n(\n    [query] =\u003e mutation($name: String, $thought: String) { createThought(name: $name, thought: $thought) { id name thought } }\n    [variables] =\u003e Array\n        (\n            [name] =\u003e John Doe\n            [thought] =\u003e Hello World\n        )\n\n)\n\n*/\n```\n\n\n#### Mutation (with required variables):\n\n```php\n$query = mutation([\n    \"operation\" =\u003e \"userSignup\",\n    \"variables\" =\u003e [\n        \"name\" =\u003e [\n            \"value\" =\u003e \"Jon Doe\",\n        ],\n        \"email\" =\u003e [\n            \"value\" =\u003e \"jon.doe@example.com\", \"required\" =\u003e true\n        ],\n        \"password\" =\u003e [\n            \"value\" =\u003e \"123456\", \"required\" =\u003e true\n        ],\n    ],\n    \"fields\" =\u003e [\"userId\"]\n]);\n\nprint_r($query);\n\n/*\n\nArray\n(\n    [query] =\u003e mutation($name: String, $email: String!, $password: String!) { userSignup(name: $name, email: $email, password: $password) { userId } }\n    [variables] =\u003e Array\n        (\n            [name] =\u003e Jon Doe\n            [email] =\u003e jon.doe@example.com\n            [password] =\u003e 123456\n        )\n)\n    \n*/\n```\n\n#### Subscription:\n\n```php\n\n$query = subscription([\n    \"operation\" =\u003e \"thoughtCreate\",\n    \"variables\" =\u003e [\n        \"name\" =\u003e \"Tyrion Lannister\",\n        \"thought\" =\u003e \"I drink and I know things.\"\n    ],\n    \"fields\" =\u003e [\"id\"]\n]);\n\nprint_r($query);\n\n/*\n\nArray\n(\n    [query] =\u003e subscription($name: String, $thought: String) { thoughtCreate(name: $name, thought: $thought) { id } }\n    [variables] =\u003e Array\n        (\n            [name] =\u003e Tyrion Lannister\n            [thought] =\u003e I drink and I know things.\n        )\n)\n    \n*/\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Fgql-query-builder-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathsgod%2Fgql-query-builder-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Fgql-query-builder-php/lists"}