{"id":23728474,"url":"https://github.com/leeturner/spring-boot-graphql-example","last_synced_at":"2026-02-18T09:30:16.323Z","repository":{"id":43935003,"uuid":"199191391","full_name":"leeturner/spring-boot-graphql-example","owner":"leeturner","description":"Demo Spring Boot project created to have a play around with Graphql","archived":false,"fork":false,"pushed_at":"2024-07-27T10:07:00.000Z","size":249,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T01:51:07.790Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leeturner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-07-27T16:52:11.000Z","updated_at":"2022-01-08T16:18:37.000Z","dependencies_parsed_at":"2023-12-07T15:30:49.292Z","dependency_job_id":"5d44def2-267f-4589-9def-97e219505b4b","html_url":"https://github.com/leeturner/spring-boot-graphql-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeturner%2Fspring-boot-graphql-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeturner%2Fspring-boot-graphql-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeturner%2Fspring-boot-graphql-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeturner%2Fspring-boot-graphql-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leeturner","download_url":"https://codeload.github.com/leeturner/spring-boot-graphql-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239832398,"owners_count":19704607,"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-12-31T01:51:16.838Z","updated_at":"2026-02-18T09:30:16.276Z","avatar_url":"https://github.com/leeturner.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Spring Boot/GraphQL Example App\n\nThis is a little Spring Boot REST application exposing a GraphQL interface designed to show the minimum needed to get up\nand running with GraphQL. It is basically the result of a few hours over a weekend to lean about what GraphQL is and\nwhat it brings to the table for REST based Spring Boot apps. At the moment this project only supports GraphQL `Query`s (\nretrieving data from our service).  `Mutation`s (updating data managed via our service) will be coming soon.\n\n## H2 Database\n\nThis app uses the H2 in-memory database and JPA to expose 2 simple entities - an `Invoice` and a `Client`. In this\nexample, a `Client` can have multiple `Invoice`'s issued to them. This is mapped by the JPA `@ManyToOne` annotation.\n\nThe H2 console has been enabled via adding these properties in the `application.properties` file:\n\n```properties\nspring.h2.console.enabled=true\nspring.h2.console.path=/h2-console\n```\n\nThe console can be accessed via this url - [http://localhost:8080/h2-console](http://localhost:8080/h2-console)\n\nOnce running you can authenticate against the in-memory database using the following credentials:\n\n* Driver Class: **org.h2.Driver**\n* JDBC URL: **jdbc:h2:mem:testdb**\n* User Name: **sa**\n* Password: [leave blank]\n\n## GraphQL\n\nGraphQL is enabled via adding the starter dependency from `com.graphql-java-kickstart`:\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.graphql-java-kickstart\u003c/groupId\u003e\n    \u003cartifactId\u003egraphql-spring-boot-starter\u003c/artifactId\u003e\n\u003c/dependency\u003e\n```\n\nThis enables the GraphQL servlet on the default location - `/graphql`. In this example we use the GraphQL schema\nlanguage to build the `graphql-java` schema. These files are stored in the `/resources/graphql/`:\n\nclient.graphqls:\n\n```\ntype Client {\n    id: ID!\n    name: String!\n    paymentTerms: Int!\n    addressLine1: String!\n    addressLine2: String\n    city: String!\n    postCode: String!\n}\n\ntype Query {\n    clients: [Client]\n    client(id: Int!): Client\n    clientCount: Int\n}\n```\n\ninvoice.graphqls:\n\n```\ntype Invoice {\n    id: ID!\n    client: Client!\n    status: String!\n    issuedDate: String\n    currency: String!\n    gross: Float!\n    net: Float!\n    vat: Float!\n}\n\nextend type Query {\n    invoices: [Invoice]\n    invoice(id: Int!): Invoice\n    invoicesByStatus(status: String): [Invoice]\n    invoiceCount: Int\n}\n```\n\n## Usage\n\nPull down the repo and build in the usual way. This is a Java 15 project so make sure you are using the correct version\nof the jdk either on the command line or within your IDE.\n\nOnce the service is up and running you can query the data using the queries defined in the `.graphqls` files. Below are\nsome example queries based on the queries we have defined:\n\nQuery:\n\n```\n{invoiceCount}\n```\n\nResult:\n\n```json\n{\n    \"data\": {\n        \"invoiceCount\": 3\n    }\n} \n```\n\nQuery:\n\n```\n{clientCount}\n```\n\nResult:\n\n```json\n{\n    \"data\": {\n        \"clientCount\": 2\n    }\n} \n```\n\nQuery:\n\n```\n{clients{id name paymentTerms}}\n```\n\nResult:\n\n```json\n{\n    \"data\": {\n        \"clients\": [\n            {\n                \"id\": \"1\",\n                \"name\": \"Bobs Marketing Agency\",\n                \"paymentTerms\": 28\n            },\n            {\n                \"id\": \"2\",\n                \"name\": \"Jills Accountancy Company\",\n                \"paymentTerms\": 28\n            }\n        ]\n    }\n} \n```\n\nYou will notice that the above query does not contain all the data managed by the `Client` entity. We can return more or\nless data in the response by changing the fields in the query:\n\nQuery:\n\n```\n{clients{id name paymentTerms addressLine1 addressLine2 city postCode}}\n```\n\nResult:\n\n```json\n{\n  \"data\": {\n    \"clients\": [\n      {\n        \"id\": \"1\",\n        \"name\": \"Bobs Marketing Agency\",\n        \"paymentTerms\": 28,\n        \"addressLine1\": \"23 Brighton Street\",\n        \"addressLine2\": \"Rottingdean\",\n        \"city\": \"Brighton\",\n        \"postCode\": \"BN2 7DP\"\n      },\n      {\n        \"id\": \"2\",\n        \"name\": \"Jills Accountancy Company\",\n        \"paymentTerms\": 28,\n        \"addressLine1\": \"24 Eastbourne Rd\",\n        \"addressLine2\": null,\n        \"city\": \"Eastboaurne\",\n        \"postCode\": \"BN23 5GP\"\n      }\n    ]\n  }\n} \n```\n\nThe same applies for the `invoices` query although this one is a little more interesting given its relationship to\nthe `Client` entity. Using GraphQL we can traverse the object graph and return the `Client` data along with the invoice:\n\nQuery:\n\n```\n{invoices{id status gross net vat client{id name}}}\n```\n\nResult:\n\n```json\n{\n  \"data\": {\n    \"invoices\": [\n      {\n        \"id\": \"3\",\n        \"status\": \"DRAFT\",\n        \"gross\": 120,\n        \"net\": 100,\n        \"vat\": 20,\n        \"client\": {\n          \"id\": \"1\",\n          \"name\": \"Bobs Marketing Agency\"\n        }\n      },\n      {\n        \"id\": \"4\",\n        \"status\": \"ISSUED\",\n        \"gross\": 1200,\n        \"net\": 1000,\n        \"vat\": 200,\n        \"client\": {\n          \"id\": \"1\",\n          \"name\": \"Bobs Marketing Agency\"\n        }\n      },\n      {\n        \"id\": \"5\",\n        \"status\": \"DRAFT\",\n        \"gross\": 120,\n        \"net\": 100,\n        \"vat\": 20,\n        \"client\": {\n          \"id\": \"2\",\n          \"name\": \"Jills Accountancy Company\"\n        }\n      }\n    ]\n  }\n}\n```\n\nAs before we can return more or less data across both entities in the same `Query`:\n\nQuery:\n\n```\n{invoices{id status client{id name addressLine1 city postCode}}}\n```\n\nResult:\n\n```json\n{\n  \"data\": {\n    \"invoices\": [\n      {\n        \"id\": \"3\",\n        \"status\": \"DRAFT\",\n        \"client\": {\n          \"id\": \"1\",\n          \"name\": \"Bobs Marketing Agency\",\n          \"addressLine1\": \"23 Brighton Street\",\n          \"city\": \"Brighton\",\n          \"postCode\": \"BN2 7DP\"\n        }\n      },\n      {\n        \"id\": \"4\",\n        \"status\": \"ISSUED\",\n        \"client\": {\n          \"id\": \"1\",\n          \"name\": \"Bobs Marketing Agency\",\n          \"addressLine1\": \"23 Brighton Street\",\n          \"city\": \"Brighton\",\n          \"postCode\": \"BN2 7DP\"\n        }\n      },\n      {\n        \"id\": \"5\",\n        \"status\": \"DRAFT\",\n        \"client\": {\n          \"id\": \"2\",\n          \"name\": \"Jills Accountancy Company\",\n          \"addressLine1\": \"24 Eastbourne Rd\",\n          \"city\": \"Eastboaurne\",\n          \"postCode\": \"BN23 5GP\"\n        }\n      }\n    ]\n  }\n}\n```\n\nQueries that require additional data such as the `invoicesByStatus` query can be passed as parameters:\n\nQuery:\n\n```\n{invoicesByStatus(status: \"DRAFT\"){id status client{id name addressLine1 city postCode}}}\n```\n\nResult:\n\n```json\n{\n  \"data\": {\n    \"invoicesByStatus\": [\n      {\n        \"id\": \"3\",\n        \"status\": \"DRAFT\",\n        \"client\": {\n          \"id\": \"1\",\n          \"name\": \"Bobs Marketing Agency\",\n          \"addressLine1\": \"23 Brighton Street\",\n          \"city\": \"Brighton\",\n          \"postCode\": \"BN2 7DP\"\n        }\n      },\n      {\n        \"id\": \"5\",\n        \"status\": \"DRAFT\",\n        \"client\": {\n          \"id\": \"2\",\n          \"name\": \"Jills Accountancy Company\",\n          \"addressLine1\": \"24 Eastbourne Rd\",\n          \"city\": \"Eastboaurne\",\n          \"postCode\": \"BN23 5GP\"\n        }\n      }\n    ]\n  }\n}\n```\n\nAll of the above queries can be sent to the service via the url. They need to be URLEncoded for them to work properly.\nFor example:\n\n```\nhttp://localhost:8080/graphql?query=%7BcountClients%7D\nhttp://localhost:8080/graphql?query=%7Bclients%7Bid%20name%20paymentTerms%7D%7D\nhttp://localhost:8080/graphql?query=%7Binvoices%7Bid%20status%20client%7Bid%20name%20addressLine1%20city%20postCode%7D%7D%7D\nhttp://localhost:8080/graphql?query=%7BinvoicesByStatus(status%3A%20%22DRAFT%22)%7Bid%20status%20client%7Bid%20name%20addressLine1%20city%20postCode%7D%7D%7D\n```\n\n### GraphiQL\n\nIf you want a more interactive experience then GraphiQL has been enabled via adding the following dependency to the\nservice:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.graphql-java-kickstart\u003c/groupId\u003e\n  \u003cartifactId\u003egraphiql-spring-boot-starter\u003c/artifactId\u003e\n  \u003cversion\u003e11.1.0\u003c/version\u003e\n  \u003cscope\u003eruntime\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nGraphiQL is an in-browser IDE for exploring GraphQL:\n\n![GraphiQL in-browser IDE](docs/images/GraphiQL.png)\n\nThe GraphiQL IDE can be accessed at the following URL - [http://localhost:8080/graphiql](http://localhost:8080/graphiql)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleeturner%2Fspring-boot-graphql-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleeturner%2Fspring-boot-graphql-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleeturner%2Fspring-boot-graphql-example/lists"}