{"id":14976088,"url":"https://github.com/jacobmountain/graphql-java-client","last_synced_at":"2026-01-18T06:11:00.117Z","repository":{"id":37886022,"uuid":"304955949","full_name":"JacobMountain/graphql-java-client","owner":"JacobMountain","description":"A Java GraphQL client annotation processor, generate a client class from a GraphQL schema file, and a Java interface","archived":false,"fork":false,"pushed_at":"2023-03-06T03:57:57.000Z","size":465,"stargazers_count":1,"open_issues_count":14,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-02-10T03:14:52.956Z","etag":null,"topics":["annotation","annotation-processing","annotation-processor","code-generation","graphql","graphql-client","graphql-schema","java","java-8","java-interface"],"latest_commit_sha":null,"homepage":"https://jacobmountain.github.io/graphql-java-client/#/","language":"Java","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/JacobMountain.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":"2020-10-17T19:42:23.000Z","updated_at":"2021-03-14T21:17:07.000Z","dependencies_parsed_at":"2024-09-27T21:50:33.353Z","dependency_job_id":null,"html_url":"https://github.com/JacobMountain/graphql-java-client","commit_stats":{"total_commits":134,"total_committers":3,"mean_commits":"44.666666666666664","dds":0.4776119402985075,"last_synced_commit":"575827b0b1617d7304a787633cb9f7c496ee71c3"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobMountain%2Fgraphql-java-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobMountain%2Fgraphql-java-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobMountain%2Fgraphql-java-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobMountain%2Fgraphql-java-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JacobMountain","download_url":"https://codeload.github.com/JacobMountain/graphql-java-client/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226196,"owners_count":20904465,"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":["annotation","annotation-processing","annotation-processor","code-generation","graphql","graphql-client","graphql-schema","java","java-8","java-interface"],"created_at":"2024-09-24T13:53:17.034Z","updated_at":"2026-01-18T06:11:00.098Z","avatar_url":"https://github.com/JacobMountain.png","language":"Java","readme":"# graphql-client ![Build + Test](https://github.com/JacobMountain/graphql-client/workflows/Build%20+%20Test/badge.svg) [![Documentation](https://img.shields.io/badge/read%20the-docs-blue)](https://jacobmountain.github.io/graphql-client/#/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.jacobmountain/graphql-java-client/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.jacobmountain/graphql-java-client)\n\nA Java GraphQL client annotation processor, generate a client class from a graphql schema file, and a Java interface.\n\n## Usage guide\n### 1. Generate a graphql schema file:\n```GraphQL\nschema {\n    query: Query\n}\n# The query type, represents all of the entry points into our object graph\ntype Query {\n    hero(episode: Episode): Character\n}\n# The episodes in the Star Wars trilogy\nenum Episode {\n    # Star Wars Episode IV: A New Hope, released in 1977.\n    NEWHOPE\n    # Star Wars Episode V: The Empire Strikes Back, released in 1980.\n    EMPIRE\n    # Star Wars Episode VI: Return of the Jedi, released in 1983.\n    JEDI\n}\n# A character from the Star Wars universe\ninterface Character {\n    # The ID of the character\n    id: ID!\n    # The name of the character\n    name: String!\n    # The friends of the character, or an empty list if they have none\n    friends: [Character]\n}\n# Units of height\nenum LengthUnit {\n    # The standard unit around the world\n    METER\n    # Primarily used in the United States\n    FOOT\n}\n# A humanoid creature from the Star Wars universe\ntype Human implements Character {\n    # The ID of the human\n    id: ID!\n    # What this human calls themselves\n    name: String!\n    # The home planet of the human, or null if unknown\n    homePlanet: String\n    # Height in the preferred unit, default is meters\n    height(unit: LengthUnit = METER): Float\n    # The friends of the character, or an empty list if they have none\n    friends: [Character]\n}\n# An autonomous mechanical character in the Star Wars universe\ntype Droid implements Character {\n    # The ID of the droid\n    id: ID!\n    # What others call this droid\n    name: String!\n    # This droid's friends, or an empty list if they have none\n    friends: [Character]\n    # This droid's primary function\n    primaryFunction: String\n}\n```\n\n### 2. Create a java interface\n```java\n@GraphQLClient(\n    schema = \"Schema.gql\",\n    mapping = {\n            @GraphQLClient.Scalar(from = \"ID\", to = String.class)\n    },\n    maxDepth = 5, // the max depth to use for graphql queries\n    nullChecking = true, // whether we should add client side null checks,\n    reactive = false\n)\npublic interface StarWarsClient {}\n```\nif this is the first time you've created the interface it may be a good idea to run build to generate all the DTO classes \nand to reduce IDE/compilation errors. \n\n### 3. Add corresponding methods to the interface that match up with the schema\n```java\n@GraphQLClient(\n    schema = \"Schema.gql\",\n    mapping = {\n            @GraphQLClient.Scalar(from = \"ID\", to = String.class)\n    },\n    maxDepth = 5, // the max depth to use for graphql queries\n    nullChecking = true // whether we should add client side null checks\n)\npublic interface StarWarsClient {\n\n    @GraphQLQuery(\"hero\")\n    Character getHero(Episode episode);\n\n}\n```\n### 4. Implement the `Fetcher` interface\nThe Fetcher interface deals with turning queries/mutations into network requests (Usually HTTP, could be websockets, etc.). \nFor a simple example on how to do this please look at [`RestTemplateFetcher.java`](https://github.com/JacobMountain/graphql-client/blob/develop/example/example-client/src/main/java/co/uk/jacobmountain/fetchers/RestTemplateFetcher.java) \nor [`WebClientFetcher.java`](https://github.com/JacobMountain/graphql-client/blob/develop/example/example-client/src/main/java/co/uk/jacobmountain/fetchers/WebClientFetcher.java).\n\n### 5. Create an instance of you newly generated interface\nRun `build` and then create an instance of the newly generated implementation.\n```java\nStarWarsClient client = new StarWarsClientGraph(new RestTemplateFetcher(\"http://your.domain.com\"));\n```\nwhere `HttpFetcher` is an implementation of the `Fetcher` interface. The default suffix for the implementation is `Graph`, \nand is overridable with the `implSuffix` parameter of the `@GraphQLClient` annotation.\n\n### 6. Profit?\n```java\nCharacter hero = heroclient.getHero(Episode.NEWHOPE);\nlog.info(\"My favourite Star Wars character is: {}!\", hero.getName());\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacobmountain%2Fgraphql-java-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacobmountain%2Fgraphql-java-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacobmountain%2Fgraphql-java-client/lists"}