{"id":15192392,"url":"https://github.com/ilyamatsuev/apex-graphql-client","last_synced_at":"2025-10-27T17:30:27.700Z","repository":{"id":40450319,"uuid":"382231660","full_name":"IlyaMatsuev/Apex-GraphQL-Client","owner":"IlyaMatsuev","description":"The package for Salesforce that provides a convenient way to communicate with a GraphQL server via Apex.","archived":false,"fork":false,"pushed_at":"2024-12-23T16:02:40.000Z","size":485,"stargazers_count":41,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-01T07:13:15.202Z","etag":null,"topics":["apex","graphql","graphql-client","library","salesforce"],"latest_commit_sha":null,"homepage":"","language":"Apex","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/IlyaMatsuev.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}},"created_at":"2021-07-02T04:40:01.000Z","updated_at":"2025-01-07T13:05:13.000Z","dependencies_parsed_at":"2024-03-11T22:55:49.218Z","dependency_job_id":null,"html_url":"https://github.com/IlyaMatsuev/Apex-GraphQL-Client","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IlyaMatsuev%2FApex-GraphQL-Client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IlyaMatsuev%2FApex-GraphQL-Client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IlyaMatsuev%2FApex-GraphQL-Client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IlyaMatsuev%2FApex-GraphQL-Client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IlyaMatsuev","download_url":"https://codeload.github.com/IlyaMatsuev/Apex-GraphQL-Client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238527216,"owners_count":19487177,"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":["apex","graphql","graphql-client","library","salesforce"],"created_at":"2024-09-27T21:23:10.519Z","updated_at":"2025-10-14T12:10:15.635Z","avatar_url":"https://github.com/IlyaMatsuev.png","language":"Apex","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Saleforce Apex GraphQL Client\n\n[![CI](https://github.com/IlyaMatsuev/Apex-GraphQL-Client/actions/workflows/scratch-test.yml/badge.svg?branch=main)](https://github.com/IlyaMatsuev/Apex-GraphQL-Client/actions/workflows/scratch-test.yml)\n[![codecov](https://codecov.io/gh/IlyaMatsuev/Apex-GraphQL-Client/branch/main/graph/badge.svg?token=ZOSPAKZTGC)](https://codecov.io/gh/IlyaMatsuev/Apex-GraphQL-Client)\n\nThe package for Salesforce that aimed to provide a convenient way to communicate with a GraphQL server via Apex.\n\nWhat is supported:\n\n-   ✅ Building queries, mutations and subscriptions\n-   ✅ Building graphql nodes (fields). If you want to send requests yourself\n-   ✅ Passing arguments to the graphql nodes (fields)\n-   ✅ Passing variables to the graphql operations from request\n-   ✅ Passing directives to the graphql operations and nodes\n-   ✅ Using fragments for graphql requests. Inline fragments are supported as well.\n-   ✅ Sync and async graphql HTTP client for sending requests (with callback implementation for async calls)\n-   ✅ Handling responses in GraphQL format\n\nWhat is NOT supported:\n\n-   ❌ Sending subscription requests (WebSocket protocol is not supported by Apex)\n\nIf you think there is something that is not implemented yet as for GraphQL client I'd appreciate if you open an issue/discussion in this repository.\n\n## 🔍 Overview\n\n### Generate a GraphQL node\n\nGraphQL node statement:\n\n```bash\ncontinents {\n  name\n  countries {\n    name\n    capital\n    currency\n  }\n}\n```\n\nEquivalent Apex code:\n\n```java\nGraphQLField continents = new GraphQLField('continents')\n    .withField('name')\n    .withField(new GraphQLField(\n        'countries',\n        new List\u003cString\u003e { 'name', 'capital', 'currency' }\n    ));\n\n// Will print a well-formatted node just like on the example above\nSystem.debug(continents.build(true));\n```\n\n### Create a query GraphQL request\n\nGraphQL query statement:\n\n```bash\nquery {\n  countries(filter: \"Bel\", count: 1) {\n    name\n    capital\n    currency\n  }\n  continents {\n    name\n  }\n}\n```\n\nEquivalent Apex code:\n\n```java\nGraphQLField countries = new GraphQLField(\n    'countries',\n    new List\u003cString\u003e { 'name', 'capital', 'currency' }\n)\n    .withArgument('filter', 'Bel')\n    .withArgument('count', 1);\n\nGraphQLField continents = new GraphQLField(\n    'continents',\n    new List\u003cString\u003e { 'name' }\n);\n\nGraphQLQuery query = new GraphQLQuery(\n    new List\u003cGraphQLField\u003e { countries, continents }\n);\n\nSystem.debug(query.build(true));\n```\n\nAfter you created a query or mutation you can send it to the GraphQL endpoint:\n\n```java\n...\nGraphQLRequest request = query.asRequest();\n\n// Add custom header if needed\nrequest.withHeader('Authorization', 'Bearer token');\n\n// Provide a GraphQL endpoint to the client\nGraphQLHttpClient client = new GraphQLHttpClient('https://gql-endpoint.com/graphql');\n\nGraphQLResponse response = client.send(request);\n\n// Check if there are any errors and data\nSystem.debug(response.hasErrors());\nSystem.debug(response.hasData());\n\nList\u003cGraphQLResponseError\u003e errors = response.getErrors();\nMap\u003cString, Object\u003e dataAsMap = response.getData();\n// It's also possible to get data as any Apex class type\nSomeWrapper dataAsWrapper = (SomeWrapper) response.getDataAs(SomeWrapper.class);\n```\n\nAlternatively, sometimes it's easier to just send a request as a plain string, so you can do:\n\n```java\nString query = 'query { countries { name, capital, currency } }';\n\nGraphQLRequest request = new GraphQLRequest(query);\n\n// Provide a GraphQL endpoint to the client\nGraphQLHttpClient client = new GraphQLHttpClient('https://gql-endpoint.com/graphql');\n\nGraphQLResponse response = client.send(request);\n\n...\n```\n\nAll examples can be found [here](docs/examples/).\n\n## 🚀 Installation\n\n### From Unmanaged Package\n\nYou can just install the package by the link on a [sandbox](http://test.salesforce.com/packaging/installPackage.apexp?p0=04t7R000000FE1lQAG) or [dev org](http://login.salesforce.com/packaging/installPackage.apexp?p0=04t7R000000FE1lQAG).\n\nIf you prefer using salesforce CLI you can simply run:\n\n```bash\nsf package:install -p 04t7R000000FE1lQAG -w 10 -b 10 -o \u003cusername\u003e\n```\n\n### From Source\n\nYou can also install the package with the automated scripts: [`pkg-deploy.sh`](scripts/pkg-deploy.sh) and [`pkg-from-scratch.sh`](scripts/pkg-from-scratch.sh). First is for deploying changes to the existing org:\n\n```bash\n./scripts/pkg-deploy.sh \u003cusername\u003e\n```\n\nSecond is for creating a new configured scratch org:\n\n```bash\n./scripts/pkg-from-scratch.sh \u003cdevhub_username\u003e \u003cscratch_username\u003e\n```\n\n## 📝 Documentation\n\nFor more detailed information about the content of the repository and the package, please visit [the documentation page](https://ilyamatsuev.github.io/Apex-GraphQL-Client/).\n\nThere is also a nice article on [medium.com](https://medium.com/@justin.wills_27437/intro-to-graphql-in-apex-salesforce-ccedb514d3c5) by [Justin Wills](https://medium.com/@justin.wills_27437) about how to use this library with the Shopify integration. He has also posted [a video on YouTube](https://www.youtube.com/watch?v=KfooQmDCGnk\u0026t=6s) for the same topic.\n\nThe changelog is [here](https://ilyamatsuev.github.io/Apex-GraphQL-Client/#/changelog).\n\n## ❓ Questions\n\nIf you have any questions you can start a discussion. If you think something works not as expected you can create an issue. If you want to request a new feature you can create an issue with the appropriate template selected.\n\n## 🤝 Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\nPlease make sure to update tests as appropriate.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyamatsuev%2Fapex-graphql-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filyamatsuev%2Fapex-graphql-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyamatsuev%2Fapex-graphql-client/lists"}