{"id":20483356,"url":"https://github.com/styczynski/tiny-graphql-scala","last_synced_at":"2025-08-18T05:43:23.932Z","repository":{"id":79817420,"uuid":"166695037","full_name":"styczynski/tiny-graphql-scala","owner":"styczynski","description":"Tiny, fast GraphQL parser written in Scala","archived":false,"fork":false,"pushed_at":"2019-01-28T17:59:41.000Z","size":76,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-05T23:06:39.420Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","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/styczynski.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,"zenodo":null}},"created_at":"2019-01-20T18:30:51.000Z","updated_at":"2020-04-10T15:52:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"20a7aec4-c384-49ac-9eaf-593da77e589e","html_url":"https://github.com/styczynski/tiny-graphql-scala","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/styczynski/tiny-graphql-scala","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styczynski%2Ftiny-graphql-scala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styczynski%2Ftiny-graphql-scala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styczynski%2Ftiny-graphql-scala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styczynski%2Ftiny-graphql-scala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/styczynski","download_url":"https://codeload.github.com/styczynski/tiny-graphql-scala/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styczynski%2Ftiny-graphql-scala/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270951162,"owners_count":24674004,"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","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-15T16:17:07.010Z","updated_at":"2025-08-18T05:43:23.915Z","avatar_url":"https://github.com/styczynski.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tiny-graphql-scala ![Build status](https://travis-ci.org/styczynski/tiny-graphql-scala.svg?branch=master) [![Coverage status](https://coveralls.io/repos/github/styczynski/tiny-graphql-scala/badge.svg?branch=master)](https://coveralls.io/github/styczynski/tiny-graphql-scala?branch=master) ![License status](https://img.shields.io/github/license/styczynski/tiny-graphql-scala.svg)\n\nTiny, fast GraphQL parser written in Scala\n\nYou can play with [online schema formatter](http://serene-lake-16900.herokuapp.com) and view it's sources [here](https://github.com/styczynski/tiny-graphql-scala-webpage).\n\n## Contents of the document\n\n * Introduction\n * GraphQL schema parser\n   * Parsing schema text\n   * Builing AST manually\n   * Types relations\n * GraphQL queries parser\n * TODOs\n \n## Introduction\n\n**This is yet experimental software, use it for your own resposibility**\n \nThis project was implemented as a part of Warsaw university course and is yet highly experimental software without any guarantee it works and that it will still work in the future.\n \nParsers are based on Scala [parboiled2](https://github.com/sirthias/parboiled2) super-fast parser generator.\n \n## GraphQL Schema parser\n\nThe parser supports all features of GraphQL except fragments.\n\n### Parsing schema text\n\nThe most basic working snippet of code is presented below.\n\n```scala\nimport parser.SchemaParser\n\nval code = \"\"\"|type MyType {\n              |    x: ID\n              |    t: Boolean\n              |    y: Int\n              |    z: Float!\n              |}\n              |\"\"\".stripMargin\nval schema = SchemaParser().parse(code)\n```\n\nParser returns instance of `GraphQLSchema` that contains representations of all loaded types.\n\n### Builiding AST manually\n\nYou can build types manually using provided case classes:\n```scala\n\nval myType = GraphQLCompositeType(Some(\"MyTypeName\"))\n          .withField(\"x\", DefaultGraphQLSchema.STRING.withNullability(false))\n          .withField(\"y\", DefaultGraphQLSchema.INT.withNullability(false))\n          .withField(\"z\", DefaultGraphQLSchema.FLOAT)\n\n```\nwhich is equivalent to the following schema:\n```graphql\ntype MyTypeName {\n  x: String!\n  y: Int!\n  z: Float\n}\n```\n\nThe `DefaultGraphQLSchema` provides implementations of basic GraphQL types.\nYou can also create circular dependencies using string references to types:\n\n```scala\nval schema = new GraphQLSchema()\nval myType = GraphQLCompositeType(Some(\"MyTypeName\"))\n          .withField(\"x\", GraphQLRefType(schema, Some(\"TypeX\"))\n```\n\nWhich is equivalent to:\n```graphql\n  type MyTypeName {\n    x: TypeX\n  }\n```\n\nWhen you use references to other types you must pass schema object that contains the required definiotions.\nIn the mentioned case the code will not throw any error, because type references are not checked.\n\nTo check if your types are valid you must call `schema.validate` (validates all types withing schema) or `myType.validateType` (only validates single type) to validate if the type really exist and if the structure of your types are valid.\n\nYou can learn more about building AST manually by looking at the tests [there](https://github.com/styczynski/tiny-graphql-scala/blob/master/src/test/scala/parser/schema/SchemaBasicTest.scala)\n\n### Types relations\n\nLet us introduce relation `~\u003c` that for `A ~\u003c B` means that B is generalization for A.\nThat in other words means that if you have an object `obj` and it's valid object of type `A` that it must be valid object of type `B`.\n\nIn similar manner we define `~\u003e` and equality `~=` which is defined by: `A ~= B is equivalent to A ~\u003c B \u0026\u0026 A ~\u003e B`\nEquality means the types represent exactly the same effective types (i.e. there exist no object that could differentiate these types).\n\n```graphql\nunion UnionC = Int | Float | String\nunion UnionB = String | Float\n```\n\nIn this case we have `String ~\u003c UnionB \u0026\u0026 UnionB ~\u003c UnionC`\nSo also we have `String ~\u003c UnionC`\n\nIt's obvious as `UnionC` contains floats, ints and especially strings.\n\nTypes ordering may be useful in case of validating types.\nFor example:\n```graphql\ntype X implements Y { ... }\n```\nmeans that `X ~\u003e Y`\n\n### GraphQL queries parser\n\nThere exists incomplete parser for GraphQL which supports only plain fields without fragments, annotations, fields arguments.\n\nThe parser can be used in similar way as the schema parser:\n```scala\nval code =\n    \"\"\"|\n       |query {\n       |  fieldA {\n       |    fieldX {\n       |      someData\n       |    }\n       |  }\n       |}\n       |\"\"\".stripMargin\n\nprintln(RequestParser().parse(code))\n```\n\n`parse()` method will return AST-representation of the query\n\n### TODOs\n\nWhat was achieved:\n * Implemented full GraphQL schema langauge support with types validation and ability to manually create in-code queries\n   * There are many features of GraphQL that parser has support for, yay!\n   * The fragments are the last functionality that is not yet supported\n * Easy way to add custom types in future with own validation, field format etc.\n * Working SBT build with coverage collection on Travis CI\n * more than 70 tests for parsing various schemas\n * Very simple GraphQL query parser (not yet finished)\n \nWhat left:\n * Implementing fully-compatible query parser\n * Implementing resolver for resolving the query\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstyczynski%2Ftiny-graphql-scala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstyczynski%2Ftiny-graphql-scala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstyczynski%2Ftiny-graphql-scala/lists"}