├── .gitignore ├── .vscode └── settings.json ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── babel-plugin ├── .gitignore ├── .npmignore ├── .yarn │ └── releases │ │ └── yarn-3.6.3.cjs ├── .yarnrc.yml ├── README.md ├── benchmark │ └── index.js ├── dev.ts ├── package.json ├── src │ └── index.ts ├── tests │ ├── fixtures │ │ ├── custom_comment_option │ │ │ ├── input.js │ │ │ ├── options.json │ │ │ └── output.js │ │ ├── migrated_001 │ │ │ ├── input.js │ │ │ └── output.js │ │ ├── migrated_002 │ │ │ ├── input.js │ │ │ └── output.js │ │ ├── migrated_003 │ │ │ ├── input.js │ │ │ └── output.js │ │ └── migrated_004 │ │ │ ├── input.js │ │ │ └── output.js │ └── index.ts ├── tsconfig.json ├── webpack.config.js └── yarn.lock ├── crates ├── playground │ ├── .gitignore │ ├── Cargo.toml │ ├── benches │ │ └── temp_bench.rs │ ├── schema.docs.graphql │ ├── src │ │ └── main.rs │ └── type.d.ts ├── rustgql_cli │ ├── Cargo.toml │ └── src │ │ ├── codegen.rs │ │ └── main.rs ├── rustgql_common │ ├── Cargo.toml │ └── src │ │ ├── ast │ │ ├── common.rs │ │ ├── mod.rs │ │ ├── query.rs │ │ └── schema.rs │ │ ├── lib.rs │ │ ├── position.rs │ │ └── token.rs ├── rustgql_core │ ├── Cargo.toml │ ├── LICENSE │ ├── README.md │ └── src │ │ └── lib.rs ├── rustgql_minifier │ ├── Cargo.toml │ ├── src │ │ ├── lib.rs │ │ └── query_minifier.rs │ └── tests │ │ ├── fixtures │ │ └── graphql_rust │ │ │ └── query │ │ │ ├── directive_args.graphql │ │ │ ├── directive_args_multiline.graphql │ │ │ ├── fragment.graphql │ │ │ ├── fragment_spread.graphql │ │ │ ├── inline_fragment.graphql │ │ │ ├── inline_fragment_dir.graphql │ │ │ ├── kitchen-sink.graphql │ │ │ ├── kitchen-sink_canonical.graphql │ │ │ ├── minimal.graphql │ │ │ ├── minimal_mutation.graphql │ │ │ ├── minimal_query.graphql │ │ │ ├── mutation_directive.graphql │ │ │ ├── mutation_nameless_vars.graphql │ │ │ ├── named_query.graphql │ │ │ ├── nested_selection.graphql │ │ │ ├── query_aliases.graphql │ │ │ ├── query_arguments.graphql │ │ │ ├── query_arguments_multiline.graphql │ │ │ ├── query_array_argument_multiline.graphql │ │ │ ├── query_directive.graphql │ │ │ ├── query_list_argument.graphql │ │ │ ├── query_nameless_vars.graphql │ │ │ ├── query_nameless_vars_multiple_fields.graphql │ │ │ ├── query_nameless_vars_multiple_fields_canonical.graphql │ │ │ ├── query_object_argument.graphql │ │ │ ├── query_object_argument_multiline.graphql │ │ │ ├── query_var_default_float.graphql │ │ │ ├── query_var_default_list.graphql │ │ │ ├── query_var_default_object.graphql │ │ │ ├── query_var_default_string.graphql │ │ │ ├── query_var_defaults.graphql │ │ │ ├── query_vars.graphql │ │ │ ├── string_literal.graphql │ │ │ ├── subscription_directive.graphql │ │ │ └── triple_quoted_literal.graphql │ │ └── minifier_graphql_rust_query_test.rs ├── rustgql_parser │ ├── Cargo.toml │ ├── benches │ │ └── parser_benches.rs │ ├── src │ │ ├── lexer.rs │ │ ├── lib.rs │ │ ├── marco.rs │ │ └── parser.rs │ └── tests │ │ ├── fixtures │ │ └── graphql_rust │ │ │ ├── query │ │ │ ├── directive_args.ast.json │ │ │ ├── directive_args_multiline.ast.json │ │ │ ├── fragment.ast.json │ │ │ ├── fragment_spread.ast.json │ │ │ ├── inline_fragment.ast.json │ │ │ ├── inline_fragment_dir.ast.json │ │ │ ├── kitchen-sink.ast.json │ │ │ ├── kitchen-sink_canonical.ast.json │ │ │ ├── minimal.ast.json │ │ │ ├── minimal_mutation.ast.json │ │ │ ├── minimal_query.ast.json │ │ │ ├── mutation_directive.ast.json │ │ │ ├── mutation_nameless_vars.ast.json │ │ │ ├── named_query.ast.json │ │ │ ├── nested_selection.ast.json │ │ │ ├── query_aliases.ast.json │ │ │ ├── query_arguments.ast.json │ │ │ ├── query_arguments_multiline.ast.json │ │ │ ├── query_array_argument_multiline.ast.json │ │ │ ├── query_directive.ast.json │ │ │ ├── query_list_argument.ast.json │ │ │ ├── query_nameless_vars.ast.json │ │ │ ├── query_nameless_vars_multiple_fields.ast.json │ │ │ ├── query_nameless_vars_multiple_fields_canonical.ast.json │ │ │ ├── query_object_argument.ast.json │ │ │ ├── query_object_argument_multiline.ast.json │ │ │ ├── query_var_default_float.ast.json │ │ │ ├── query_var_default_list.ast.json │ │ │ ├── query_var_default_object.ast.json │ │ │ ├── query_var_default_string.ast.json │ │ │ ├── query_var_defaults.ast.json │ │ │ ├── query_vars.ast.json │ │ │ ├── string_literal.ast.json │ │ │ ├── subscription_directive.ast.json │ │ │ └── triple_quoted_literal.ast.json │ │ │ └── schema │ │ │ ├── directive.ast.json │ │ │ ├── directive_descriptions.ast.json │ │ │ ├── directive_descriptions_canonical.ast.json │ │ │ ├── directive_variable_definition.ast.json │ │ │ ├── empty_union.ast.json │ │ │ ├── enum.ast.json │ │ │ ├── extend_enum.ast.json │ │ │ ├── extend_input.ast.json │ │ │ ├── extend_input_canonical.ast.json │ │ │ ├── extend_interface.ast.json │ │ │ ├── extend_object.ast.json │ │ │ ├── extend_scalar.ast.json │ │ │ ├── implements.ast.json │ │ │ ├── implements_amp.ast.json │ │ │ ├── implements_amp_canonical.ast.json │ │ │ ├── implements_interface.ast.json │ │ │ ├── input_type.ast.json │ │ │ ├── interface.ast.json │ │ │ ├── kitchen-sink.ast.json │ │ │ ├── kitchen-sink_canonical.ast.json │ │ │ ├── minimal.ast.json │ │ │ ├── minimal_type.ast.json │ │ │ ├── repeatable.ast.json │ │ │ ├── scalar_type.ast.json │ │ │ ├── simple_object.ast.json │ │ │ ├── union.ast.json │ │ │ └── union_extension.ast.json │ │ ├── parser_graphql_rust_query_test.rs │ │ └── parser_graphql_rust_schema_test.rs └── rustgql_typegen │ ├── Cargo.toml │ └── src │ ├── graphql_table.rs │ ├── lib.rs │ ├── query_generator.rs │ └── schema_generator.rs └── fixtures ├── baseline └── query_complex.graphql ├── graphql_github ├── query_simple.graphql └── schema.docs.graphql └── graphql_rust ├── errors ├── bad_args.graphql └── invalid_curly_brace.graphql ├── query ├── directive_args.graphql ├── directive_args_multiline.graphql ├── fragment.graphql ├── fragment_spread.graphql ├── inline_fragment.graphql ├── inline_fragment_dir.graphql ├── kitchen-sink.graphql ├── kitchen-sink_canonical.graphql ├── minimal.graphql ├── minimal_mutation.graphql ├── minimal_query.graphql ├── mutation_directive.graphql ├── mutation_nameless_vars.graphql ├── named_query.graphql ├── nested_selection.graphql ├── query_aliases.graphql ├── query_arguments.graphql ├── query_arguments_multiline.graphql ├── query_array_argument_multiline.graphql ├── query_directive.graphql ├── query_list_argument.graphql ├── query_nameless_vars.graphql ├── query_nameless_vars_multiple_fields.graphql ├── query_nameless_vars_multiple_fields_canonical.graphql ├── query_object_argument.graphql ├── query_object_argument_multiline.graphql ├── query_var_default_float.graphql ├── query_var_default_list.graphql ├── query_var_default_object.graphql ├── query_var_default_string.graphql ├── query_var_defaults.graphql ├── query_vars.graphql ├── string_literal.graphql ├── subscription_directive.graphql └── triple_quoted_literal.graphql └── schema ├── directive.graphql ├── directive_descriptions.graphql ├── directive_descriptions_canonical.graphql ├── directive_variable_definition.graphql ├── empty_union.graphql ├── enum.graphql ├── extend_enum.graphql ├── extend_input.graphql ├── extend_input_canonical.graphql ├── extend_interface.graphql ├── extend_object.graphql ├── extend_scalar.graphql ├── implements.graphql ├── implements_amp.graphql ├── implements_amp_canonical.graphql ├── implements_interface.graphql ├── input_type.graphql ├── interface.graphql ├── kitchen-sink.graphql ├── kitchen-sink_canonical.graphql ├── minimal.graphql ├── minimal_type.graphql ├── repeatable.graphql ├── scalar_type.graphql ├── simple_object.graphql ├── union.graphql └── union_extension.graphql /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .DS_Store 3 | /**/.DS_Store 4 | /**/pkg -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.checkOnSave.command": "clippy" 3 | } -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | members = [ 4 | "crates/rustgql_common", 5 | "crates/rustgql_parser", 6 | "crates/rustgql_typegen", 7 | "crates/rustgql_minifier", 8 | "crates/rustgql_cli", 9 | "crates/rustgql_core", 10 | "crates/playground" 11 | ] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Steven 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RustGQL 2 | a tool for graqhql , written in rust for better performance. pass all test case in graphql-rust ([link](https://github.com/graphql-rust/graphql-parser/tree/master/tests)) 3 | 4 | ## Quick Start 5 | install rustql_parser and rustql_common. 6 | - rustgql_parser: lexer and parser for graphql. 7 | - rustgql_common: ast and token for graphql. 8 | - rustgql_typegen: generate typescript `.d.ts` file from your schema. 9 | ```rust 10 | use rustgql_parser::parser::Parser; 11 | fn main() { 12 | let code = " 13 | query { 14 | node { 15 | id 16 | ...something 17 | } 18 | } 19 | "; 20 | let mut parser = Parser::new(code); 21 | let doc = parser.parse(); 22 | println!("{:?}", doc); 23 | } 24 | ``` 25 | ## Benchesmark 26 | using criterion for benchmark, compare to graphql-rust is 4 time faster. 27 | 28 | | **file** | kitchen-sink_canonical | 29 | | -----------------: | ----------------------: | 30 | | **graphql-rust** | 28.016 us | 31 | | **rustgql** | 6.1192us | 32 | | **~** | 4.5783x | -------------------------------------------------------------------------------- /babel-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .pnp.* 4 | .yarn/* 5 | !.yarn/patches 6 | !.yarn/plugins 7 | !.yarn/releases 8 | !.yarn/sdks 9 | !.yarn/versions -------------------------------------------------------------------------------- /babel-plugin/.npmignore: -------------------------------------------------------------------------------- 1 | /* 2 | !/dist/*.js 3 | !/dist/*.wasm -------------------------------------------------------------------------------- /babel-plugin/.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | yarnPath: .yarn/releases/yarn-3.6.3.cjs 4 | -------------------------------------------------------------------------------- /babel-plugin/README.md: -------------------------------------------------------------------------------- 1 | # babel-plugin-graphql-query-minifier 2 | 3 | > This plugin is to minify your graphql query string when transform JavaScript/TypeScript file by babel. 4 | 5 | ## Install 6 | ``` 7 | npm install -D babel-plugin-graphql-query-minifier 8 | ``` 9 | ## Quick Start 10 | This plugin can help you minify your graphql string when babel transform your JavaScript/TypeScript files. By minify the query string, you can get a more mini size of result bundle files. 11 | 12 | This plugin can minify query string by certain comment or tag function name, default is `graphql` comment and `gql` tag function, you can change it by option config (see below section). 13 | 14 | For example below is some query string: 15 | ```js 16 | const queryByComment = /* graphql */` 17 | query GetUser { 18 | name, 19 | age, 20 | id 21 | } 22 | `; 23 | const queryByTagFunction = gql` 24 | mutation ChangeSomeThing (uuid: ${uuid}) { 25 | result, 26 | log, 27 | } 28 | `; 29 | ``` 30 | By this plugin, you can get : 31 | ```js 32 | const queryByComment = /* graphql */`query GetUser{name,age,id}`; 33 | const queryByTagFunction = gql`mutation ChangeSomeThing($uuid:String=${uuid}){result,log}`; 34 | ``` 35 | 36 | ## Usage 37 | You can use babel config to start this plugin. By using `babelrc` : 38 | ```json 39 | { 40 | "plugins": [ 41 | [ 42 | "babel-plugin-graphql-query-minifier", 43 | { 44 | "comment": "graphql", 45 | "function": "gql", 46 | } 47 | ] 48 | ] 49 | } 50 | ``` 51 | 52 | ## Option Config 53 | This plugin provide you can customize the comment name and tag function name to minify graphql query string, you can pass config by babel config or using CLI or API. 54 | The following options are available: 55 | - `comment` : `String`, comment values in front of graphql query string. 56 | - `function` : `String`, tag function name take query string as arguments. 57 | 58 | ## Compare with grahpql-compress 59 | This plugin can minify more charater than `graphql-compress` related plugin, and it's core is running by wasm, so it is faster than use `graphql-compress`. 60 | 61 | For example, `babel-plugin-transform-compress-graphql` would still leave some space after argument type and the fragment spread. 62 | ```js 63 | const query = /* graphql */ ` 64 | query QueryWithArgument(name: String = "test-name") { 65 | ... SomeFragment 66 | ... on SomeData { 67 | field 68 | } 69 | } 70 | `; 71 | // result of using `babel-plugin-transform-compress-graphql` 72 | const queryResult1 = `query QueryWithArgument($name:String = "test-name"){... SomeFragment ... on SomeData{field}}`; 73 | // result of using `babel-plugin-graphql-query-minifier` 74 | const queryResult2 = `query QueryWithArgument($name:String="test-name"){...SomeFragment...on SomeData{field}}`; 75 | ``` 76 | And it's speed is also faster then using `graphql-compress`'s related plugin, by using `tinybench` package, result shows that `babel-plugin-graphql-query-minifier` is 3 time faster then `babel-plugin-transform-compress-graphql`, you can see this result by running `yarn bench` at this repo. 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /babel-plugin/benchmark/index.js: -------------------------------------------------------------------------------- 1 | const { Bench } = require('tinybench'); 2 | const { transform } = require('@babel/core'); 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const tranformCompressGraphql = require('babel-plugin-transform-compress-graphql'); 6 | const MyPlugin = require('../dist'); 7 | const code = `const query = /* graphql */ \`${fs.readFileSync(path.join(__dirname,"../../fixtures/baseline/query_complex.graphql")).toString()}\``; 8 | const bench = new Bench({ time: 150 }); 9 | 10 | async function asyncTransform(plugins) { 11 | return new Promise((resolve, reject) => { 12 | transform( 13 | code, 14 | { plugins }, 15 | (err, result) => { 16 | if(err) { 17 | reject(err); 18 | return; 19 | } 20 | if(!result) { 21 | reject(); 22 | return; 23 | } 24 | resolve(result.code); 25 | } 26 | ) 27 | }) 28 | } 29 | async function benchWrapper() { 30 | await asyncTransform([tranformCompressGraphql]); 31 | await asyncTransform([MyPlugin]); 32 | bench.add("transform-compress-graphql", async () => { 33 | await asyncTransform([tranformCompressGraphql]); 34 | }); 35 | bench.add("graphql-query-minifier", async () => { 36 | await asyncTransform([MyPlugin]); 37 | }); 38 | await bench.run(); 39 | console.table(bench.table()); 40 | } 41 | async function compareResultLength() { 42 | const codeFromCompress = await asyncTransform([tranformCompressGraphql]); 43 | const codeFromGraphql = await asyncTransform([MyPlugin]); 44 | console.log("==============================================="); 45 | console.log("Compress Length: ", codeFromCompress.length + "/* graphql */".length); 46 | console.log("My Plugin Length:", codeFromGraphql.length); 47 | console.log("==============================================="); 48 | } 49 | 50 | benchWrapper(); 51 | compareResultLength(); -------------------------------------------------------------------------------- /babel-plugin/dev.ts: -------------------------------------------------------------------------------- 1 | import MyPlugin from "./src"; 2 | import { transform } from "@babel/core"; 3 | 4 | const code = ` 5 | const query = /* graphql */\` 6 | query GetUser { 7 | name, age 8 | } 9 | \`; 10 | `; 11 | 12 | async function testResult(code: string, options = {}) { 13 | return new Promise((resolve, reject) => { 14 | transform( 15 | code, 16 | { plugins: [ 17 | [ 18 | MyPlugin, 19 | options 20 | ] 21 | ] }, 22 | (err, result) => { 23 | if(err) { 24 | reject(err); 25 | return; 26 | } 27 | if(!result) { 28 | reject(new Error("result is null")); 29 | return; 30 | } 31 | resolve(result); 32 | } 33 | ) 34 | }); 35 | }; 36 | 37 | async function mainRunnner() { 38 | await testResult(code, { 39 | comment: "test" 40 | }).then((result) => { 41 | console.log(result); 42 | }) 43 | } 44 | 45 | mainRunnner(); -------------------------------------------------------------------------------- /babel-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-graphql-query-minifier", 3 | "version": "0.0.2", 4 | "author": "Solo-steven ", 5 | "description": "babel plugin for minify your graphql query string at compile time", 6 | "keywords": [ 7 | "graphql", 8 | "babel-plugin", 9 | "minifier", 10 | "babel" 11 | ], 12 | "main": "./dist/index.js", 13 | "license": "MIT", 14 | "packageManager": "yarn@3.6.3", 15 | "homepage": "https://github.com/Solo-steven/rustgql", 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/Solo-steven/rustgql.git" 19 | }, 20 | "scripts": { 21 | "dev": "ts-node ./dev.ts", 22 | "build": "NODE_ENV=production webpack", 23 | "test": "ts-node ./tests/index.ts", 24 | "bench": "node ./benchmark/index.js" 25 | }, 26 | "dependencies": { 27 | "rustgql_core": "^0.1.1" 28 | }, 29 | "devDependencies": { 30 | "@babel/core": "^7.22.17", 31 | "@babel/preset-env": "^7.22.15", 32 | "@babel/preset-typescript": "^7.22.15", 33 | "@babel/traverse": "^7.22.15", 34 | "@babel/types": "^7.22.15", 35 | "@types/babel__core": "^7.20.1", 36 | "@types/babel__traverse": "^7.20.1", 37 | "@types/node": "^20.6.0", 38 | "babel-loader": "^9.1.3", 39 | "babel-plugin-transform-compress-graphql": "^1.3.3", 40 | "copy-webpack-plugin": "^11.0.0", 41 | "graphql-query-compress": "^1.2.4", 42 | "tinybench": "^2.5.0", 43 | "ts-node": "^10.9.1", 44 | "typescript": "^5.2.2", 45 | "webpack": "^5.88.2", 46 | "webpack-cli": "^5.1.4" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /babel-plugin/src/index.ts: -------------------------------------------------------------------------------- 1 | import { minify_query as minifyQuery } from "rustgql_core"; 2 | import { type Visitor } from "@babel/traverse"; 3 | import { type TemplateLiteral } from "@babel/types"; 4 | 5 | const DEFAULT_COMMENT = "graphql"; 6 | const DEFAULT_FUNCTION = "gql"; 7 | 8 | type StateType = { 9 | opts: { 10 | comment: string, 11 | function: string, 12 | } 13 | } 14 | 15 | function handleTemplateLiteral(node: TemplateLiteral) { 16 | if(node.quasis.length === 1) { 17 | const rawValue = node.quasis[0].value.raw; 18 | const minifiedValue = minifyQuery(rawValue); 19 | node.quasis[0].value.raw = minifiedValue; 20 | node.quasis[0].value.cooked = minifiedValue 21 | return; 22 | } 23 | const concatQuasi = node.quasis.reduce((pre, current, index) => { 24 | if(index === 0) return current.value.raw; 25 | return pre + "\"RUSTGQL_SYMBOL\"" + current.value.raw; 26 | }, "") 27 | const minifiedValue = minifyQuery(concatQuasi); 28 | const nextQuasi = minifiedValue.split("\"RUSTGQL_SYMBOL\""); 29 | for(let i = 0 ; i < node.quasis.length ; ++i) { 30 | node.quasis[i].value.raw = nextQuasi[i]; 31 | node.quasis[i].value.cooked = nextQuasi[i]; 32 | } 33 | return; 34 | } 35 | 36 | const visitor: Visitor = { 37 | TemplateLiteral(path, state) { 38 | const node = path.node; 39 | if(!node.leadingComments) { 40 | return; 41 | } 42 | const pluckComment = (state as StateType).opts.comment || DEFAULT_COMMENT; 43 | const containPluckCommentIndex = node.leadingComments.findIndex( 44 | (comment) => comment.value.trim() === pluckComment 45 | ); 46 | if(containPluckCommentIndex >= 0 ) { 47 | handleTemplateLiteral(node) 48 | } 49 | }, 50 | TaggedTemplateExpression(path, state) { 51 | const node = path.node; 52 | const pluckTagFunction = (state as StateType).opts.function || DEFAULT_FUNCTION; 53 | if(node.tag.type === "Identifier") { 54 | if(node.tag.name === pluckTagFunction) { 55 | handleTemplateLiteral(node.quasi); 56 | } 57 | } 58 | } 59 | }; 60 | 61 | export default function () { 62 | return { 63 | name: "graphql-query-minifier", 64 | visitor, 65 | } 66 | } -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/custom_comment_option/input.js: -------------------------------------------------------------------------------- 1 | const query = /* graphql */` 2 | query GetUser { 3 | names 4 | } 5 | `; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/custom_comment_option/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "test" 3 | } -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/custom_comment_option/output.js: -------------------------------------------------------------------------------- 1 | const query = /* graphql */` 2 | query GetUser { 3 | names 4 | } 5 | `; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/migrated_001/input.js: -------------------------------------------------------------------------------- 1 | const query = /* graphql */` 2 | query { 3 | name 4 | age 5 | } 6 | `; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/migrated_001/output.js: -------------------------------------------------------------------------------- 1 | const query = /* graphql */`query{name,age}`; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/migrated_002/input.js: -------------------------------------------------------------------------------- 1 | const uuid = "some-uuid"; 2 | const query = /* graphql */` 3 | query GetUser($uuid: String =${uuid}) { 4 | name 5 | age 6 | } 7 | `; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/migrated_002/output.js: -------------------------------------------------------------------------------- 1 | const uuid = "some-uuid"; 2 | const query = /* graphql */`query GetUser($uuid:String=${uuid}){name,age}`; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/migrated_003/input.js: -------------------------------------------------------------------------------- 1 | const query = gql` 2 | query { 3 | name, 4 | age 5 | } 6 | `; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/migrated_003/output.js: -------------------------------------------------------------------------------- 1 | const query = gql`query{name,age}`; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/migrated_004/input.js: -------------------------------------------------------------------------------- 1 | const query = gql` 2 | query GetUser ($uuid: String = ${uuid}){ 3 | name, 4 | age 5 | } 6 | `; -------------------------------------------------------------------------------- /babel-plugin/tests/fixtures/migrated_004/output.js: -------------------------------------------------------------------------------- 1 | const query = gql`query GetUser($uuid:String=${uuid}){name,age}`; -------------------------------------------------------------------------------- /babel-plugin/tests/index.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs/promises"; 2 | import path from "path"; 3 | import { transform } from "@babel/core"; 4 | import MyPlugin from "../src"; 5 | 6 | type TestCase = { 7 | fileId: string, 8 | input: string, 9 | output: string, 10 | options: { 11 | comment?: string, 12 | function?: string, 13 | } 14 | } 15 | 16 | type FaildReason = { 17 | fileId: string, 18 | expectCode: string | null, 19 | getCode: string | null, 20 | transformError: Error | null, 21 | } 22 | 23 | let allTestCaseCount = 0; 24 | const failedTestCase: Array = [] 25 | 26 | async function readTestCasesParallel() { 27 | const testCaseRoots = await fs.readdir(path.join(__dirname, "./fixtures")); 28 | const testCases = await Promise.all(testCaseRoots.map(async (root)=> { 29 | const [input, output, options ]= await Promise.all([ 30 | fs.readFile(path.join(__dirname, `./fixtures/${root}/input.js`)), 31 | fs.readFile(path.join(__dirname, `./fixtures/${root}/output.js`)), 32 | fs.readFile(path.join(__dirname, `./fixtures/${root}/options.json`)) 33 | .then(result => JSON.parse(result.toString())) 34 | .catch(_error => ({})) 35 | ]); 36 | return { fileId: root, input: input.toString(), output: output.toString(), options} as TestCase 37 | })); 38 | allTestCaseCount = testCases.length; 39 | return testCases 40 | } 41 | 42 | async function matchTestCase(testCase: TestCase) { 43 | return new Promise((resolve, reject) => { 44 | transform( 45 | testCase.input, 46 | { plugins: [ 47 | [ 48 | MyPlugin, 49 | testCase.options 50 | ] 51 | ]}, 52 | (err, result) => { 53 | if(err) { 54 | resolve(result); 55 | failedTestCase.push({ 56 | fileId: testCase.fileId, 57 | expectCode: null, 58 | getCode: null, 59 | transformError: err, 60 | }); 61 | return; 62 | } 63 | if(!result) { 64 | failedTestCase.push({ 65 | fileId: testCase.fileId, 66 | expectCode: null, 67 | getCode: null, 68 | transformError: new Error("transform result not exsied"), 69 | }); 70 | return; 71 | } 72 | if(result.code === testCase.output) { 73 | resolve(result); 74 | return; 75 | } 76 | failedTestCase.push({ 77 | fileId: testCase.fileId, 78 | expectCode: testCase.output, 79 | getCode: result.code || null, 80 | transformError: null, 81 | }); 82 | resolve(result); 83 | }) 84 | }) 85 | } 86 | 87 | function summaryCodeCoverage() { 88 | let misMatchCount = 0; 89 | let babelErrorCount = 0; 90 | if(failedTestCase.length === 0) { 91 | console.log(" ===== All Test Pass ====="); 92 | return; 93 | } 94 | for(const testCase of failedTestCase) { 95 | console.log(` ===== ${testCase.fileId} Failed =====`); 96 | if(testCase.transformError !== null) { 97 | misMatchCount ++; 98 | }else { 99 | babelErrorCount ++; 100 | } 101 | console.log(` ======| reason: ${testCase.transformError !== null ? "babel transform error" : "output missmatch "} `); 102 | } 103 | console.log(" ===== Summary ===== "); 104 | console.log(` ===| pass count : ${allTestCaseCount - misMatchCount - babelErrorCount}/${allTestCaseCount}`); 105 | console.log(` ===| mismatch error : ${misMatchCount}/${allTestCaseCount} `); 106 | console.log(` ===| transform error : ${babelErrorCount}/${allTestCaseCount} `); 107 | } 108 | 109 | async function runAllTestCase() { 110 | const testCases = await readTestCasesParallel(); 111 | await Promise.all(testCases.map(matchTestCase)); 112 | summaryCodeCoverage(); 113 | } 114 | 115 | 116 | runAllTestCase(); -------------------------------------------------------------------------------- /babel-plugin/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const mode = process.env.NODE_ENV || "development"; 3 | const CopyPlugin = require('copy-webpack-plugin'); 4 | 5 | module.exports = { 6 | mode, 7 | target: "node", 8 | entry: "./src/index.ts", 9 | output: { 10 | filename: "index.js", 11 | path: path.join(__dirname, "dist"), 12 | library: { 13 | type: 'commonjs' 14 | } 15 | }, 16 | module: { 17 | rules: [ 18 | { 19 | test: /\.ts/, 20 | exclude: /node_modules/, 21 | use: { 22 | loader: "babel-loader", 23 | options: { 24 | presets: [ 25 | "@babel/preset-typescript", 26 | "@babel/preset-env" 27 | ] 28 | } 29 | }, 30 | 31 | } 32 | ] 33 | }, 34 | plugins: [ 35 | new CopyPlugin({ 36 | patterns: [ 37 | { 38 | from: path.join(__dirname, "node_modules/rustgql_core/rustgql_core_bg.wasm"), 39 | } 40 | ] 41 | }) 42 | ], 43 | optimization: { 44 | minimize: false, 45 | }, 46 | resolve: { 47 | extensions: ['.tsx', '.ts', '.js'] 48 | }, 49 | } -------------------------------------------------------------------------------- /crates/playground/.gitignore: -------------------------------------------------------------------------------- 1 | test.json -------------------------------------------------------------------------------- /crates/playground/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "playground" 3 | authors = ["Solo-steven"] 4 | description = "cli tool for rustql" 5 | version = "0.1.0" 6 | edition = "2021" 7 | license-file = "../../LICENSE" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [dependencies] 12 | rustgql_common = { version = "0.1.0", path = "../rustgql_common"} 13 | rustgql_parser = { version = "0.1.0", path = "../rustgql_parser"} 14 | rustgql_typegen = { version = "0.1.0", path = "../rustgql_typegen"} 15 | rustgql_minifier = { version = "0.1.0", path= "../rustgql_minifier" } 16 | serde = "1.0.183" 17 | serde_derive = "1.0.183" 18 | serde_json = "1.0.104" 19 | 20 | [dev-dependencies] 21 | criterion = { version = "0.4", features = ["html_reports"] } 22 | 23 | [[bench]] 24 | name = "temp_bench" 25 | harness = false 26 | -------------------------------------------------------------------------------- /crates/playground/benches/temp_bench.rs: -------------------------------------------------------------------------------- 1 | use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId}; 2 | use rustgql_parser::parser::Parser; 3 | use rustgql_typegen::graphql_table::GrahpQLTable; 4 | use rustgql_typegen::query_generator::QueryGenerator; 5 | use rustgql_typegen::schema_generator::SchemaGenerator; 6 | 7 | const TINT_FILE_STR: &str = include_str!("../schema.docs.graphql"); 8 | 9 | fn criterion_benchmark(c: &mut Criterion) { 10 | c.bench_with_input( 11 | BenchmarkId::new("rustgql generate simple query type from ", "string of boostrap css"), 12 | &TINT_FILE_STR, 13 | |b, file| { 14 | b.iter(|| { 15 | let github_query = " 16 | query { 17 | viewer { 18 | login 19 | } 20 | } 21 | "; 22 | let mut parser = Parser::new(file); 23 | let schema = parser.parse(); 24 | parser = Parser::new(github_query); 25 | let query_doc = parser.parse(); 26 | let mut table = GrahpQLTable::new(); 27 | table.build_table(&schema); 28 | let mut query_generator = QueryGenerator::new(table); 29 | let mut schema_generator = SchemaGenerator::new(); 30 | let schema_ts = schema_generator.generate(&schema); 31 | let output = query_generator.generate(&query_doc); 32 | }) 33 | } 34 | ); 35 | 36 | } 37 | 38 | criterion_group!(benches, criterion_benchmark); 39 | criterion_main!(benches); -------------------------------------------------------------------------------- /crates/playground/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs::File; 2 | use std::io::Write; 3 | use std::borrow::Cow; 4 | use rustgql_parser::parser::Parser; 5 | use rustgql_typegen::graphql_table::GrahpQLTable; 6 | use rustgql_typegen::query_generator::QueryGenerator; 7 | use rustgql_typegen::schema_generator::SchemaGenerator; 8 | use serde_json::to_string_pretty; 9 | use std::time::Instant; 10 | 11 | const github_str: &str = include_str!("../schema.docs.graphql"); 12 | 13 | fn main(){ 14 | let query_code = r#" 15 | query GetTrack { 16 | tracksForHome { 17 | ...Test, 18 | variant { 19 | ...on PossibleA { 20 | name, 21 | } 22 | ... on PossibleB { 23 | age 24 | node { 25 | id 26 | } 27 | } 28 | } 29 | } 30 | } 31 | fragment Test on Track { 32 | id, 33 | title, 34 | } 35 | "#; 36 | let schema_code = r#" 37 | type Track { 38 | id: ID!, 39 | title: String!, 40 | author: Author!, 41 | tumbnail: String, 42 | length: Int, 43 | modulesCount: Int, 44 | node: [Node], 45 | variant: VariantType 46 | } 47 | scalar Data 48 | type Author { 49 | id: ID!, 50 | name: String!, 51 | photo: String 52 | } 53 | type Query { 54 | tracksForHome: [Track] 55 | } 56 | type Node { 57 | id: ID!, 58 | data: String, 59 | } 60 | union VariantType = PossibleA | PossibleB 61 | 62 | type PossibleA { 63 | name: String, 64 | node: [Node] 65 | } 66 | type PossibleB { 67 | age: Int, 68 | node: [Node] 69 | } 70 | "#; 71 | // let mut parser = Parser::new(query_code); 72 | // let query_document = parser.parse(); 73 | // parser = Parser::new(schema_code); 74 | // let mut query_file = File::create("./query.json").unwrap(); 75 | // write!(query_file, "{}", to_string_pretty(&query_document).unwrap()).unwrap(); 76 | // let schema_doucment = parser.parse(); 77 | // let mut table = GrahpQLTable::new(); 78 | // table.build_table(&schema_doucment); 79 | // println!("{:?}", table); 80 | // let mut query_generator = QueryGenerator::new(table); 81 | // let mut schema_generator = SchemaGenerator::new(); 82 | // let schema_ts = schema_generator.generate(&schema_doucment); 83 | // let output = query_generator.generate(&query_document); 84 | // println!("{:?}", output); 85 | // let mut query_type_file = File::create("./type.d.ts").unwrap(); 86 | // write!(query_type_file, "{}\n {}", output.as_str(), schema_ts.as_str()).unwrap(); 87 | 88 | // let github_query = " 89 | // query { 90 | // viewer { 91 | // login 92 | // } 93 | // } 94 | // "; 95 | // let now = Instant::now(); 96 | // let mut parser = Parser::new(github_str); 97 | // let schema = parser.parse(); 98 | // parser = Parser::new(github_query); 99 | // let query_doc = parser.parse(); 100 | // let mut table = GrahpQLTable::new(); 101 | // table.build_table(&schema); 102 | // let mut query_generator = QueryGenerator::new(table); 103 | // let mut schema_generator = SchemaGenerator::new(); 104 | // let schema_ts = schema_generator.generate(&schema); 105 | // let output = query_generator.generate(&query_doc); 106 | // println!("{:?}", output); 107 | // let mut query_type_file = File::create("./type.d.ts").unwrap(); 108 | // write!(query_type_file, "{}\n{}\n{}", QueryGenerator::generate_default(), output.as_str(), schema_ts.as_str()).unwrap(); 109 | // println!("cost: {}", (now.elapsed().as_nanos() as f64) / 1000.0 / 1000.0); 110 | 111 | let min = r#" 112 | query GetUser($uuid: String = "RUSTQL_SYMBOL") { 113 | name 114 | age 115 | } 116 | "#; 117 | let mut parser = Parser::new(min); 118 | let doc = parser.parse(); 119 | let mut minifier = rustgql_minifier::query_minifier::QueryMinifier::new(); 120 | println!("{:?}", minifier.generate(&doc)); 121 | } -------------------------------------------------------------------------------- /crates/rustgql_cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustgql_cli" 3 | authors = ["Solo-steven"] 4 | description = "cli tool for rustql" 5 | version = "0.1.0" 6 | edition = "2021" 7 | license-file = "../../LICENSE" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [dependencies] 12 | clap = { version = "4.3.21", features = ["derive"] } 13 | rustgql_common = { version = "0.1.0", path = "../rustgql_common"} 14 | rustgql_parser = { version = "0.1.0", path = "../rustgql_parser"} 15 | rustgql_typegen = { version = "0.1.0", path = "../rustgql_typegen"} 16 | 17 | [dev-dependencies] 18 | criterion = { version = "0.4", features = ["html_reports"] } 19 | serde = "1.0.183" 20 | serde_derive = "1.0.183" 21 | serde_json = "1.0.104" 22 | -------------------------------------------------------------------------------- /crates/rustgql_cli/src/codegen.rs: -------------------------------------------------------------------------------- 1 | use rustgql_parser::parser::Parser; 2 | use rustgql_typegen::schema_generator::SchemaGenerator; 3 | 4 | pub fn generate_type_string_from_input(input: &str) -> String { 5 | let mut parser = Parser::new(input); 6 | let document = parser.parse(); 7 | let mut codegen = SchemaGenerator::new(); 8 | codegen.generate(&document) 9 | } -------------------------------------------------------------------------------- /crates/rustgql_cli/src/main.rs: -------------------------------------------------------------------------------- 1 | mod codegen; 2 | use std::path::PathBuf; 3 | use std::fs::{read_to_string, File}; 4 | use std::io::Write; 5 | use clap::{Parser,command}; 6 | 7 | use codegen::*; 8 | 9 | #[derive(Parser)] 10 | #[command(author="Solo-steven")] 11 | #[command(name="rustql-cli")] 12 | #[command(version = "0.1.0")] 13 | struct Application { 14 | #[arg(long, short)] 15 | input: PathBuf, 16 | #[arg(long, short)] 17 | output: Option, 18 | #[arg(long, short)] 19 | name: Option 20 | } 21 | 22 | fn main() { 23 | let app = Application::parse(); 24 | let file_name = match app.name { 25 | Some(name) => name, 26 | None => String::from("type.d.ts") 27 | }; 28 | let output_file_path = match app.output { 29 | Some(file_path ) => file_path, 30 | None => PathBuf::from(format!("./{}", file_name)), 31 | }; 32 | let input_file_string = match read_to_string(&app.input) { 33 | Ok(file_path) => file_path, 34 | Err(_reason) => panic!("[Error]: Can not read the input file ({:?})", &app.input) 35 | }; 36 | let output_string = generate_type_string_from_input(input_file_string.as_str()); 37 | let output_file = match File::create(&output_file_path) { 38 | Ok(file) => file, 39 | Err(_) => panic!("[Error]: Can not create the output file ({:?})", &output_file_path), 40 | }; 41 | match write!(&output_file, "{}", output_string) { 42 | Ok(_) => {}, 43 | Err(_) => panic!("[Error]: Can not write to the output file") 44 | } 45 | } -------------------------------------------------------------------------------- /crates/rustgql_common/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustgql_common" 3 | description = "ast and common type for rustgql packages" 4 | authors = ["Solo-steven"] 5 | version = "0.1.0" 6 | edition = "2021" 7 | license-file = "../../LICENSE" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [dependencies] 12 | serde = "1.0.183" 13 | serde_derive = "1.0.183" 14 | serde_json = "1.0.104" 15 | -------------------------------------------------------------------------------- /crates/rustgql_common/src/ast/common.rs: -------------------------------------------------------------------------------- 1 | use std::borrow::Cow; 2 | use serde_derive::{Deserialize, Serialize}; 3 | use crate::position::Span; 4 | use crate::ast::query::*; 5 | use crate::ast::schema::*; 6 | // use crate::position::Position; 7 | 8 | /* ========== Common AST Type ========== */ 9 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 10 | #[serde(tag="type")] 11 | pub enum Value<'a> { 12 | Variable(Variable<'a>), 13 | IntValue(IntValue<'a>), 14 | FloatValue(FloatValue<'a>), 15 | StringValue(StringValue<'a>), 16 | BooleanValue(BoolValue<'a>), 17 | NullValue(NullValue), 18 | ListValue(ListValue<'a>), 19 | ObjectValue(ObjectValue<'a>), 20 | EnumValue(EnumValue<'a>) 21 | } 22 | 23 | pub fn get_value_span(value: &Value) -> Span { 24 | match value { 25 | Value::Variable(value) => value.span.clone(), 26 | Value::IntValue(value) => value.span.clone(), 27 | Value::FloatValue(value) => value.span.clone(), 28 | Value::StringValue(value) => value.span.clone(), 29 | Value::BooleanValue(value) => value.span.clone(), 30 | Value::NullValue(value) => value.span.clone(), 31 | Value::ListValue(value) => value.span.clone(), 32 | Value::ObjectValue(value) => value.span.clone(), 33 | Value::EnumValue(value) => value.span.clone(), 34 | } 35 | } 36 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 37 | pub struct Variable<'a> { 38 | pub code: Cow<'a, str>, 39 | pub span: Span 40 | } 41 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 42 | pub struct IntValue<'a> { 43 | pub code: Cow<'a, str>, 44 | pub span: Span, 45 | } 46 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 47 | pub struct FloatValue<'a> { 48 | pub code: Cow<'a, str>, 49 | pub span: Span, 50 | } 51 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 52 | pub struct StringValue<'a> { 53 | pub code: Cow<'a, str>, 54 | pub span: Span, 55 | pub is_block: bool 56 | } 57 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 58 | pub struct BoolValue<'a> { 59 | pub code: Cow<'a, str>, 60 | pub span: Span, 61 | } 62 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 63 | pub struct NullValue { 64 | pub span: Span, 65 | } 66 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 67 | pub struct EnumValue<'a> { 68 | pub code: Cow<'a, str>, 69 | pub span: Span, 70 | } 71 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 72 | pub struct ListValue<'a> { 73 | pub values: Vec>, 74 | pub span: Span, 75 | } 76 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 77 | pub struct ObjectValue<'a> { 78 | pub fields: Vec>, 79 | pub span: Span, 80 | } 81 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 82 | #[serde(tag="type")] 83 | pub struct Name<'a> { 84 | pub value: Cow<'a, str>, 85 | pub span: Span, 86 | } 87 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 88 | #[serde(tag="type")] 89 | pub enum VarType<'a> { 90 | NameVarType(NameVarType<'a>), 91 | ListVarType(ListVarType<'a>), 92 | NonNullVarType(NonNullType<'a>) 93 | } 94 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 95 | pub struct NameVarType<'a> { 96 | pub name: Cow<'a, str>, 97 | pub span: Span, 98 | } 99 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 100 | pub struct ListVarType<'a> { 101 | pub list_type: Box> 102 | } 103 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 104 | pub struct NonNullType<'a> { 105 | pub nonull_type: Box> 106 | } 107 | pub fn get_type_span(some_type: &VarType) -> Span { 108 | match some_type { 109 | VarType::NameVarType(name_type) => name_type.span.clone(), 110 | VarType::ListVarType(list_type) => get_type_span(list_type.list_type.as_ref()), 111 | VarType::NonNullVarType(nonull_type) => get_type_span(nonull_type.nonull_type.as_ref()) 112 | } 113 | } 114 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 115 | #[serde(tag="type")] 116 | pub struct Argument<'a> { 117 | pub name: Name<'a>, 118 | pub value: Value<'a>, 119 | pub span: Span, 120 | } 121 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 122 | #[serde(tag="type")] 123 | pub struct ObjectField<'a> { 124 | pub name: Name<'a>, 125 | pub value: Value<'a>, 126 | } 127 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 128 | #[serde(tag="type")] 129 | pub struct Directive<'a> { 130 | pub name: Name<'a>, 131 | pub arguments: Option>>, 132 | pub span: Span, 133 | } 134 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 135 | #[serde(tag="type")] 136 | pub struct Document<'a> { 137 | pub definations: Vec>, 138 | } 139 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 140 | #[serde(tag="type")] 141 | pub enum Defination<'a> { 142 | // type system defination 143 | SchemaTypeDefination(SchmaTypeDefination<'a>), 144 | DirectiveDefination(DirectiveDefinition<'a>), 145 | ScalarTypeDefinition(ScalarTypeDefinition<'a>), 146 | ObjectTypeDefinition(ObjectTypeDefinition<'a>), 147 | InterfaceTypeDefinition(InterfaceTypeDefinition<'a>), 148 | UnionTypeDefinition(UnionTypeDefinition<'a>), 149 | EnumTypeDefinition(EnumTypeDefinition<'a>), 150 | InputObjectTypeDefinition(InputObjectTypeDefinition<'a>), 151 | // type extension defination 152 | SchemaTypeExtension(SchemaTypeExtension<'a>), 153 | ScalarTypeExtension(ScalarTypeExtension<'a>), 154 | ObjectTypeExtension(ObjectTypeExtension<'a>), 155 | InterfaceTypeExtension(InterfaceTypeExtension<'a>), 156 | UnionTypeExtension(UnionTypeExtension<'a>), 157 | EnumTypeExtension(EnumTypeExtension<'a>), 158 | InputObjectTypeExtension(InputObjectTypeExtension<'a>), 159 | // operation defination 160 | SelectSet(SelectSet<'a>), 161 | Query(Query<'a>), 162 | Mutation(Mutation<'a>), 163 | Subscription(Subscription<'a>), 164 | // fragment defination 165 | FragmentDefination(FragmentDefination<'a>), 166 | } -------------------------------------------------------------------------------- /crates/rustgql_common/src/ast/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod common; 2 | pub mod query; 3 | pub mod schema; -------------------------------------------------------------------------------- /crates/rustgql_common/src/ast/query.rs: -------------------------------------------------------------------------------- 1 | use serde_derive::{Deserialize, Serialize}; 2 | use crate::position::Span; 3 | use crate::ast::common::*; 4 | 5 | /* ============ Document AST Type ========== */ 6 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 7 | pub struct FragmentDefination<'a> { 8 | pub name: Name<'a>, 9 | pub type_condition: VarType<'a>, 10 | pub directives: Option>>, 11 | pub selectionset: SelectSet<'a>, 12 | pub span: Span, 13 | } 14 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 15 | pub struct Query<'a> { 16 | pub name: Option>, 17 | pub variable_definations: Option>>, 18 | pub directives: Option>>, 19 | pub selectionset: SelectSet<'a>, 20 | pub span: Span, 21 | } 22 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 23 | pub struct Mutation<'a> { 24 | pub name:Option>, 25 | pub variable_definations: Option>>, 26 | pub directives: Option>>, 27 | pub selectionset: SelectSet<'a>, 28 | pub span: Span, 29 | } 30 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 31 | pub struct Subscription<'a> { 32 | pub name: Option>, 33 | pub variable_definations: Option>>, 34 | pub directives: Option>>, 35 | pub selectionset: SelectSet<'a>, 36 | pub span: Span, 37 | } 38 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 39 | #[serde(tag="type")] 40 | pub struct VariableDefination<'a> { 41 | pub name: Name<'a>, 42 | pub var_type: VarType<'a>, 43 | pub default_value: Option>, 44 | pub span: Span, 45 | } 46 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 47 | pub struct SelectSet<'a> { 48 | pub selections: Vec>, 49 | pub span: Span, 50 | } 51 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 52 | #[serde(tag="type")] 53 | pub enum Selection<'a> { 54 | Field(Field<'a>), 55 | FragmentSpread(FragmentSpread<'a>), 56 | InlineFragment(InlineFragment<'a>), 57 | } 58 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 59 | pub struct Field<'a> { 60 | pub alias: Option>, 61 | pub name: Name<'a>, 62 | pub arguments: Option>>, 63 | pub directives: Option>>, 64 | pub selectionset: Option>, 65 | pub span: Span 66 | } 67 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 68 | pub struct FragmentSpread<'a> { 69 | pub name: Name<'a>, 70 | pub directives: Option>>, 71 | pub span: Span 72 | } 73 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 74 | pub struct InlineFragment<'a> { 75 | pub type_condition: Option>, 76 | pub directives: Option>>, 77 | pub selectionset: SelectSet<'a>, 78 | pub span: Span 79 | } -------------------------------------------------------------------------------- /crates/rustgql_common/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod ast; 2 | pub mod position; 3 | pub mod token; -------------------------------------------------------------------------------- /crates/rustgql_common/src/position.rs: -------------------------------------------------------------------------------- 1 | use serde_derive::{Deserialize, Serialize}; 2 | #[derive(Debug, Clone, PartialEq, Deserialize ,Serialize)] 3 | pub struct Position { 4 | pub col: usize, 5 | pub row: usize, 6 | pub index: usize, 7 | } 8 | impl Default for Position { 9 | fn default() -> Self { 10 | Self::new() 11 | } 12 | } 13 | impl Position { 14 | pub fn new() -> Self { 15 | Self { 16 | col: 0, row: 0, index: 0 17 | } 18 | } 19 | } 20 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 21 | pub struct Span { 22 | pub start: Position, 23 | pub end: Position, 24 | } 25 | impl Span { 26 | pub fn new(start_pos: Position, end_pos: Position) -> Self { 27 | Self { 28 | start: start_pos, end: end_pos 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /crates/rustgql_common/src/token.rs: -------------------------------------------------------------------------------- 1 | use serde_derive::{Deserialize, Serialize}; 2 | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] 3 | pub enum TokenKind { 4 | /* Start and EOF */ 5 | Start, 6 | EOFToken, 7 | /* Punctuator */ 8 | Point, // ! 9 | DollarSign, // $ 10 | ParenthesesLeft, // ( 11 | ParenthesesRight, // ) 12 | Ellipsis, // ... 13 | Colon, // : 14 | Eqal, // = 15 | At, // @ 16 | BracketLeft, // [ 17 | BracketRight, // ] 18 | BracesLeft, // { 19 | Pipe, // | 20 | BracesRight, // } 21 | And, // & (not in the spec, but need it) 22 | /* Name */ 23 | Name, 24 | /* IntValue */ 25 | IntValue, 26 | /* FloatValue */ 27 | FloatValue, 28 | /* StringValue */ 29 | StringValue, 30 | /* BlockStringValue */ 31 | BlockString, 32 | /* Comment */ 33 | Comment, 34 | } -------------------------------------------------------------------------------- /crates/rustgql_core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustgql_core" 3 | authors = ["Solo-steven"] 4 | description = "core api for rustgql" 5 | version = "0.1.1" 6 | edition = "2021" 7 | license = "MIT" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | [lib] 11 | crate-type = ["cdylib", "rlib"] 12 | 13 | [dependencies] 14 | rustgql_common = { version = "0.1.0", path = "../rustgql_common"} 15 | rustgql_parser = { version = "0.1.0", path = "../rustgql_parser"} 16 | rustgql_typegen = { version = "0.1.0", path = "../rustgql_typegen"} 17 | rustgql_minifier = { version = "0.1.0", path= "../rustgql_minifier" } 18 | wasm-bindgen = "0.2.87" 19 | 20 | [dev-dependencies] 21 | criterion = { version = "0.4", features = ["html_reports"] } 22 | serde = "1.0.183" 23 | serde_derive = "1.0.183" 24 | serde_json = "1.0.104" 25 | -------------------------------------------------------------------------------- /crates/rustgql_core/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Steven 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /crates/rustgql_core/README.md: -------------------------------------------------------------------------------- 1 | # rustgql core 2 | 3 | this crate provide some wasm api for JavaScript env. 4 | -------------------------------------------------------------------------------- /crates/rustgql_core/src/lib.rs: -------------------------------------------------------------------------------- 1 | use rustgql_parser::parser::Parser; 2 | use rustgql_minifier::query_minifier::QueryMinifier; 3 | use rustgql_typegen::graphql_table::GrahpQLTable; 4 | use rustgql_typegen::query_generator::QueryGenerator; 5 | use rustgql_typegen::schema_generator::SchemaGenerator; 6 | use wasm_bindgen::prelude::*; 7 | 8 | #[wasm_bindgen] 9 | pub fn minify_query(code: &str) -> String { 10 | let mut parser = Parser::new(code); 11 | let document = parser.parse(); 12 | let mut query_minifier = QueryMinifier::new(); 13 | query_minifier.generate(&document) 14 | } 15 | 16 | #[wasm_bindgen] 17 | pub fn generate_typescript_for_query(document_code: &str, query_code: &str) -> String { 18 | let mut schema_parser = Parser::new(document_code); 19 | let mut query_parser = Parser::new(query_code); 20 | let schema_document = schema_parser.parse(); 21 | let query_document = query_parser.parse(); 22 | let mut grahpql_table = GrahpQLTable::new(); 23 | grahpql_table.build_table(&schema_document); 24 | let mut query_generator = QueryGenerator::new(grahpql_table); 25 | let mut schena_generator = SchemaGenerator::new(); 26 | format!("{}\n{}\n{}", SchemaGenerator::generate_default(), schena_generator.generate(&schema_document), query_generator.generate(&query_document)) 27 | } -------------------------------------------------------------------------------- /crates/rustgql_minifier/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustgql_minifier" 3 | authors = ["Solo-steven"] 4 | description = "generate graphql from graphql schma" 5 | version = "0.1.0" 6 | edition = "2021" 7 | license-file = "../../LICENSE" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [dependencies] 12 | rustgql_common = { version = "0.1.0", path = "../rustgql_common"} 13 | 14 | [dev-dependencies] 15 | rustgql_parser = { version = "0.1.0", path = "../rustgql_parser"} 16 | criterion = { version = "0.4", features = ["html_reports"] } 17 | serde = "1.0.183" 18 | serde_derive = "1.0.183" 19 | serde_json = "1.0.104" 20 | -------------------------------------------------------------------------------- /crates/rustgql_minifier/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod query_minifier; -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/directive_args.graphql: -------------------------------------------------------------------------------- 1 | query{node@dir(a:1,b:"2"c:true,d:false,e:null)} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/directive_args_multiline.graphql: -------------------------------------------------------------------------------- 1 | query{node@dir(a:1,b:"2"c:true,d:false,e:null)} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/fragment.graphql: -------------------------------------------------------------------------------- 1 | fragement frag on Friend{node} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/fragment_spread.graphql: -------------------------------------------------------------------------------- 1 | query{node{id...something}} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/inline_fragment.graphql: -------------------------------------------------------------------------------- 1 | query{node{id...on User{name}}} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/inline_fragment_dir.graphql: -------------------------------------------------------------------------------- 1 | query{node{id...on User@defer{name}}} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/kitchen-sink.graphql: -------------------------------------------------------------------------------- 1 | query queryName($foo:ComplexType$site:Site=MOBILE){whoever123is:node(id:[123,456]){id...on User@defer{field2{id,alias:field1(first:10,after:$foo)@include(if:$foo){id...frag}}}...@skip(unless:$foo){id}...{id}}}mutation likeStory{like(story:123)@defer{story{id}}}subscription StoryLikeSubscription($input:StoryLikeSubscribeInput){storyLikeSubscribe(input:$input){story{likers{count},likeSentence{text}}}}fragement frag on Friend{foo(size:$size,bar:$b,obj:{key:"value"block:""" 2 | 3 | block string uses \""" 4 | 5 | """})}{unnamed(truthy:true,falsey:false,nullish:null),query} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/kitchen-sink_canonical.graphql: -------------------------------------------------------------------------------- 1 | query queryName($foo:ComplexType$site:Site=MOBILE){whoever123is:node(id:[123,456]){id...on User@defer{field2{id,alias:field1(first:10,after:$foo)@include(if:$foo){id...frag}}}...@skip(unless:$foo){id}...{id}}}mutation likeStory{like(story:123)@defer{story{id}}}subscription StoryLikeSubscription($input:StoryLikeSubscribeInput){storyLikeSubscribe(input:$input){story{likers{count},likeSentence{text}}}}fragement frag on Friend{foo(size:$size,bar:$b,obj:{block:""" 2 | 3 | block string uses \""" 4 | 5 | """key:"value"})}{unnamed(truthy:true,falsey:false,nullish:null),query} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/minimal.graphql: -------------------------------------------------------------------------------- 1 | {a} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/minimal_mutation.graphql: -------------------------------------------------------------------------------- 1 | mutation{notify} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/minimal_query.graphql: -------------------------------------------------------------------------------- 1 | query{node} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/mutation_directive.graphql: -------------------------------------------------------------------------------- 1 | mutation@directive{node} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/mutation_nameless_vars.graphql: -------------------------------------------------------------------------------- 1 | mutation($first:Int$second:Int){field1(first:$first),field2(second:$second)} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/named_query.graphql: -------------------------------------------------------------------------------- 1 | query Foo{field} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/nested_selection.graphql: -------------------------------------------------------------------------------- 1 | query{node{id}} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_aliases.graphql: -------------------------------------------------------------------------------- 1 | query{an_alias:node} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_arguments.graphql: -------------------------------------------------------------------------------- 1 | query{node(id:1)} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_arguments_multiline.graphql: -------------------------------------------------------------------------------- 1 | query{node(id:1),node(id:1,one:3)} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_array_argument_multiline.graphql: -------------------------------------------------------------------------------- 1 | query{node(id:[5,6,7])} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_directive.graphql: -------------------------------------------------------------------------------- 1 | query@directive{node} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_list_argument.graphql: -------------------------------------------------------------------------------- 1 | query{node(id:1,list:[123,456])} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_nameless_vars.graphql: -------------------------------------------------------------------------------- 1 | query($first:Int$second:Int){field1(first:$first),field2(second:$second)} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_nameless_vars_multiple_fields.graphql: -------------------------------------------------------------------------------- 1 | query($houseId:String!$streetNumber:Int!){house(id:$houseId){id,name,lat,lng},street(number:$streetNumber){id},houseStreet(id:$houseId,number:$streetNumber){id}} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_nameless_vars_multiple_fields_canonical.graphql: -------------------------------------------------------------------------------- 1 | query($houseId:String!$streetNumber:Int!){house(id:$houseId){id,name,lat,lng},street(number:$streetNumber){id},houseStreet(id:$houseId,number:$streetNumber){id}} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_object_argument.graphql: -------------------------------------------------------------------------------- 1 | query{node(id:1,obj:{key1:123,key2:456})} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_object_argument_multiline.graphql: -------------------------------------------------------------------------------- 1 | query{node(id:1,obj:{key1:123,key2:456})} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_var_default_float.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site:Float=0.5){field} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_var_default_list.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site:[Int]=[123,456]){field} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_var_default_object.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site:Site={url:null}){field} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_var_default_string.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site:String="string"){field} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_var_defaults.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site:Site=MOBILE){field} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/query_vars.graphql: -------------------------------------------------------------------------------- 1 | query Foo($arg:SomeType){field} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/string_literal.graphql: -------------------------------------------------------------------------------- 1 | query{node(id:"hello")} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/subscription_directive.graphql: -------------------------------------------------------------------------------- 1 | subscription@directive{node} -------------------------------------------------------------------------------- /crates/rustgql_minifier/tests/fixtures/graphql_rust/query/triple_quoted_literal.graphql: -------------------------------------------------------------------------------- 1 | query{node(id:""" 2 | Hello, 3 | world! 4 | """)} -------------------------------------------------------------------------------- /crates/rustgql_parser/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustgql_parser" 3 | authors = ["Solo-steven"] 4 | description = "rustql parser for graphql" 5 | version = "0.1.0" 6 | edition = "2021" 7 | license-file = "../../LICENSE" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [dependencies] 12 | rustgql_common = { version = "0.1.0", path = "../rustgql_common"} 13 | 14 | [dev-dependencies] 15 | criterion = { version = "0.4", features = ["html_reports"] } 16 | serde_json = "1.0.104" 17 | graphql-parser = "0.4.0" 18 | 19 | [[bench]] 20 | name = "parser_benches" 21 | harness = false -------------------------------------------------------------------------------- /crates/rustgql_parser/benches/parser_benches.rs: -------------------------------------------------------------------------------- 1 | use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId}; 2 | use rustgql_parser::parser::Parser; 3 | use graphql_parser::{parse_schema, parse_query}; 4 | 5 | const GIHTUB_SCHEMA: &str = include_str!("../../../fixtures/graphql_github/schema.docs.graphql"); 6 | const SIMPLE_QUERY: &str = include_str!("../../../fixtures/graphql_rust/query/kitchen-sink_canonical.graphql"); 7 | 8 | fn criterion_benchmark(c: &mut Criterion) { 9 | c.bench_with_input( 10 | BenchmarkId::new("rustgql parse github graphql schema", "string of github GraphQL schema"), 11 | &GIHTUB_SCHEMA, 12 | |b, file| { 13 | b.iter(|| { 14 | let mut parser = Parser::new(file); 15 | parser.parse(); 16 | }) 17 | } 18 | ); 19 | c.bench_with_input( 20 | BenchmarkId::new("graphql-rust parse github graphql schema", "string of github GraphQL schema"), 21 | &GIHTUB_SCHEMA, 22 | |b, file| { 23 | b.iter(|| { 24 | parse_schema::<&str>(file).unwrap(); 25 | }) 26 | } 27 | ); 28 | c.bench_with_input( 29 | BenchmarkId::new("rustgql parse simple query", "simple query string"), 30 | &SIMPLE_QUERY, 31 | |b, file| { 32 | b.iter(|| { 33 | let mut parser = Parser::new(file); 34 | parser.parse(); 35 | }) 36 | } 37 | ); 38 | c.bench_with_input( 39 | BenchmarkId::new("graphql-rust parse simple query", "simple query string"), 40 | &SIMPLE_QUERY, 41 | |b, file| { 42 | b.iter(|| { 43 | parse_query::<&str>(file).unwrap(); 44 | }) 45 | } 46 | ); 47 | 48 | } 49 | 50 | criterion_group!(benches, criterion_benchmark); 51 | criterion_main!(benches); -------------------------------------------------------------------------------- /crates/rustgql_parser/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod marco; 2 | pub mod lexer; 3 | pub mod parser; -------------------------------------------------------------------------------- /crates/rustgql_parser/src/marco.rs: -------------------------------------------------------------------------------- 1 | #[macro_export] 2 | macro_rules! lexer_error { 3 | ($message: expr, $lexer: expr) => { 4 | let pos = $lexer.get_pos(); 5 | match $lexer.get_char() { 6 | Some(ch) => { 7 | panic!("[Syntax Error]: Unexecpt Charater {:?} {:?}, at ({:?}, {:?}).", ch, $message , pos.row, pos.col ); 8 | } 9 | None => { 10 | panic!("[Syntax Error]: Unexecpt EOF {:?}, at ({:?}, {:?})", $message, pos.row, pos.col ); 11 | } 12 | } 13 | }; 14 | } 15 | #[macro_export] 16 | macro_rules! internal_error { 17 | ($message: expr) => { 18 | panic!("[Internal Error]: {:?}, please report this bug to developer, Thanks ~", $message) 19 | }; 20 | } 21 | #[macro_export] 22 | macro_rules! is_keyword_name { 23 | ($expect_value: expr, $parser: expr) => {{ 24 | match $parser.get_token() { 25 | TokenKind::Name => { 26 | match $parser.get_value() { 27 | $expect_value => { 28 | true 29 | } 30 | _ => { false } 31 | } 32 | } 33 | _ => { false } 34 | } 35 | }}; 36 | } 37 | #[macro_export] 38 | macro_rules! expect_keyword_name { 39 | ($expect_value: expr, $parser: expr) => {{ 40 | match $parser.get_token() { 41 | TokenKind::Name => { 42 | match $parser.get_value() { 43 | $expect_value => $parser.next_token(), 44 | _ => parser_error!(format!("expect name token with {:?}, value.", $parser.get_token()), $parser) 45 | } 46 | } 47 | _ => parser_error!(format!("expect name token with {:?}, value.", $parser.get_token()), $parser) 48 | } 49 | }}; 50 | } 51 | #[macro_export] 52 | macro_rules! parser_error { 53 | ($msg: expr, $parser: expr) => {{ 54 | let pos = $parser.get_start_pos(); 55 | panic!("[Syntax Error]: Unexpect Token {:?}, {} at ({:?}, {:?}).", $parser.get_token(), $msg, pos.row, pos.col); 56 | }}; 57 | } 58 | #[macro_export] 59 | macro_rules! sematic_error { 60 | ($msg: expr, $parser: expr) => {{ 61 | let pos = $parser.get_start_pos(); 62 | panic!("[Syntax Error]: {} at ({:?}, {:?}).", $msg, pos.row, pos.col); 63 | }}; 64 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/fragment.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "FragmentDefination", 6 | "name": { 7 | "type": "Name", 8 | "value": "frag", 9 | "span": { 10 | "start": { 11 | "col": 9, 12 | "row": 0, 13 | "index": 9 14 | }, 15 | "end": { 16 | "col": 13, 17 | "row": 0, 18 | "index": 13 19 | } 20 | } 21 | }, 22 | "type_condition": { 23 | "type": "NameVarType", 24 | "name": "Friend", 25 | "span": { 26 | "start": { 27 | "col": 17, 28 | "row": 0, 29 | "index": 17 30 | }, 31 | "end": { 32 | "col": 23, 33 | "row": 0, 34 | "index": 23 35 | } 36 | } 37 | }, 38 | "directives": null, 39 | "selectionset": { 40 | "selections": [ 41 | { 42 | "type": "Field", 43 | "alias": null, 44 | "name": { 45 | "type": "Name", 46 | "value": "node", 47 | "span": { 48 | "start": { 49 | "col": 2, 50 | "row": 1, 51 | "index": 28 52 | }, 53 | "end": { 54 | "col": 6, 55 | "row": 1, 56 | "index": 32 57 | } 58 | } 59 | }, 60 | "arguments": null, 61 | "directives": null, 62 | "selectionset": null, 63 | "span": { 64 | "start": { 65 | "col": 2, 66 | "row": 1, 67 | "index": 28 68 | }, 69 | "end": { 70 | "col": 6, 71 | "row": 1, 72 | "index": 32 73 | } 74 | } 75 | } 76 | ], 77 | "span": { 78 | "start": { 79 | "col": 24, 80 | "row": 0, 81 | "index": 24 82 | }, 83 | "end": { 84 | "col": 1, 85 | "row": 2, 86 | "index": 34 87 | } 88 | } 89 | }, 90 | "span": { 91 | "start": { 92 | "col": 0, 93 | "row": 0, 94 | "index": 0 95 | }, 96 | "end": { 97 | "col": 1, 98 | "row": 2, 99 | "index": 34 100 | } 101 | } 102 | } 103 | ] 104 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/fragment_spread.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": null, 14 | "name": { 15 | "type": "Name", 16 | "value": "node", 17 | "span": { 18 | "start": { 19 | "col": 2, 20 | "row": 1, 21 | "index": 10 22 | }, 23 | "end": { 24 | "col": 6, 25 | "row": 1, 26 | "index": 14 27 | } 28 | } 29 | }, 30 | "arguments": null, 31 | "directives": null, 32 | "selectionset": { 33 | "selections": [ 34 | { 35 | "type": "Field", 36 | "alias": null, 37 | "name": { 38 | "type": "Name", 39 | "value": "id", 40 | "span": { 41 | "start": { 42 | "col": 4, 43 | "row": 2, 44 | "index": 21 45 | }, 46 | "end": { 47 | "col": 6, 48 | "row": 2, 49 | "index": 23 50 | } 51 | } 52 | }, 53 | "arguments": null, 54 | "directives": null, 55 | "selectionset": null, 56 | "span": { 57 | "start": { 58 | "col": 4, 59 | "row": 2, 60 | "index": 21 61 | }, 62 | "end": { 63 | "col": 6, 64 | "row": 2, 65 | "index": 23 66 | } 67 | } 68 | }, 69 | { 70 | "type": "FragmentSpread", 71 | "name": { 72 | "type": "Name", 73 | "value": "something", 74 | "span": { 75 | "start": { 76 | "col": 7, 77 | "row": 3, 78 | "index": 31 79 | }, 80 | "end": { 81 | "col": 16, 82 | "row": 3, 83 | "index": 40 84 | } 85 | } 86 | }, 87 | "directives": null, 88 | "span": { 89 | "start": { 90 | "col": 4, 91 | "row": 3, 92 | "index": 28 93 | }, 94 | "end": { 95 | "col": 3, 96 | "row": 4, 97 | "index": 44 98 | } 99 | } 100 | } 101 | ], 102 | "span": { 103 | "start": { 104 | "col": 7, 105 | "row": 1, 106 | "index": 15 107 | }, 108 | "end": { 109 | "col": 3, 110 | "row": 4, 111 | "index": 44 112 | } 113 | } 114 | }, 115 | "span": { 116 | "start": { 117 | "col": 2, 118 | "row": 1, 119 | "index": 10 120 | }, 121 | "end": { 122 | "col": 3, 123 | "row": 4, 124 | "index": 44 125 | } 126 | } 127 | } 128 | ], 129 | "span": { 130 | "start": { 131 | "col": 6, 132 | "row": 0, 133 | "index": 6 134 | }, 135 | "end": { 136 | "col": 1, 137 | "row": 5, 138 | "index": 46 139 | } 140 | } 141 | }, 142 | "span": { 143 | "start": { 144 | "col": 0, 145 | "row": 0, 146 | "index": 0 147 | }, 148 | "end": { 149 | "col": 1, 150 | "row": 5, 151 | "index": 46 152 | } 153 | } 154 | } 155 | ] 156 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/minimal.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "SelectSet", 6 | "selections": [ 7 | { 8 | "type": "Field", 9 | "alias": null, 10 | "name": { 11 | "type": "Name", 12 | "value": "a", 13 | "span": { 14 | "start": { 15 | "col": 2, 16 | "row": 1, 17 | "index": 4 18 | }, 19 | "end": { 20 | "col": 3, 21 | "row": 1, 22 | "index": 5 23 | } 24 | } 25 | }, 26 | "arguments": null, 27 | "directives": null, 28 | "selectionset": null, 29 | "span": { 30 | "start": { 31 | "col": 2, 32 | "row": 1, 33 | "index": 4 34 | }, 35 | "end": { 36 | "col": 3, 37 | "row": 1, 38 | "index": 5 39 | } 40 | } 41 | } 42 | ], 43 | "span": { 44 | "start": { 45 | "col": 0, 46 | "row": 0, 47 | "index": 0 48 | }, 49 | "end": { 50 | "col": 1, 51 | "row": 2, 52 | "index": 7 53 | } 54 | } 55 | } 56 | ] 57 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/minimal_mutation.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Mutation", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": null, 14 | "name": { 15 | "type": "Name", 16 | "value": "notify", 17 | "span": { 18 | "start": { 19 | "col": 2, 20 | "row": 1, 21 | "index": 13 22 | }, 23 | "end": { 24 | "col": 8, 25 | "row": 1, 26 | "index": 19 27 | } 28 | } 29 | }, 30 | "arguments": null, 31 | "directives": null, 32 | "selectionset": null, 33 | "span": { 34 | "start": { 35 | "col": 2, 36 | "row": 1, 37 | "index": 13 38 | }, 39 | "end": { 40 | "col": 8, 41 | "row": 1, 42 | "index": 19 43 | } 44 | } 45 | } 46 | ], 47 | "span": { 48 | "start": { 49 | "col": 9, 50 | "row": 0, 51 | "index": 9 52 | }, 53 | "end": { 54 | "col": 1, 55 | "row": 2, 56 | "index": 21 57 | } 58 | } 59 | }, 60 | "span": { 61 | "start": { 62 | "col": 0, 63 | "row": 0, 64 | "index": 0 65 | }, 66 | "end": { 67 | "col": 1, 68 | "row": 2, 69 | "index": 21 70 | } 71 | } 72 | } 73 | ] 74 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/minimal_query.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": null, 14 | "name": { 15 | "type": "Name", 16 | "value": "node", 17 | "span": { 18 | "start": { 19 | "col": 2, 20 | "row": 1, 21 | "index": 10 22 | }, 23 | "end": { 24 | "col": 6, 25 | "row": 1, 26 | "index": 14 27 | } 28 | } 29 | }, 30 | "arguments": null, 31 | "directives": null, 32 | "selectionset": null, 33 | "span": { 34 | "start": { 35 | "col": 2, 36 | "row": 1, 37 | "index": 10 38 | }, 39 | "end": { 40 | "col": 6, 41 | "row": 1, 42 | "index": 14 43 | } 44 | } 45 | } 46 | ], 47 | "span": { 48 | "start": { 49 | "col": 6, 50 | "row": 0, 51 | "index": 6 52 | }, 53 | "end": { 54 | "col": 1, 55 | "row": 2, 56 | "index": 16 57 | } 58 | } 59 | }, 60 | "span": { 61 | "start": { 62 | "col": 0, 63 | "row": 0, 64 | "index": 0 65 | }, 66 | "end": { 67 | "col": 1, 68 | "row": 2, 69 | "index": 16 70 | } 71 | } 72 | } 73 | ] 74 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/mutation_directive.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Mutation", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": [ 9 | { 10 | "type": "Directive", 11 | "name": { 12 | "type": "Name", 13 | "value": "directive", 14 | "span": { 15 | "start": { 16 | "col": 10, 17 | "row": 0, 18 | "index": 10 19 | }, 20 | "end": { 21 | "col": 19, 22 | "row": 0, 23 | "index": 19 24 | } 25 | } 26 | }, 27 | "arguments": null, 28 | "span": { 29 | "start": { 30 | "col": 10, 31 | "row": 0, 32 | "index": 10 33 | }, 34 | "end": { 35 | "col": 19, 36 | "row": 0, 37 | "index": 19 38 | } 39 | } 40 | } 41 | ], 42 | "selectionset": { 43 | "selections": [ 44 | { 45 | "type": "Field", 46 | "alias": null, 47 | "name": { 48 | "type": "Name", 49 | "value": "node", 50 | "span": { 51 | "start": { 52 | "col": 2, 53 | "row": 1, 54 | "index": 24 55 | }, 56 | "end": { 57 | "col": 6, 58 | "row": 1, 59 | "index": 28 60 | } 61 | } 62 | }, 63 | "arguments": null, 64 | "directives": null, 65 | "selectionset": null, 66 | "span": { 67 | "start": { 68 | "col": 2, 69 | "row": 1, 70 | "index": 24 71 | }, 72 | "end": { 73 | "col": 6, 74 | "row": 1, 75 | "index": 28 76 | } 77 | } 78 | } 79 | ], 80 | "span": { 81 | "start": { 82 | "col": 20, 83 | "row": 0, 84 | "index": 20 85 | }, 86 | "end": { 87 | "col": 1, 88 | "row": 2, 89 | "index": 30 90 | } 91 | } 92 | }, 93 | "span": { 94 | "start": { 95 | "col": 0, 96 | "row": 0, 97 | "index": 0 98 | }, 99 | "end": { 100 | "col": 1, 101 | "row": 2, 102 | "index": 30 103 | } 104 | } 105 | } 106 | ] 107 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/named_query.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": { 7 | "type": "Name", 8 | "value": "Foo", 9 | "span": { 10 | "start": { 11 | "col": 6, 12 | "row": 0, 13 | "index": 6 14 | }, 15 | "end": { 16 | "col": 9, 17 | "row": 0, 18 | "index": 9 19 | } 20 | } 21 | }, 22 | "variable_definations": null, 23 | "directives": null, 24 | "selectionset": { 25 | "selections": [ 26 | { 27 | "type": "Field", 28 | "alias": null, 29 | "name": { 30 | "type": "Name", 31 | "value": "field", 32 | "span": { 33 | "start": { 34 | "col": 2, 35 | "row": 1, 36 | "index": 14 37 | }, 38 | "end": { 39 | "col": 7, 40 | "row": 1, 41 | "index": 19 42 | } 43 | } 44 | }, 45 | "arguments": null, 46 | "directives": null, 47 | "selectionset": null, 48 | "span": { 49 | "start": { 50 | "col": 2, 51 | "row": 1, 52 | "index": 14 53 | }, 54 | "end": { 55 | "col": 7, 56 | "row": 1, 57 | "index": 19 58 | } 59 | } 60 | } 61 | ], 62 | "span": { 63 | "start": { 64 | "col": 10, 65 | "row": 0, 66 | "index": 10 67 | }, 68 | "end": { 69 | "col": 1, 70 | "row": 2, 71 | "index": 21 72 | } 73 | } 74 | }, 75 | "span": { 76 | "start": { 77 | "col": 0, 78 | "row": 0, 79 | "index": 0 80 | }, 81 | "end": { 82 | "col": 1, 83 | "row": 2, 84 | "index": 21 85 | } 86 | } 87 | } 88 | ] 89 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/nested_selection.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": null, 14 | "name": { 15 | "type": "Name", 16 | "value": "node", 17 | "span": { 18 | "start": { 19 | "col": 2, 20 | "row": 1, 21 | "index": 10 22 | }, 23 | "end": { 24 | "col": 6, 25 | "row": 1, 26 | "index": 14 27 | } 28 | } 29 | }, 30 | "arguments": null, 31 | "directives": null, 32 | "selectionset": { 33 | "selections": [ 34 | { 35 | "type": "Field", 36 | "alias": null, 37 | "name": { 38 | "type": "Name", 39 | "value": "id", 40 | "span": { 41 | "start": { 42 | "col": 4, 43 | "row": 2, 44 | "index": 21 45 | }, 46 | "end": { 47 | "col": 6, 48 | "row": 2, 49 | "index": 23 50 | } 51 | } 52 | }, 53 | "arguments": null, 54 | "directives": null, 55 | "selectionset": null, 56 | "span": { 57 | "start": { 58 | "col": 4, 59 | "row": 2, 60 | "index": 21 61 | }, 62 | "end": { 63 | "col": 6, 64 | "row": 2, 65 | "index": 23 66 | } 67 | } 68 | } 69 | ], 70 | "span": { 71 | "start": { 72 | "col": 7, 73 | "row": 1, 74 | "index": 15 75 | }, 76 | "end": { 77 | "col": 3, 78 | "row": 3, 79 | "index": 27 80 | } 81 | } 82 | }, 83 | "span": { 84 | "start": { 85 | "col": 2, 86 | "row": 1, 87 | "index": 10 88 | }, 89 | "end": { 90 | "col": 3, 91 | "row": 3, 92 | "index": 27 93 | } 94 | } 95 | } 96 | ], 97 | "span": { 98 | "start": { 99 | "col": 6, 100 | "row": 0, 101 | "index": 6 102 | }, 103 | "end": { 104 | "col": 1, 105 | "row": 4, 106 | "index": 29 107 | } 108 | } 109 | }, 110 | "span": { 111 | "start": { 112 | "col": 0, 113 | "row": 0, 114 | "index": 0 115 | }, 116 | "end": { 117 | "col": 1, 118 | "row": 4, 119 | "index": 29 120 | } 121 | } 122 | } 123 | ] 124 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_aliases.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": { 14 | "type": "Name", 15 | "value": "an_alias", 16 | "span": { 17 | "start": { 18 | "col": 2, 19 | "row": 1, 20 | "index": 10 21 | }, 22 | "end": { 23 | "col": 10, 24 | "row": 1, 25 | "index": 18 26 | } 27 | } 28 | }, 29 | "name": { 30 | "type": "Name", 31 | "value": "node", 32 | "span": { 33 | "start": { 34 | "col": 12, 35 | "row": 1, 36 | "index": 20 37 | }, 38 | "end": { 39 | "col": 16, 40 | "row": 1, 41 | "index": 24 42 | } 43 | } 44 | }, 45 | "arguments": null, 46 | "directives": null, 47 | "selectionset": null, 48 | "span": { 49 | "start": { 50 | "col": 2, 51 | "row": 1, 52 | "index": 10 53 | }, 54 | "end": { 55 | "col": 10, 56 | "row": 1, 57 | "index": 18 58 | } 59 | } 60 | } 61 | ], 62 | "span": { 63 | "start": { 64 | "col": 6, 65 | "row": 0, 66 | "index": 6 67 | }, 68 | "end": { 69 | "col": 1, 70 | "row": 2, 71 | "index": 26 72 | } 73 | } 74 | }, 75 | "span": { 76 | "start": { 77 | "col": 0, 78 | "row": 0, 79 | "index": 0 80 | }, 81 | "end": { 82 | "col": 1, 83 | "row": 2, 84 | "index": 26 85 | } 86 | } 87 | } 88 | ] 89 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_arguments.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": null, 14 | "name": { 15 | "type": "Name", 16 | "value": "node", 17 | "span": { 18 | "start": { 19 | "col": 2, 20 | "row": 1, 21 | "index": 10 22 | }, 23 | "end": { 24 | "col": 6, 25 | "row": 1, 26 | "index": 14 27 | } 28 | } 29 | }, 30 | "arguments": [ 31 | { 32 | "type": "Argument", 33 | "name": { 34 | "type": "Name", 35 | "value": "id", 36 | "span": { 37 | "start": { 38 | "col": 7, 39 | "row": 1, 40 | "index": 15 41 | }, 42 | "end": { 43 | "col": 9, 44 | "row": 1, 45 | "index": 17 46 | } 47 | } 48 | }, 49 | "value": { 50 | "type": "IntValue", 51 | "code": "1", 52 | "span": { 53 | "start": { 54 | "col": 11, 55 | "row": 1, 56 | "index": 19 57 | }, 58 | "end": { 59 | "col": 12, 60 | "row": 1, 61 | "index": 20 62 | } 63 | } 64 | }, 65 | "span": { 66 | "start": { 67 | "col": 7, 68 | "row": 1, 69 | "index": 15 70 | }, 71 | "end": { 72 | "col": 12, 73 | "row": 1, 74 | "index": 20 75 | } 76 | } 77 | } 78 | ], 79 | "directives": null, 80 | "selectionset": null, 81 | "span": { 82 | "start": { 83 | "col": 2, 84 | "row": 1, 85 | "index": 10 86 | }, 87 | "end": { 88 | "col": 13, 89 | "row": 1, 90 | "index": 21 91 | } 92 | } 93 | } 94 | ], 95 | "span": { 96 | "start": { 97 | "col": 6, 98 | "row": 0, 99 | "index": 6 100 | }, 101 | "end": { 102 | "col": 1, 103 | "row": 2, 104 | "index": 23 105 | } 106 | } 107 | }, 108 | "span": { 109 | "start": { 110 | "col": 0, 111 | "row": 0, 112 | "index": 0 113 | }, 114 | "end": { 115 | "col": 1, 116 | "row": 2, 117 | "index": 23 118 | } 119 | } 120 | } 121 | ] 122 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_array_argument_multiline.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": null, 14 | "name": { 15 | "type": "Name", 16 | "value": "node", 17 | "span": { 18 | "start": { 19 | "col": 2, 20 | "row": 1, 21 | "index": 10 22 | }, 23 | "end": { 24 | "col": 6, 25 | "row": 1, 26 | "index": 14 27 | } 28 | } 29 | }, 30 | "arguments": [ 31 | { 32 | "type": "Argument", 33 | "name": { 34 | "type": "Name", 35 | "value": "id", 36 | "span": { 37 | "start": { 38 | "col": 4, 39 | "row": 2, 40 | "index": 20 41 | }, 42 | "end": { 43 | "col": 6, 44 | "row": 2, 45 | "index": 22 46 | } 47 | } 48 | }, 49 | "value": { 50 | "type": "ListValue", 51 | "values": [ 52 | { 53 | "type": "IntValue", 54 | "code": "5", 55 | "span": { 56 | "start": { 57 | "col": 6, 58 | "row": 3, 59 | "index": 32 60 | }, 61 | "end": { 62 | "col": 7, 63 | "row": 3, 64 | "index": 33 65 | } 66 | } 67 | }, 68 | { 69 | "type": "IntValue", 70 | "code": "6", 71 | "span": { 72 | "start": { 73 | "col": 6, 74 | "row": 4, 75 | "index": 41 76 | }, 77 | "end": { 78 | "col": 7, 79 | "row": 4, 80 | "index": 42 81 | } 82 | } 83 | }, 84 | { 85 | "type": "IntValue", 86 | "code": "7", 87 | "span": { 88 | "start": { 89 | "col": 6, 90 | "row": 5, 91 | "index": 50 92 | }, 93 | "end": { 94 | "col": 7, 95 | "row": 5, 96 | "index": 51 97 | } 98 | } 99 | } 100 | ], 101 | "span": { 102 | "start": { 103 | "col": 8, 104 | "row": 2, 105 | "index": 24 106 | }, 107 | "end": { 108 | "col": 5, 109 | "row": 6, 110 | "index": 57 111 | } 112 | } 113 | }, 114 | "span": { 115 | "start": { 116 | "col": 4, 117 | "row": 2, 118 | "index": 20 119 | }, 120 | "end": { 121 | "col": 5, 122 | "row": 6, 123 | "index": 57 124 | } 125 | } 126 | } 127 | ], 128 | "directives": null, 129 | "selectionset": null, 130 | "span": { 131 | "start": { 132 | "col": 2, 133 | "row": 1, 134 | "index": 10 135 | }, 136 | "end": { 137 | "col": 3, 138 | "row": 7, 139 | "index": 61 140 | } 141 | } 142 | } 143 | ], 144 | "span": { 145 | "start": { 146 | "col": 6, 147 | "row": 0, 148 | "index": 6 149 | }, 150 | "end": { 151 | "col": 1, 152 | "row": 8, 153 | "index": 63 154 | } 155 | } 156 | }, 157 | "span": { 158 | "start": { 159 | "col": 0, 160 | "row": 0, 161 | "index": 0 162 | }, 163 | "end": { 164 | "col": 1, 165 | "row": 8, 166 | "index": 63 167 | } 168 | } 169 | } 170 | ] 171 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_directive.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": [ 9 | { 10 | "type": "Directive", 11 | "name": { 12 | "type": "Name", 13 | "value": "directive", 14 | "span": { 15 | "start": { 16 | "col": 7, 17 | "row": 0, 18 | "index": 7 19 | }, 20 | "end": { 21 | "col": 16, 22 | "row": 0, 23 | "index": 16 24 | } 25 | } 26 | }, 27 | "arguments": null, 28 | "span": { 29 | "start": { 30 | "col": 7, 31 | "row": 0, 32 | "index": 7 33 | }, 34 | "end": { 35 | "col": 16, 36 | "row": 0, 37 | "index": 16 38 | } 39 | } 40 | } 41 | ], 42 | "selectionset": { 43 | "selections": [ 44 | { 45 | "type": "Field", 46 | "alias": null, 47 | "name": { 48 | "type": "Name", 49 | "value": "node", 50 | "span": { 51 | "start": { 52 | "col": 2, 53 | "row": 1, 54 | "index": 21 55 | }, 56 | "end": { 57 | "col": 6, 58 | "row": 1, 59 | "index": 25 60 | } 61 | } 62 | }, 63 | "arguments": null, 64 | "directives": null, 65 | "selectionset": null, 66 | "span": { 67 | "start": { 68 | "col": 2, 69 | "row": 1, 70 | "index": 21 71 | }, 72 | "end": { 73 | "col": 6, 74 | "row": 1, 75 | "index": 25 76 | } 77 | } 78 | } 79 | ], 80 | "span": { 81 | "start": { 82 | "col": 17, 83 | "row": 0, 84 | "index": 17 85 | }, 86 | "end": { 87 | "col": 1, 88 | "row": 2, 89 | "index": 27 90 | } 91 | } 92 | }, 93 | "span": { 94 | "start": { 95 | "col": 0, 96 | "row": 0, 97 | "index": 0 98 | }, 99 | "end": { 100 | "col": 1, 101 | "row": 2, 102 | "index": 27 103 | } 104 | } 105 | } 106 | ] 107 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_var_default_float.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": { 7 | "type": "Name", 8 | "value": "Foo", 9 | "span": { 10 | "start": { 11 | "col": 6, 12 | "row": 0, 13 | "index": 6 14 | }, 15 | "end": { 16 | "col": 9, 17 | "row": 0, 18 | "index": 9 19 | } 20 | } 21 | }, 22 | "variable_definations": [ 23 | { 24 | "type": "VariableDefination", 25 | "name": { 26 | "type": "Name", 27 | "value": "site", 28 | "span": { 29 | "start": { 30 | "col": 11, 31 | "row": 0, 32 | "index": 11 33 | }, 34 | "end": { 35 | "col": 15, 36 | "row": 0, 37 | "index": 15 38 | } 39 | } 40 | }, 41 | "var_type": { 42 | "type": "NameVarType", 43 | "name": "Float", 44 | "span": { 45 | "start": { 46 | "col": 17, 47 | "row": 0, 48 | "index": 17 49 | }, 50 | "end": { 51 | "col": 22, 52 | "row": 0, 53 | "index": 22 54 | } 55 | } 56 | }, 57 | "default_value": { 58 | "type": "FloatValue", 59 | "code": "0.5", 60 | "span": { 61 | "start": { 62 | "col": 25, 63 | "row": 0, 64 | "index": 25 65 | }, 66 | "end": { 67 | "col": 28, 68 | "row": 0, 69 | "index": 28 70 | } 71 | } 72 | }, 73 | "span": { 74 | "start": { 75 | "col": 10, 76 | "row": 0, 77 | "index": 10 78 | }, 79 | "end": { 80 | "col": 28, 81 | "row": 0, 82 | "index": 28 83 | } 84 | } 85 | } 86 | ], 87 | "directives": null, 88 | "selectionset": { 89 | "selections": [ 90 | { 91 | "type": "Field", 92 | "alias": null, 93 | "name": { 94 | "type": "Name", 95 | "value": "field", 96 | "span": { 97 | "start": { 98 | "col": 2, 99 | "row": 1, 100 | "index": 34 101 | }, 102 | "end": { 103 | "col": 7, 104 | "row": 1, 105 | "index": 39 106 | } 107 | } 108 | }, 109 | "arguments": null, 110 | "directives": null, 111 | "selectionset": null, 112 | "span": { 113 | "start": { 114 | "col": 2, 115 | "row": 1, 116 | "index": 34 117 | }, 118 | "end": { 119 | "col": 7, 120 | "row": 1, 121 | "index": 39 122 | } 123 | } 124 | } 125 | ], 126 | "span": { 127 | "start": { 128 | "col": 30, 129 | "row": 0, 130 | "index": 30 131 | }, 132 | "end": { 133 | "col": 1, 134 | "row": 2, 135 | "index": 41 136 | } 137 | } 138 | }, 139 | "span": { 140 | "start": { 141 | "col": 0, 142 | "row": 0, 143 | "index": 0 144 | }, 145 | "end": { 146 | "col": 1, 147 | "row": 2, 148 | "index": 41 149 | } 150 | } 151 | } 152 | ] 153 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_var_default_list.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": { 7 | "type": "Name", 8 | "value": "Foo", 9 | "span": { 10 | "start": { 11 | "col": 6, 12 | "row": 0, 13 | "index": 6 14 | }, 15 | "end": { 16 | "col": 9, 17 | "row": 0, 18 | "index": 9 19 | } 20 | } 21 | }, 22 | "variable_definations": [ 23 | { 24 | "type": "VariableDefination", 25 | "name": { 26 | "type": "Name", 27 | "value": "site", 28 | "span": { 29 | "start": { 30 | "col": 11, 31 | "row": 0, 32 | "index": 11 33 | }, 34 | "end": { 35 | "col": 15, 36 | "row": 0, 37 | "index": 15 38 | } 39 | } 40 | }, 41 | "var_type": { 42 | "type": "ListVarType", 43 | "list_type": { 44 | "type": "NameVarType", 45 | "name": "Int", 46 | "span": { 47 | "start": { 48 | "col": 18, 49 | "row": 0, 50 | "index": 18 51 | }, 52 | "end": { 53 | "col": 21, 54 | "row": 0, 55 | "index": 21 56 | } 57 | } 58 | } 59 | }, 60 | "default_value": { 61 | "type": "ListValue", 62 | "values": [ 63 | { 64 | "type": "IntValue", 65 | "code": "123", 66 | "span": { 67 | "start": { 68 | "col": 26, 69 | "row": 0, 70 | "index": 26 71 | }, 72 | "end": { 73 | "col": 29, 74 | "row": 0, 75 | "index": 29 76 | } 77 | } 78 | }, 79 | { 80 | "type": "IntValue", 81 | "code": "456", 82 | "span": { 83 | "start": { 84 | "col": 31, 85 | "row": 0, 86 | "index": 31 87 | }, 88 | "end": { 89 | "col": 34, 90 | "row": 0, 91 | "index": 34 92 | } 93 | } 94 | } 95 | ], 96 | "span": { 97 | "start": { 98 | "col": 25, 99 | "row": 0, 100 | "index": 25 101 | }, 102 | "end": { 103 | "col": 35, 104 | "row": 0, 105 | "index": 35 106 | } 107 | } 108 | }, 109 | "span": { 110 | "start": { 111 | "col": 10, 112 | "row": 0, 113 | "index": 10 114 | }, 115 | "end": { 116 | "col": 35, 117 | "row": 0, 118 | "index": 35 119 | } 120 | } 121 | } 122 | ], 123 | "directives": null, 124 | "selectionset": { 125 | "selections": [ 126 | { 127 | "type": "Field", 128 | "alias": null, 129 | "name": { 130 | "type": "Name", 131 | "value": "field", 132 | "span": { 133 | "start": { 134 | "col": 2, 135 | "row": 1, 136 | "index": 41 137 | }, 138 | "end": { 139 | "col": 7, 140 | "row": 1, 141 | "index": 46 142 | } 143 | } 144 | }, 145 | "arguments": null, 146 | "directives": null, 147 | "selectionset": null, 148 | "span": { 149 | "start": { 150 | "col": 2, 151 | "row": 1, 152 | "index": 41 153 | }, 154 | "end": { 155 | "col": 7, 156 | "row": 1, 157 | "index": 46 158 | } 159 | } 160 | } 161 | ], 162 | "span": { 163 | "start": { 164 | "col": 37, 165 | "row": 0, 166 | "index": 37 167 | }, 168 | "end": { 169 | "col": 1, 170 | "row": 2, 171 | "index": 48 172 | } 173 | } 174 | }, 175 | "span": { 176 | "start": { 177 | "col": 0, 178 | "row": 0, 179 | "index": 0 180 | }, 181 | "end": { 182 | "col": 1, 183 | "row": 2, 184 | "index": 48 185 | } 186 | } 187 | } 188 | ] 189 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_var_default_object.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": { 7 | "type": "Name", 8 | "value": "Foo", 9 | "span": { 10 | "start": { 11 | "col": 6, 12 | "row": 0, 13 | "index": 6 14 | }, 15 | "end": { 16 | "col": 9, 17 | "row": 0, 18 | "index": 9 19 | } 20 | } 21 | }, 22 | "variable_definations": [ 23 | { 24 | "type": "VariableDefination", 25 | "name": { 26 | "type": "Name", 27 | "value": "site", 28 | "span": { 29 | "start": { 30 | "col": 11, 31 | "row": 0, 32 | "index": 11 33 | }, 34 | "end": { 35 | "col": 15, 36 | "row": 0, 37 | "index": 15 38 | } 39 | } 40 | }, 41 | "var_type": { 42 | "type": "NameVarType", 43 | "name": "Site", 44 | "span": { 45 | "start": { 46 | "col": 17, 47 | "row": 0, 48 | "index": 17 49 | }, 50 | "end": { 51 | "col": 21, 52 | "row": 0, 53 | "index": 21 54 | } 55 | } 56 | }, 57 | "default_value": { 58 | "type": "ObjectValue", 59 | "fields": [ 60 | { 61 | "type": "ObjectField", 62 | "name": { 63 | "type": "Name", 64 | "value": "url", 65 | "span": { 66 | "start": { 67 | "col": 25, 68 | "row": 0, 69 | "index": 25 70 | }, 71 | "end": { 72 | "col": 28, 73 | "row": 0, 74 | "index": 28 75 | } 76 | } 77 | }, 78 | "value": { 79 | "type": "NullValue", 80 | "span": { 81 | "start": { 82 | "col": 30, 83 | "row": 0, 84 | "index": 30 85 | }, 86 | "end": { 87 | "col": 34, 88 | "row": 0, 89 | "index": 34 90 | } 91 | } 92 | } 93 | } 94 | ], 95 | "span": { 96 | "start": { 97 | "col": 24, 98 | "row": 0, 99 | "index": 24 100 | }, 101 | "end": { 102 | "col": 35, 103 | "row": 0, 104 | "index": 35 105 | } 106 | } 107 | }, 108 | "span": { 109 | "start": { 110 | "col": 10, 111 | "row": 0, 112 | "index": 10 113 | }, 114 | "end": { 115 | "col": 35, 116 | "row": 0, 117 | "index": 35 118 | } 119 | } 120 | } 121 | ], 122 | "directives": null, 123 | "selectionset": { 124 | "selections": [ 125 | { 126 | "type": "Field", 127 | "alias": null, 128 | "name": { 129 | "type": "Name", 130 | "value": "field", 131 | "span": { 132 | "start": { 133 | "col": 2, 134 | "row": 1, 135 | "index": 41 136 | }, 137 | "end": { 138 | "col": 7, 139 | "row": 1, 140 | "index": 46 141 | } 142 | } 143 | }, 144 | "arguments": null, 145 | "directives": null, 146 | "selectionset": null, 147 | "span": { 148 | "start": { 149 | "col": 2, 150 | "row": 1, 151 | "index": 41 152 | }, 153 | "end": { 154 | "col": 7, 155 | "row": 1, 156 | "index": 46 157 | } 158 | } 159 | } 160 | ], 161 | "span": { 162 | "start": { 163 | "col": 37, 164 | "row": 0, 165 | "index": 37 166 | }, 167 | "end": { 168 | "col": 1, 169 | "row": 2, 170 | "index": 48 171 | } 172 | } 173 | }, 174 | "span": { 175 | "start": { 176 | "col": 0, 177 | "row": 0, 178 | "index": 0 179 | }, 180 | "end": { 181 | "col": 1, 182 | "row": 2, 183 | "index": 48 184 | } 185 | } 186 | } 187 | ] 188 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_var_default_string.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": { 7 | "type": "Name", 8 | "value": "Foo", 9 | "span": { 10 | "start": { 11 | "col": 6, 12 | "row": 0, 13 | "index": 6 14 | }, 15 | "end": { 16 | "col": 9, 17 | "row": 0, 18 | "index": 9 19 | } 20 | } 21 | }, 22 | "variable_definations": [ 23 | { 24 | "type": "VariableDefination", 25 | "name": { 26 | "type": "Name", 27 | "value": "site", 28 | "span": { 29 | "start": { 30 | "col": 11, 31 | "row": 0, 32 | "index": 11 33 | }, 34 | "end": { 35 | "col": 15, 36 | "row": 0, 37 | "index": 15 38 | } 39 | } 40 | }, 41 | "var_type": { 42 | "type": "NameVarType", 43 | "name": "String", 44 | "span": { 45 | "start": { 46 | "col": 17, 47 | "row": 0, 48 | "index": 17 49 | }, 50 | "end": { 51 | "col": 23, 52 | "row": 0, 53 | "index": 23 54 | } 55 | } 56 | }, 57 | "default_value": { 58 | "type": "StringValue", 59 | "code": "string", 60 | "span": { 61 | "start": { 62 | "col": 26, 63 | "row": 0, 64 | "index": 26 65 | }, 66 | "end": { 67 | "col": 34, 68 | "row": 0, 69 | "index": 34 70 | } 71 | }, 72 | "is_block": false 73 | }, 74 | "span": { 75 | "start": { 76 | "col": 10, 77 | "row": 0, 78 | "index": 10 79 | }, 80 | "end": { 81 | "col": 34, 82 | "row": 0, 83 | "index": 34 84 | } 85 | } 86 | } 87 | ], 88 | "directives": null, 89 | "selectionset": { 90 | "selections": [ 91 | { 92 | "type": "Field", 93 | "alias": null, 94 | "name": { 95 | "type": "Name", 96 | "value": "field", 97 | "span": { 98 | "start": { 99 | "col": 2, 100 | "row": 1, 101 | "index": 40 102 | }, 103 | "end": { 104 | "col": 7, 105 | "row": 1, 106 | "index": 45 107 | } 108 | } 109 | }, 110 | "arguments": null, 111 | "directives": null, 112 | "selectionset": null, 113 | "span": { 114 | "start": { 115 | "col": 2, 116 | "row": 1, 117 | "index": 40 118 | }, 119 | "end": { 120 | "col": 7, 121 | "row": 1, 122 | "index": 45 123 | } 124 | } 125 | } 126 | ], 127 | "span": { 128 | "start": { 129 | "col": 36, 130 | "row": 0, 131 | "index": 36 132 | }, 133 | "end": { 134 | "col": 1, 135 | "row": 2, 136 | "index": 47 137 | } 138 | } 139 | }, 140 | "span": { 141 | "start": { 142 | "col": 0, 143 | "row": 0, 144 | "index": 0 145 | }, 146 | "end": { 147 | "col": 1, 148 | "row": 2, 149 | "index": 47 150 | } 151 | } 152 | } 153 | ] 154 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_var_defaults.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": { 7 | "type": "Name", 8 | "value": "Foo", 9 | "span": { 10 | "start": { 11 | "col": 6, 12 | "row": 0, 13 | "index": 6 14 | }, 15 | "end": { 16 | "col": 9, 17 | "row": 0, 18 | "index": 9 19 | } 20 | } 21 | }, 22 | "variable_definations": [ 23 | { 24 | "type": "VariableDefination", 25 | "name": { 26 | "type": "Name", 27 | "value": "site", 28 | "span": { 29 | "start": { 30 | "col": 11, 31 | "row": 0, 32 | "index": 11 33 | }, 34 | "end": { 35 | "col": 15, 36 | "row": 0, 37 | "index": 15 38 | } 39 | } 40 | }, 41 | "var_type": { 42 | "type": "NameVarType", 43 | "name": "Site", 44 | "span": { 45 | "start": { 46 | "col": 17, 47 | "row": 0, 48 | "index": 17 49 | }, 50 | "end": { 51 | "col": 21, 52 | "row": 0, 53 | "index": 21 54 | } 55 | } 56 | }, 57 | "default_value": { 58 | "type": "EnumValue", 59 | "code": "MOBILE", 60 | "span": { 61 | "start": { 62 | "col": 24, 63 | "row": 0, 64 | "index": 24 65 | }, 66 | "end": { 67 | "col": 30, 68 | "row": 0, 69 | "index": 30 70 | } 71 | } 72 | }, 73 | "span": { 74 | "start": { 75 | "col": 10, 76 | "row": 0, 77 | "index": 10 78 | }, 79 | "end": { 80 | "col": 30, 81 | "row": 0, 82 | "index": 30 83 | } 84 | } 85 | } 86 | ], 87 | "directives": null, 88 | "selectionset": { 89 | "selections": [ 90 | { 91 | "type": "Field", 92 | "alias": null, 93 | "name": { 94 | "type": "Name", 95 | "value": "field", 96 | "span": { 97 | "start": { 98 | "col": 2, 99 | "row": 1, 100 | "index": 36 101 | }, 102 | "end": { 103 | "col": 7, 104 | "row": 1, 105 | "index": 41 106 | } 107 | } 108 | }, 109 | "arguments": null, 110 | "directives": null, 111 | "selectionset": null, 112 | "span": { 113 | "start": { 114 | "col": 2, 115 | "row": 1, 116 | "index": 36 117 | }, 118 | "end": { 119 | "col": 7, 120 | "row": 1, 121 | "index": 41 122 | } 123 | } 124 | } 125 | ], 126 | "span": { 127 | "start": { 128 | "col": 32, 129 | "row": 0, 130 | "index": 32 131 | }, 132 | "end": { 133 | "col": 1, 134 | "row": 2, 135 | "index": 43 136 | } 137 | } 138 | }, 139 | "span": { 140 | "start": { 141 | "col": 0, 142 | "row": 0, 143 | "index": 0 144 | }, 145 | "end": { 146 | "col": 1, 147 | "row": 2, 148 | "index": 43 149 | } 150 | } 151 | } 152 | ] 153 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/query_vars.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": { 7 | "type": "Name", 8 | "value": "Foo", 9 | "span": { 10 | "start": { 11 | "col": 6, 12 | "row": 0, 13 | "index": 6 14 | }, 15 | "end": { 16 | "col": 9, 17 | "row": 0, 18 | "index": 9 19 | } 20 | } 21 | }, 22 | "variable_definations": [ 23 | { 24 | "type": "VariableDefination", 25 | "name": { 26 | "type": "Name", 27 | "value": "arg", 28 | "span": { 29 | "start": { 30 | "col": 11, 31 | "row": 0, 32 | "index": 11 33 | }, 34 | "end": { 35 | "col": 14, 36 | "row": 0, 37 | "index": 14 38 | } 39 | } 40 | }, 41 | "var_type": { 42 | "type": "NameVarType", 43 | "name": "SomeType", 44 | "span": { 45 | "start": { 46 | "col": 16, 47 | "row": 0, 48 | "index": 16 49 | }, 50 | "end": { 51 | "col": 24, 52 | "row": 0, 53 | "index": 24 54 | } 55 | } 56 | }, 57 | "default_value": null, 58 | "span": { 59 | "start": { 60 | "col": 10, 61 | "row": 0, 62 | "index": 10 63 | }, 64 | "end": { 65 | "col": 24, 66 | "row": 0, 67 | "index": 24 68 | } 69 | } 70 | } 71 | ], 72 | "directives": null, 73 | "selectionset": { 74 | "selections": [ 75 | { 76 | "type": "Field", 77 | "alias": null, 78 | "name": { 79 | "type": "Name", 80 | "value": "field", 81 | "span": { 82 | "start": { 83 | "col": 2, 84 | "row": 1, 85 | "index": 30 86 | }, 87 | "end": { 88 | "col": 7, 89 | "row": 1, 90 | "index": 35 91 | } 92 | } 93 | }, 94 | "arguments": null, 95 | "directives": null, 96 | "selectionset": null, 97 | "span": { 98 | "start": { 99 | "col": 2, 100 | "row": 1, 101 | "index": 30 102 | }, 103 | "end": { 104 | "col": 7, 105 | "row": 1, 106 | "index": 35 107 | } 108 | } 109 | } 110 | ], 111 | "span": { 112 | "start": { 113 | "col": 26, 114 | "row": 0, 115 | "index": 26 116 | }, 117 | "end": { 118 | "col": 1, 119 | "row": 2, 120 | "index": 37 121 | } 122 | } 123 | }, 124 | "span": { 125 | "start": { 126 | "col": 0, 127 | "row": 0, 128 | "index": 0 129 | }, 130 | "end": { 131 | "col": 1, 132 | "row": 2, 133 | "index": 37 134 | } 135 | } 136 | } 137 | ] 138 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/string_literal.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": null, 14 | "name": { 15 | "type": "Name", 16 | "value": "node", 17 | "span": { 18 | "start": { 19 | "col": 2, 20 | "row": 1, 21 | "index": 10 22 | }, 23 | "end": { 24 | "col": 6, 25 | "row": 1, 26 | "index": 14 27 | } 28 | } 29 | }, 30 | "arguments": [ 31 | { 32 | "type": "Argument", 33 | "name": { 34 | "type": "Name", 35 | "value": "id", 36 | "span": { 37 | "start": { 38 | "col": 7, 39 | "row": 1, 40 | "index": 15 41 | }, 42 | "end": { 43 | "col": 9, 44 | "row": 1, 45 | "index": 17 46 | } 47 | } 48 | }, 49 | "value": { 50 | "type": "StringValue", 51 | "code": "hello", 52 | "span": { 53 | "start": { 54 | "col": 11, 55 | "row": 1, 56 | "index": 19 57 | }, 58 | "end": { 59 | "col": 18, 60 | "row": 1, 61 | "index": 26 62 | } 63 | }, 64 | "is_block": false 65 | }, 66 | "span": { 67 | "start": { 68 | "col": 7, 69 | "row": 1, 70 | "index": 15 71 | }, 72 | "end": { 73 | "col": 18, 74 | "row": 1, 75 | "index": 26 76 | } 77 | } 78 | } 79 | ], 80 | "directives": null, 81 | "selectionset": null, 82 | "span": { 83 | "start": { 84 | "col": 2, 85 | "row": 1, 86 | "index": 10 87 | }, 88 | "end": { 89 | "col": 19, 90 | "row": 1, 91 | "index": 27 92 | } 93 | } 94 | } 95 | ], 96 | "span": { 97 | "start": { 98 | "col": 6, 99 | "row": 0, 100 | "index": 6 101 | }, 102 | "end": { 103 | "col": 1, 104 | "row": 2, 105 | "index": 29 106 | } 107 | } 108 | }, 109 | "span": { 110 | "start": { 111 | "col": 0, 112 | "row": 0, 113 | "index": 0 114 | }, 115 | "end": { 116 | "col": 1, 117 | "row": 2, 118 | "index": 29 119 | } 120 | } 121 | } 122 | ] 123 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/subscription_directive.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Subscription", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": [ 9 | { 10 | "type": "Directive", 11 | "name": { 12 | "type": "Name", 13 | "value": "directive", 14 | "span": { 15 | "start": { 16 | "col": 14, 17 | "row": 0, 18 | "index": 14 19 | }, 20 | "end": { 21 | "col": 23, 22 | "row": 0, 23 | "index": 23 24 | } 25 | } 26 | }, 27 | "arguments": null, 28 | "span": { 29 | "start": { 30 | "col": 14, 31 | "row": 0, 32 | "index": 14 33 | }, 34 | "end": { 35 | "col": 23, 36 | "row": 0, 37 | "index": 23 38 | } 39 | } 40 | } 41 | ], 42 | "selectionset": { 43 | "selections": [ 44 | { 45 | "type": "Field", 46 | "alias": null, 47 | "name": { 48 | "type": "Name", 49 | "value": "node", 50 | "span": { 51 | "start": { 52 | "col": 2, 53 | "row": 1, 54 | "index": 28 55 | }, 56 | "end": { 57 | "col": 6, 58 | "row": 1, 59 | "index": 32 60 | } 61 | } 62 | }, 63 | "arguments": null, 64 | "directives": null, 65 | "selectionset": null, 66 | "span": { 67 | "start": { 68 | "col": 2, 69 | "row": 1, 70 | "index": 28 71 | }, 72 | "end": { 73 | "col": 6, 74 | "row": 1, 75 | "index": 32 76 | } 77 | } 78 | } 79 | ], 80 | "span": { 81 | "start": { 82 | "col": 24, 83 | "row": 0, 84 | "index": 24 85 | }, 86 | "end": { 87 | "col": 1, 88 | "row": 2, 89 | "index": 34 90 | } 91 | } 92 | }, 93 | "span": { 94 | "start": { 95 | "col": 0, 96 | "row": 0, 97 | "index": 0 98 | }, 99 | "end": { 100 | "col": 1, 101 | "row": 2, 102 | "index": 34 103 | } 104 | } 105 | } 106 | ] 107 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/query/triple_quoted_literal.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "Query", 6 | "name": null, 7 | "variable_definations": null, 8 | "directives": null, 9 | "selectionset": { 10 | "selections": [ 11 | { 12 | "type": "Field", 13 | "alias": null, 14 | "name": { 15 | "type": "Name", 16 | "value": "node", 17 | "span": { 18 | "start": { 19 | "col": 2, 20 | "row": 1, 21 | "index": 10 22 | }, 23 | "end": { 24 | "col": 6, 25 | "row": 1, 26 | "index": 14 27 | } 28 | } 29 | }, 30 | "arguments": [ 31 | { 32 | "type": "Argument", 33 | "name": { 34 | "type": "Name", 35 | "value": "id", 36 | "span": { 37 | "start": { 38 | "col": 7, 39 | "row": 1, 40 | "index": 15 41 | }, 42 | "end": { 43 | "col": 9, 44 | "row": 1, 45 | "index": 17 46 | } 47 | } 48 | }, 49 | "value": { 50 | "type": "StringValue", 51 | "code": "\n Hello,\n world!\n ", 52 | "span": { 53 | "start": { 54 | "col": 11, 55 | "row": 1, 56 | "index": 19 57 | }, 58 | "end": { 59 | "col": 5, 60 | "row": 4, 61 | "index": 52 62 | } 63 | }, 64 | "is_block": true 65 | }, 66 | "span": { 67 | "start": { 68 | "col": 7, 69 | "row": 1, 70 | "index": 15 71 | }, 72 | "end": { 73 | "col": 5, 74 | "row": 4, 75 | "index": 52 76 | } 77 | } 78 | } 79 | ], 80 | "directives": null, 81 | "selectionset": null, 82 | "span": { 83 | "start": { 84 | "col": 2, 85 | "row": 1, 86 | "index": 10 87 | }, 88 | "end": { 89 | "col": 6, 90 | "row": 4, 91 | "index": 53 92 | } 93 | } 94 | } 95 | ], 96 | "span": { 97 | "start": { 98 | "col": 6, 99 | "row": 0, 100 | "index": 6 101 | }, 102 | "end": { 103 | "col": 1, 104 | "row": 5, 105 | "index": 55 106 | } 107 | } 108 | }, 109 | "span": { 110 | "start": { 111 | "col": 0, 112 | "row": 0, 113 | "index": 0 114 | }, 115 | "end": { 116 | "col": 1, 117 | "row": 5, 118 | "index": 55 119 | } 120 | } 121 | } 122 | ] 123 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/directive.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "DirectiveDefination", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "skip", 10 | "span": { 11 | "start": { 12 | "col": 11, 13 | "row": 0, 14 | "index": 11 15 | }, 16 | "end": { 17 | "col": 15, 18 | "row": 0, 19 | "index": 15 20 | } 21 | } 22 | }, 23 | "argument_definations": [ 24 | { 25 | "description": null, 26 | "name": { 27 | "type": "Name", 28 | "value": "if", 29 | "span": { 30 | "start": { 31 | "col": 16, 32 | "row": 0, 33 | "index": 16 34 | }, 35 | "end": { 36 | "col": 18, 37 | "row": 0, 38 | "index": 18 39 | } 40 | } 41 | }, 42 | "var_type": { 43 | "type": "NonNullVarType", 44 | "nonull_type": { 45 | "type": "NameVarType", 46 | "name": "Boolean", 47 | "span": { 48 | "start": { 49 | "col": 20, 50 | "row": 0, 51 | "index": 20 52 | }, 53 | "end": { 54 | "col": 27, 55 | "row": 0, 56 | "index": 27 57 | } 58 | } 59 | } 60 | }, 61 | "default_value": null, 62 | "directives": null, 63 | "span": { 64 | "start": { 65 | "col": 16, 66 | "row": 0, 67 | "index": 16 68 | }, 69 | "end": { 70 | "col": 27, 71 | "row": 0, 72 | "index": 27 73 | } 74 | } 75 | } 76 | ], 77 | "directive_locations": [ 78 | "Field", 79 | "FragmentSpread", 80 | "InlineFragment" 81 | ], 82 | "is_repeatable": false, 83 | "span": { 84 | "start": { 85 | "col": 11, 86 | "row": 0, 87 | "index": 11 88 | }, 89 | "end": { 90 | "col": 74, 91 | "row": 0, 92 | "index": 74 93 | } 94 | } 95 | } 96 | ] 97 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/directive_variable_definition.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "DirectiveDefination", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "configurable", 10 | "span": { 11 | "start": { 12 | "col": 11, 13 | "row": 0, 14 | "index": 11 15 | }, 16 | "end": { 17 | "col": 23, 18 | "row": 0, 19 | "index": 23 20 | } 21 | } 22 | }, 23 | "argument_definations": null, 24 | "directive_locations": [ 25 | "VariableDefination" 26 | ], 27 | "is_repeatable": false, 28 | "span": { 29 | "start": { 30 | "col": 11, 31 | "row": 0, 32 | "index": 11 33 | }, 34 | "end": { 35 | "col": 46, 36 | "row": 0, 37 | "index": 46 38 | } 39 | } 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/empty_union.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "UnionTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "UndefinedUnion", 10 | "span": { 11 | "start": { 12 | "col": 6, 13 | "row": 0, 14 | "index": 6 15 | }, 16 | "end": { 17 | "col": 20, 18 | "row": 0, 19 | "index": 20 20 | } 21 | } 22 | }, 23 | "directives": null, 24 | "union_member_types": null, 25 | "span": { 26 | "start": { 27 | "col": 6, 28 | "row": 0, 29 | "index": 6 30 | }, 31 | "end": { 32 | "col": 20, 33 | "row": 0, 34 | "index": 20 35 | } 36 | } 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/enum.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "EnumTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "Site", 10 | "span": { 11 | "start": { 12 | "col": 5, 13 | "row": 0, 14 | "index": 5 15 | }, 16 | "end": { 17 | "col": 9, 18 | "row": 0, 19 | "index": 9 20 | } 21 | } 22 | }, 23 | "directives": null, 24 | "value_definations": [ 25 | { 26 | "description": null, 27 | "value": { 28 | "code": "DESKTOP", 29 | "span": { 30 | "start": { 31 | "col": 2, 32 | "row": 1, 33 | "index": 14 34 | }, 35 | "end": { 36 | "col": 9, 37 | "row": 1, 38 | "index": 21 39 | } 40 | } 41 | }, 42 | "directives": null, 43 | "span": { 44 | "start": { 45 | "col": 2, 46 | "row": 1, 47 | "index": 14 48 | }, 49 | "end": { 50 | "col": 9, 51 | "row": 1, 52 | "index": 21 53 | } 54 | } 55 | }, 56 | { 57 | "description": null, 58 | "value": { 59 | "code": "MOBILE", 60 | "span": { 61 | "start": { 62 | "col": 2, 63 | "row": 2, 64 | "index": 24 65 | }, 66 | "end": { 67 | "col": 8, 68 | "row": 2, 69 | "index": 30 70 | } 71 | } 72 | }, 73 | "directives": null, 74 | "span": { 75 | "start": { 76 | "col": 2, 77 | "row": 2, 78 | "index": 24 79 | }, 80 | "end": { 81 | "col": 8, 82 | "row": 2, 83 | "index": 30 84 | } 85 | } 86 | } 87 | ], 88 | "span": { 89 | "start": { 90 | "col": 5, 91 | "row": 0, 92 | "index": 5 93 | }, 94 | "end": { 95 | "col": 9, 96 | "row": 0, 97 | "index": 9 98 | } 99 | } 100 | } 101 | ] 102 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/extend_enum.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "EnumTypeExtension", 6 | "name": { 7 | "type": "Name", 8 | "value": "Site", 9 | "span": { 10 | "start": { 11 | "col": 12, 12 | "row": 0, 13 | "index": 12 14 | }, 15 | "end": { 16 | "col": 16, 17 | "row": 0, 18 | "index": 16 19 | } 20 | } 21 | }, 22 | "directives": null, 23 | "value_definations": [ 24 | { 25 | "description": null, 26 | "value": { 27 | "code": "VR", 28 | "span": { 29 | "start": { 30 | "col": 2, 31 | "row": 1, 32 | "index": 21 33 | }, 34 | "end": { 35 | "col": 4, 36 | "row": 1, 37 | "index": 23 38 | } 39 | } 40 | }, 41 | "directives": null, 42 | "span": { 43 | "start": { 44 | "col": 2, 45 | "row": 1, 46 | "index": 21 47 | }, 48 | "end": { 49 | "col": 4, 50 | "row": 1, 51 | "index": 23 52 | } 53 | } 54 | } 55 | ], 56 | "span": { 57 | "start": { 58 | "col": 0, 59 | "row": 0, 60 | "index": 0 61 | }, 62 | "end": { 63 | "col": 16, 64 | "row": 0, 65 | "index": 16 66 | } 67 | } 68 | } 69 | ] 70 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/extend_input.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "InputObjectTypeExtension", 6 | "name": { 7 | "type": "Name", 8 | "value": "InputType", 9 | "span": { 10 | "start": { 11 | "col": 13, 12 | "row": 0, 13 | "index": 13 14 | }, 15 | "end": { 16 | "col": 22, 17 | "row": 0, 18 | "index": 22 19 | } 20 | } 21 | }, 22 | "directives": null, 23 | "input_definations": [ 24 | { 25 | "description": null, 26 | "name": { 27 | "type": "Name", 28 | "value": "other", 29 | "span": { 30 | "start": { 31 | "col": 2, 32 | "row": 1, 33 | "index": 27 34 | }, 35 | "end": { 36 | "col": 7, 37 | "row": 1, 38 | "index": 32 39 | } 40 | } 41 | }, 42 | "var_type": { 43 | "type": "NameVarType", 44 | "name": "Float", 45 | "span": { 46 | "start": { 47 | "col": 9, 48 | "row": 1, 49 | "index": 34 50 | }, 51 | "end": { 52 | "col": 14, 53 | "row": 1, 54 | "index": 39 55 | } 56 | } 57 | }, 58 | "default_value": { 59 | "type": "FloatValue", 60 | "code": "1.23e4", 61 | "span": { 62 | "start": { 63 | "col": 17, 64 | "row": 1, 65 | "index": 42 66 | }, 67 | "end": { 68 | "col": 23, 69 | "row": 1, 70 | "index": 48 71 | } 72 | } 73 | }, 74 | "directives": null, 75 | "span": { 76 | "start": { 77 | "col": 2, 78 | "row": 1, 79 | "index": 27 80 | }, 81 | "end": { 82 | "col": 23, 83 | "row": 1, 84 | "index": 48 85 | } 86 | } 87 | } 88 | ], 89 | "span": { 90 | "start": { 91 | "col": 0, 92 | "row": 0, 93 | "index": 0 94 | }, 95 | "end": { 96 | "col": 1, 97 | "row": 2, 98 | "index": 50 99 | } 100 | } 101 | } 102 | ] 103 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/extend_input_canonical.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "InputObjectTypeExtension", 6 | "name": { 7 | "type": "Name", 8 | "value": "InputType", 9 | "span": { 10 | "start": { 11 | "col": 13, 12 | "row": 0, 13 | "index": 13 14 | }, 15 | "end": { 16 | "col": 22, 17 | "row": 0, 18 | "index": 22 19 | } 20 | } 21 | }, 22 | "directives": null, 23 | "input_definations": [ 24 | { 25 | "description": null, 26 | "name": { 27 | "type": "Name", 28 | "value": "other", 29 | "span": { 30 | "start": { 31 | "col": 2, 32 | "row": 1, 33 | "index": 27 34 | }, 35 | "end": { 36 | "col": 7, 37 | "row": 1, 38 | "index": 32 39 | } 40 | } 41 | }, 42 | "var_type": { 43 | "type": "NameVarType", 44 | "name": "Float", 45 | "span": { 46 | "start": { 47 | "col": 9, 48 | "row": 1, 49 | "index": 34 50 | }, 51 | "end": { 52 | "col": 14, 53 | "row": 1, 54 | "index": 39 55 | } 56 | } 57 | }, 58 | "default_value": { 59 | "type": "IntValue", 60 | "code": "12300", 61 | "span": { 62 | "start": { 63 | "col": 17, 64 | "row": 1, 65 | "index": 42 66 | }, 67 | "end": { 68 | "col": 22, 69 | "row": 1, 70 | "index": 47 71 | } 72 | } 73 | }, 74 | "directives": null, 75 | "span": { 76 | "start": { 77 | "col": 2, 78 | "row": 1, 79 | "index": 27 80 | }, 81 | "end": { 82 | "col": 22, 83 | "row": 1, 84 | "index": 47 85 | } 86 | } 87 | } 88 | ], 89 | "span": { 90 | "start": { 91 | "col": 0, 92 | "row": 0, 93 | "index": 0 94 | }, 95 | "end": { 96 | "col": 1, 97 | "row": 2, 98 | "index": 49 99 | } 100 | } 101 | } 102 | ] 103 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/extend_scalar.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "ScalarTypeExtension", 6 | "name": { 7 | "type": "Name", 8 | "value": "CustomScalar", 9 | "span": { 10 | "start": { 11 | "col": 14, 12 | "row": 0, 13 | "index": 14 14 | }, 15 | "end": { 16 | "col": 26, 17 | "row": 0, 18 | "index": 26 19 | } 20 | } 21 | }, 22 | "directives": [ 23 | { 24 | "type": "Directive", 25 | "name": { 26 | "type": "Name", 27 | "value": "onScalar", 28 | "span": { 29 | "start": { 30 | "col": 28, 31 | "row": 0, 32 | "index": 28 33 | }, 34 | "end": { 35 | "col": 36, 36 | "row": 0, 37 | "index": 36 38 | } 39 | } 40 | }, 41 | "arguments": null, 42 | "span": { 43 | "start": { 44 | "col": 28, 45 | "row": 0, 46 | "index": 28 47 | }, 48 | "end": { 49 | "col": 36, 50 | "row": 0, 51 | "index": 36 52 | } 53 | } 54 | } 55 | ], 56 | "span": { 57 | "start": { 58 | "col": 0, 59 | "row": 0, 60 | "index": 0 61 | }, 62 | "end": { 63 | "col": 36, 64 | "row": 0, 65 | "index": 36 66 | } 67 | } 68 | } 69 | ] 70 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/implements.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "ObjectTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "Type1", 10 | "span": { 11 | "start": { 12 | "col": 5, 13 | "row": 0, 14 | "index": 5 15 | }, 16 | "end": { 17 | "col": 10, 18 | "row": 0, 19 | "index": 10 20 | } 21 | } 22 | }, 23 | "implement_interfaces": [ 24 | { 25 | "name": "IOne", 26 | "span": { 27 | "start": { 28 | "col": 22, 29 | "row": 0, 30 | "index": 22 31 | }, 32 | "end": { 33 | "col": 26, 34 | "row": 0, 35 | "index": 26 36 | } 37 | } 38 | } 39 | ], 40 | "field_definations": null, 41 | "directives": null, 42 | "span": { 43 | "start": { 44 | "col": 5, 45 | "row": 0, 46 | "index": 5 47 | }, 48 | "end": { 49 | "col": 10, 50 | "row": 0, 51 | "index": 10 52 | } 53 | } 54 | }, 55 | { 56 | "type": "ObjectTypeDefinition", 57 | "description": null, 58 | "name": { 59 | "type": "Name", 60 | "value": "Type1", 61 | "span": { 62 | "start": { 63 | "col": 5, 64 | "row": 2, 65 | "index": 33 66 | }, 67 | "end": { 68 | "col": 10, 69 | "row": 2, 70 | "index": 38 71 | } 72 | } 73 | }, 74 | "implement_interfaces": [ 75 | { 76 | "name": "IOne", 77 | "span": { 78 | "start": { 79 | "col": 22, 80 | "row": 2, 81 | "index": 50 82 | }, 83 | "end": { 84 | "col": 26, 85 | "row": 2, 86 | "index": 54 87 | } 88 | } 89 | }, 90 | { 91 | "name": "ITwo", 92 | "span": { 93 | "start": { 94 | "col": 29, 95 | "row": 2, 96 | "index": 57 97 | }, 98 | "end": { 99 | "col": 33, 100 | "row": 2, 101 | "index": 61 102 | } 103 | } 104 | } 105 | ], 106 | "field_definations": null, 107 | "directives": null, 108 | "span": { 109 | "start": { 110 | "col": 5, 111 | "row": 2, 112 | "index": 33 113 | }, 114 | "end": { 115 | "col": 10, 116 | "row": 2, 117 | "index": 38 118 | } 119 | } 120 | } 121 | ] 122 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/implements_amp.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "ObjectTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "Type1", 10 | "span": { 11 | "start": { 12 | "col": 5, 13 | "row": 0, 14 | "index": 5 15 | }, 16 | "end": { 17 | "col": 10, 18 | "row": 0, 19 | "index": 10 20 | } 21 | } 22 | }, 23 | "implement_interfaces": [ 24 | { 25 | "name": "IOne", 26 | "span": { 27 | "start": { 28 | "col": 24, 29 | "row": 0, 30 | "index": 24 31 | }, 32 | "end": { 33 | "col": 28, 34 | "row": 0, 35 | "index": 28 36 | } 37 | } 38 | }, 39 | { 40 | "name": "ITwo", 41 | "span": { 42 | "start": { 43 | "col": 31, 44 | "row": 0, 45 | "index": 31 46 | }, 47 | "end": { 48 | "col": 35, 49 | "row": 0, 50 | "index": 35 51 | } 52 | } 53 | } 54 | ], 55 | "field_definations": null, 56 | "directives": null, 57 | "span": { 58 | "start": { 59 | "col": 5, 60 | "row": 0, 61 | "index": 5 62 | }, 63 | "end": { 64 | "col": 10, 65 | "row": 0, 66 | "index": 10 67 | } 68 | } 69 | }, 70 | { 71 | "type": "ObjectTypeDefinition", 72 | "description": null, 73 | "name": { 74 | "type": "Name", 75 | "value": "Type2", 76 | "span": { 77 | "start": { 78 | "col": 5, 79 | "row": 1, 80 | "index": 41 81 | }, 82 | "end": { 83 | "col": 10, 84 | "row": 1, 85 | "index": 46 86 | } 87 | } 88 | }, 89 | "implement_interfaces": [ 90 | { 91 | "name": "IOne", 92 | "span": { 93 | "start": { 94 | "col": 24, 95 | "row": 1, 96 | "index": 60 97 | }, 98 | "end": { 99 | "col": 28, 100 | "row": 1, 101 | "index": 64 102 | } 103 | } 104 | } 105 | ], 106 | "field_definations": null, 107 | "directives": null, 108 | "span": { 109 | "start": { 110 | "col": 5, 111 | "row": 1, 112 | "index": 41 113 | }, 114 | "end": { 115 | "col": 10, 116 | "row": 1, 117 | "index": 46 118 | } 119 | } 120 | } 121 | ] 122 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/implements_amp_canonical.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "ObjectTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "Type1", 10 | "span": { 11 | "start": { 12 | "col": 5, 13 | "row": 0, 14 | "index": 5 15 | }, 16 | "end": { 17 | "col": 10, 18 | "row": 0, 19 | "index": 10 20 | } 21 | } 22 | }, 23 | "implement_interfaces": [ 24 | { 25 | "name": "IOne", 26 | "span": { 27 | "start": { 28 | "col": 22, 29 | "row": 0, 30 | "index": 22 31 | }, 32 | "end": { 33 | "col": 26, 34 | "row": 0, 35 | "index": 26 36 | } 37 | } 38 | }, 39 | { 40 | "name": "ITwo", 41 | "span": { 42 | "start": { 43 | "col": 29, 44 | "row": 0, 45 | "index": 29 46 | }, 47 | "end": { 48 | "col": 33, 49 | "row": 0, 50 | "index": 33 51 | } 52 | } 53 | } 54 | ], 55 | "field_definations": null, 56 | "directives": null, 57 | "span": { 58 | "start": { 59 | "col": 5, 60 | "row": 0, 61 | "index": 5 62 | }, 63 | "end": { 64 | "col": 10, 65 | "row": 0, 66 | "index": 10 67 | } 68 | } 69 | }, 70 | { 71 | "type": "ObjectTypeDefinition", 72 | "description": null, 73 | "name": { 74 | "type": "Name", 75 | "value": "Type2", 76 | "span": { 77 | "start": { 78 | "col": 5, 79 | "row": 2, 80 | "index": 40 81 | }, 82 | "end": { 83 | "col": 10, 84 | "row": 2, 85 | "index": 45 86 | } 87 | } 88 | }, 89 | "implement_interfaces": [ 90 | { 91 | "name": "IOne", 92 | "span": { 93 | "start": { 94 | "col": 22, 95 | "row": 2, 96 | "index": 57 97 | }, 98 | "end": { 99 | "col": 26, 100 | "row": 2, 101 | "index": 61 102 | } 103 | } 104 | } 105 | ], 106 | "field_definations": null, 107 | "directives": null, 108 | "span": { 109 | "start": { 110 | "col": 5, 111 | "row": 2, 112 | "index": 40 113 | }, 114 | "end": { 115 | "col": 10, 116 | "row": 2, 117 | "index": 45 118 | } 119 | } 120 | } 121 | ] 122 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/implements_interface.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "InterfaceTypeDefinition", 6 | "description": null, 7 | "implement_interfaces": [ 8 | { 9 | "name": "ITwo", 10 | "span": { 11 | "start": { 12 | "col": 26, 13 | "row": 0, 14 | "index": 26 15 | }, 16 | "end": { 17 | "col": 30, 18 | "row": 0, 19 | "index": 30 20 | } 21 | } 22 | } 23 | ], 24 | "name": { 25 | "type": "Name", 26 | "value": "IOne", 27 | "span": { 28 | "start": { 29 | "col": 10, 30 | "row": 0, 31 | "index": 10 32 | }, 33 | "end": { 34 | "col": 14, 35 | "row": 0, 36 | "index": 14 37 | } 38 | } 39 | }, 40 | "directives": null, 41 | "field_definations": null, 42 | "span": { 43 | "start": { 44 | "col": 10, 45 | "row": 0, 46 | "index": 10 47 | }, 48 | "end": { 49 | "col": 14, 50 | "row": 0, 51 | "index": 14 52 | } 53 | } 54 | }, 55 | { 56 | "type": "InterfaceTypeDefinition", 57 | "description": null, 58 | "implement_interfaces": [ 59 | { 60 | "name": "IFour", 61 | "span": { 62 | "start": { 63 | "col": 28, 64 | "row": 2, 65 | "index": 60 66 | }, 67 | "end": { 68 | "col": 33, 69 | "row": 2, 70 | "index": 65 71 | } 72 | } 73 | }, 74 | { 75 | "name": "IFive", 76 | "span": { 77 | "start": { 78 | "col": 36, 79 | "row": 2, 80 | "index": 68 81 | }, 82 | "end": { 83 | "col": 41, 84 | "row": 2, 85 | "index": 73 86 | } 87 | } 88 | } 89 | ], 90 | "name": { 91 | "type": "Name", 92 | "value": "IThree", 93 | "span": { 94 | "start": { 95 | "col": 10, 96 | "row": 2, 97 | "index": 42 98 | }, 99 | "end": { 100 | "col": 16, 101 | "row": 2, 102 | "index": 48 103 | } 104 | } 105 | }, 106 | "directives": null, 107 | "field_definations": null, 108 | "span": { 109 | "start": { 110 | "col": 10, 111 | "row": 2, 112 | "index": 42 113 | }, 114 | "end": { 115 | "col": 16, 116 | "row": 2, 117 | "index": 48 118 | } 119 | } 120 | } 121 | ] 122 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/input_type.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "InputObjectTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "InputType", 10 | "span": { 11 | "start": { 12 | "col": 6, 13 | "row": 0, 14 | "index": 6 15 | }, 16 | "end": { 17 | "col": 15, 18 | "row": 0, 19 | "index": 15 20 | } 21 | } 22 | }, 23 | "directives": null, 24 | "input_definations": [ 25 | { 26 | "description": null, 27 | "name": { 28 | "type": "Name", 29 | "value": "key", 30 | "span": { 31 | "start": { 32 | "col": 2, 33 | "row": 1, 34 | "index": 20 35 | }, 36 | "end": { 37 | "col": 5, 38 | "row": 1, 39 | "index": 23 40 | } 41 | } 42 | }, 43 | "var_type": { 44 | "type": "NonNullVarType", 45 | "nonull_type": { 46 | "type": "NameVarType", 47 | "name": "String", 48 | "span": { 49 | "start": { 50 | "col": 7, 51 | "row": 1, 52 | "index": 25 53 | }, 54 | "end": { 55 | "col": 13, 56 | "row": 1, 57 | "index": 31 58 | } 59 | } 60 | } 61 | }, 62 | "default_value": null, 63 | "directives": null, 64 | "span": { 65 | "start": { 66 | "col": 2, 67 | "row": 1, 68 | "index": 20 69 | }, 70 | "end": { 71 | "col": 13, 72 | "row": 1, 73 | "index": 31 74 | } 75 | } 76 | }, 77 | { 78 | "description": null, 79 | "name": { 80 | "type": "Name", 81 | "value": "answer", 82 | "span": { 83 | "start": { 84 | "col": 2, 85 | "row": 2, 86 | "index": 35 87 | }, 88 | "end": { 89 | "col": 8, 90 | "row": 2, 91 | "index": 41 92 | } 93 | } 94 | }, 95 | "var_type": { 96 | "type": "NameVarType", 97 | "name": "Int", 98 | "span": { 99 | "start": { 100 | "col": 10, 101 | "row": 2, 102 | "index": 43 103 | }, 104 | "end": { 105 | "col": 13, 106 | "row": 2, 107 | "index": 46 108 | } 109 | } 110 | }, 111 | "default_value": { 112 | "type": "IntValue", 113 | "code": "42", 114 | "span": { 115 | "start": { 116 | "col": 16, 117 | "row": 2, 118 | "index": 49 119 | }, 120 | "end": { 121 | "col": 18, 122 | "row": 2, 123 | "index": 51 124 | } 125 | } 126 | }, 127 | "directives": null, 128 | "span": { 129 | "start": { 130 | "col": 2, 131 | "row": 2, 132 | "index": 35 133 | }, 134 | "end": { 135 | "col": 18, 136 | "row": 2, 137 | "index": 51 138 | } 139 | } 140 | } 141 | ], 142 | "span": { 143 | "start": { 144 | "col": 6, 145 | "row": 0, 146 | "index": 6 147 | }, 148 | "end": { 149 | "col": 1, 150 | "row": 3, 151 | "index": 53 152 | } 153 | } 154 | } 155 | ] 156 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/interface.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "InterfaceTypeDefinition", 6 | "description": null, 7 | "implement_interfaces": null, 8 | "name": { 9 | "type": "Name", 10 | "value": "Bar", 11 | "span": { 12 | "start": { 13 | "col": 10, 14 | "row": 0, 15 | "index": 10 16 | }, 17 | "end": { 18 | "col": 13, 19 | "row": 0, 20 | "index": 13 21 | } 22 | } 23 | }, 24 | "directives": null, 25 | "field_definations": [ 26 | { 27 | "description": null, 28 | "name": { 29 | "type": "Name", 30 | "value": "one", 31 | "span": { 32 | "start": { 33 | "col": 2, 34 | "row": 1, 35 | "index": 18 36 | }, 37 | "end": { 38 | "col": 5, 39 | "row": 1, 40 | "index": 21 41 | } 42 | } 43 | }, 44 | "argument_definations": null, 45 | "directives": null, 46 | "var_type": { 47 | "type": "NameVarType", 48 | "name": "Type", 49 | "span": { 50 | "start": { 51 | "col": 7, 52 | "row": 1, 53 | "index": 23 54 | }, 55 | "end": { 56 | "col": 11, 57 | "row": 1, 58 | "index": 27 59 | } 60 | } 61 | }, 62 | "span": { 63 | "start": { 64 | "col": 2, 65 | "row": 1, 66 | "index": 18 67 | }, 68 | "end": { 69 | "col": 11, 70 | "row": 1, 71 | "index": 27 72 | } 73 | } 74 | } 75 | ], 76 | "span": { 77 | "start": { 78 | "col": 10, 79 | "row": 0, 80 | "index": 10 81 | }, 82 | "end": { 83 | "col": 1, 84 | "row": 2, 85 | "index": 29 86 | } 87 | } 88 | } 89 | ] 90 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/minimal.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "SchemaTypeDefination", 6 | "description": null, 7 | "directives": null, 8 | "query": [ 9 | { 10 | "name": "Query", 11 | "span": { 12 | "start": { 13 | "col": 9, 14 | "row": 1, 15 | "index": 18 16 | }, 17 | "end": { 18 | "col": 14, 19 | "row": 1, 20 | "index": 23 21 | } 22 | } 23 | } 24 | ], 25 | "mutation": [], 26 | "subscription": [], 27 | "span": { 28 | "start": { 29 | "col": 0, 30 | "row": 0, 31 | "index": 0 32 | }, 33 | "end": { 34 | "col": 1, 35 | "row": 2, 36 | "index": 25 37 | } 38 | } 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/minimal_type.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "ObjectTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "UndefinedType", 10 | "span": { 11 | "start": { 12 | "col": 5, 13 | "row": 0, 14 | "index": 5 15 | }, 16 | "end": { 17 | "col": 18, 18 | "row": 0, 19 | "index": 18 20 | } 21 | } 22 | }, 23 | "implement_interfaces": null, 24 | "field_definations": null, 25 | "directives": null, 26 | "span": { 27 | "start": { 28 | "col": 5, 29 | "row": 0, 30 | "index": 5 31 | }, 32 | "end": { 33 | "col": 18, 34 | "row": 0, 35 | "index": 18 36 | } 37 | } 38 | } 39 | ] 40 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/repeatable.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "DirectiveDefination", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "filter", 10 | "span": { 11 | "start": { 12 | "col": 11, 13 | "row": 0, 14 | "index": 11 15 | }, 16 | "end": { 17 | "col": 17, 18 | "row": 0, 19 | "index": 17 20 | } 21 | } 22 | }, 23 | "argument_definations": [ 24 | { 25 | "description": null, 26 | "name": { 27 | "type": "Name", 28 | "value": "expression", 29 | "span": { 30 | "start": { 31 | "col": 18, 32 | "row": 0, 33 | "index": 18 34 | }, 35 | "end": { 36 | "col": 28, 37 | "row": 0, 38 | "index": 28 39 | } 40 | } 41 | }, 42 | "var_type": { 43 | "type": "NonNullVarType", 44 | "nonull_type": { 45 | "type": "NameVarType", 46 | "name": "String", 47 | "span": { 48 | "start": { 49 | "col": 30, 50 | "row": 0, 51 | "index": 30 52 | }, 53 | "end": { 54 | "col": 36, 55 | "row": 0, 56 | "index": 36 57 | } 58 | } 59 | } 60 | }, 61 | "default_value": null, 62 | "directives": null, 63 | "span": { 64 | "start": { 65 | "col": 18, 66 | "row": 0, 67 | "index": 18 68 | }, 69 | "end": { 70 | "col": 36, 71 | "row": 0, 72 | "index": 36 73 | } 74 | } 75 | } 76 | ], 77 | "directive_locations": [ 78 | "Field" 79 | ], 80 | "is_repeatable": true, 81 | "span": { 82 | "start": { 83 | "col": 11, 84 | "row": 0, 85 | "index": 11 86 | }, 87 | "end": { 88 | "col": 58, 89 | "row": 0, 90 | "index": 58 91 | } 92 | } 93 | } 94 | ] 95 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/scalar_type.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "ScalarTypeDefinition", 6 | "description": { 7 | "code": "This is the best scalar type", 8 | "span": { 9 | "start": { 10 | "col": 0, 11 | "row": 0, 12 | "index": 0 13 | }, 14 | "end": { 15 | "col": 30, 16 | "row": 0, 17 | "index": 30 18 | } 19 | }, 20 | "is_block": false 21 | }, 22 | "name": { 23 | "type": "Name", 24 | "value": "BestType", 25 | "span": { 26 | "start": { 27 | "col": 7, 28 | "row": 1, 29 | "index": 38 30 | }, 31 | "end": { 32 | "col": 15, 33 | "row": 1, 34 | "index": 46 35 | } 36 | } 37 | }, 38 | "directives": [ 39 | { 40 | "type": "Directive", 41 | "name": { 42 | "type": "Name", 43 | "value": "perfectness", 44 | "span": { 45 | "start": { 46 | "col": 17, 47 | "row": 1, 48 | "index": 48 49 | }, 50 | "end": { 51 | "col": 28, 52 | "row": 1, 53 | "index": 59 54 | } 55 | } 56 | }, 57 | "arguments": [ 58 | { 59 | "type": "Argument", 60 | "name": { 61 | "type": "Name", 62 | "value": "value", 63 | "span": { 64 | "start": { 65 | "col": 29, 66 | "row": 1, 67 | "index": 60 68 | }, 69 | "end": { 70 | "col": 34, 71 | "row": 1, 72 | "index": 65 73 | } 74 | } 75 | }, 76 | "value": { 77 | "type": "IntValue", 78 | "code": "100500", 79 | "span": { 80 | "start": { 81 | "col": 36, 82 | "row": 1, 83 | "index": 67 84 | }, 85 | "end": { 86 | "col": 42, 87 | "row": 1, 88 | "index": 73 89 | } 90 | } 91 | }, 92 | "span": { 93 | "start": { 94 | "col": 29, 95 | "row": 1, 96 | "index": 60 97 | }, 98 | "end": { 99 | "col": 42, 100 | "row": 1, 101 | "index": 73 102 | } 103 | } 104 | } 105 | ], 106 | "span": { 107 | "start": { 108 | "col": 17, 109 | "row": 1, 110 | "index": 48 111 | }, 112 | "end": { 113 | "col": 43, 114 | "row": 1, 115 | "index": 74 116 | } 117 | } 118 | } 119 | ], 120 | "span": { 121 | "start": { 122 | "col": 0, 123 | "row": 0, 124 | "index": 0 125 | }, 126 | "end": { 127 | "col": 43, 128 | "row": 1, 129 | "index": 74 130 | } 131 | } 132 | } 133 | ] 134 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/simple_object.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "ObjectTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "Foo", 10 | "span": { 11 | "start": { 12 | "col": 5, 13 | "row": 0, 14 | "index": 5 15 | }, 16 | "end": { 17 | "col": 8, 18 | "row": 0, 19 | "index": 8 20 | } 21 | } 22 | }, 23 | "implement_interfaces": null, 24 | "field_definations": [ 25 | { 26 | "description": null, 27 | "name": { 28 | "type": "Name", 29 | "value": "bar", 30 | "span": { 31 | "start": { 32 | "col": 2, 33 | "row": 1, 34 | "index": 13 35 | }, 36 | "end": { 37 | "col": 5, 38 | "row": 1, 39 | "index": 16 40 | } 41 | } 42 | }, 43 | "argument_definations": null, 44 | "directives": null, 45 | "var_type": { 46 | "type": "NameVarType", 47 | "name": "Type", 48 | "span": { 49 | "start": { 50 | "col": 7, 51 | "row": 1, 52 | "index": 18 53 | }, 54 | "end": { 55 | "col": 11, 56 | "row": 1, 57 | "index": 22 58 | } 59 | } 60 | }, 61 | "span": { 62 | "start": { 63 | "col": 2, 64 | "row": 1, 65 | "index": 13 66 | }, 67 | "end": { 68 | "col": 11, 69 | "row": 1, 70 | "index": 22 71 | } 72 | } 73 | } 74 | ], 75 | "directives": null, 76 | "span": { 77 | "start": { 78 | "col": 5, 79 | "row": 0, 80 | "index": 5 81 | }, 82 | "end": { 83 | "col": 1, 84 | "row": 2, 85 | "index": 24 86 | } 87 | } 88 | } 89 | ] 90 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/union.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "UnionTypeDefinition", 6 | "description": null, 7 | "name": { 8 | "type": "Name", 9 | "value": "Feed", 10 | "span": { 11 | "start": { 12 | "col": 6, 13 | "row": 0, 14 | "index": 6 15 | }, 16 | "end": { 17 | "col": 10, 18 | "row": 0, 19 | "index": 10 20 | } 21 | } 22 | }, 23 | "directives": null, 24 | "union_member_types": [ 25 | { 26 | "name": "Story", 27 | "span": { 28 | "start": { 29 | "col": 13, 30 | "row": 0, 31 | "index": 13 32 | }, 33 | "end": { 34 | "col": 18, 35 | "row": 0, 36 | "index": 18 37 | } 38 | } 39 | }, 40 | { 41 | "name": "Article", 42 | "span": { 43 | "start": { 44 | "col": 21, 45 | "row": 0, 46 | "index": 21 47 | }, 48 | "end": { 49 | "col": 28, 50 | "row": 0, 51 | "index": 28 52 | } 53 | } 54 | }, 55 | { 56 | "name": "Advert", 57 | "span": { 58 | "start": { 59 | "col": 31, 60 | "row": 0, 61 | "index": 31 62 | }, 63 | "end": { 64 | "col": 37, 65 | "row": 0, 66 | "index": 37 67 | } 68 | } 69 | } 70 | ], 71 | "span": { 72 | "start": { 73 | "col": 6, 74 | "row": 0, 75 | "index": 6 76 | }, 77 | "end": { 78 | "col": 37, 79 | "row": 0, 80 | "index": 37 81 | } 82 | } 83 | } 84 | ] 85 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/fixtures/graphql_rust/schema/union_extension.ast.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Document", 3 | "definations": [ 4 | { 5 | "type": "UnionTypeExtension", 6 | "name": { 7 | "type": "Name", 8 | "value": "Feed", 9 | "span": { 10 | "start": { 11 | "col": 13, 12 | "row": 0, 13 | "index": 13 14 | }, 15 | "end": { 16 | "col": 17, 17 | "row": 0, 18 | "index": 17 19 | } 20 | } 21 | }, 22 | "directives": null, 23 | "union_member_types": [ 24 | { 25 | "name": "Photo", 26 | "span": { 27 | "start": { 28 | "col": 20, 29 | "row": 0, 30 | "index": 20 31 | }, 32 | "end": { 33 | "col": 25, 34 | "row": 0, 35 | "index": 25 36 | } 37 | } 38 | }, 39 | { 40 | "name": "Video", 41 | "span": { 42 | "start": { 43 | "col": 28, 44 | "row": 0, 45 | "index": 28 46 | }, 47 | "end": { 48 | "col": 33, 49 | "row": 0, 50 | "index": 33 51 | } 52 | } 53 | } 54 | ], 55 | "span": { 56 | "start": { 57 | "col": 0, 58 | "row": 0, 59 | "index": 0 60 | }, 61 | "end": { 62 | "col": 33, 63 | "row": 0, 64 | "index": 33 65 | } 66 | } 67 | } 68 | ] 69 | } -------------------------------------------------------------------------------- /crates/rustgql_parser/tests/parser_graphql_rust_schema_test.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | mod test { 3 | use rustgql_parser::parser::Parser; 4 | use std::fs::{File, read_to_string}; 5 | use std::io::Write; 6 | use std::env; 7 | use serde_json::to_string_pretty; 8 | 9 | fn get_fixtures_folder_path(file_path: &'static str) -> String { 10 | String::from(env::current_dir().unwrap().join("../../fixtures").join(file_path).as_os_str().to_str().unwrap()) 11 | } 12 | fn get_test_folder_path(file_path: &'static str) -> String { 13 | format!("./tests/fixtures/{}", file_path) 14 | } 15 | macro_rules! test_case_for_parser { 16 | ($path: expr) => { 17 | let ql_file_path = format!("{}.graphql",get_fixtures_folder_path($path)); 18 | let ast_file_path = format!("{}.ast.json", get_test_folder_path($path)); 19 | 20 | let ql_file_str = match read_to_string(ql_file_path.as_str()) { 21 | Ok(ql_str) => ql_str, 22 | Err(_reason) => panic!("[Test Error]: Can not find test file {:?}", ql_file_path.as_str()) 23 | }; 24 | let mut parser = Parser::new(ql_file_str.as_str()); 25 | let root = parser.parse(); 26 | 27 | match read_to_string(ast_file_path.as_str()) { 28 | Ok(ast_str) => { 29 | assert_eq!(ast_str, to_string_pretty(&root).unwrap()); 30 | }, 31 | Err(_reason) => { 32 | let mut output = File::create(ast_file_path.as_str()).unwrap(); 33 | write!(output, "{}",to_string_pretty(&root).unwrap().as_str()).unwrap(); 34 | } 35 | }; 36 | }; 37 | } 38 | #[test] 39 | fn test_parser_schema_directive_descriptions_canonical() { 40 | test_case_for_parser!("graphql_rust/schema/directive_descriptions_canonical"); 41 | } 42 | #[test] 43 | fn test_parser_schema_directive_descriptions() { 44 | test_case_for_parser!("graphql_rust/schema/directive_descriptions"); 45 | } 46 | #[test] 47 | fn test_parser_schema_directive_variable_definition() { 48 | test_case_for_parser!("graphql_rust/schema/directive_variable_definition"); 49 | } 50 | #[test] 51 | fn test_parser_schema_directive() { 52 | test_case_for_parser!("graphql_rust/schema/directive"); 53 | } 54 | #[test] 55 | fn test_parser_schema_empty_union() { 56 | test_case_for_parser!("graphql_rust/schema/empty_union"); 57 | } 58 | #[test] 59 | fn test_parser_schema_enum() { 60 | test_case_for_parser!("graphql_rust/schema/enum"); 61 | } 62 | #[test] 63 | fn test_parser_schema_extend_enum() { 64 | test_case_for_parser!("graphql_rust/schema/extend_enum"); 65 | } 66 | #[test] 67 | fn test_parser_schema_extend_input_canonical() { 68 | test_case_for_parser!("graphql_rust/schema/extend_input_canonical"); 69 | } 70 | #[test] 71 | fn test_parser_schema_extend_input() { 72 | test_case_for_parser!("graphql_rust/schema/extend_input"); 73 | } 74 | #[test] 75 | fn test_parser_schema_extend_interface() { 76 | test_case_for_parser!("graphql_rust/schema/extend_interface"); 77 | } 78 | #[test] 79 | fn test_parser_schema_extend_object() { 80 | test_case_for_parser!("graphql_rust/schema/extend_object"); 81 | } 82 | #[test] 83 | fn test_parser_schema_extend_scalar() { 84 | test_case_for_parser!("graphql_rust/schema/extend_scalar"); 85 | } 86 | #[test] 87 | fn test_parser_schema_implements_amp_canonical() { 88 | test_case_for_parser!("graphql_rust/schema/implements_amp_canonical"); 89 | } 90 | #[test] 91 | fn test_parser_schema_implements_amp() { 92 | test_case_for_parser!("graphql_rust/schema/implements_amp"); 93 | } 94 | #[test] 95 | fn test_parser_schema_implements_interface() { 96 | test_case_for_parser!("graphql_rust/schema/implements_interface"); 97 | } 98 | #[test] 99 | fn test_parser_schema_implements() { 100 | test_case_for_parser!("graphql_rust/schema/implements"); 101 | } 102 | #[test] 103 | fn test_parser_schema_input_type() { 104 | test_case_for_parser!("graphql_rust/schema/input_type"); 105 | } 106 | #[test] 107 | fn test_parser_schema_interface() { 108 | test_case_for_parser!("graphql_rust/schema/interface"); 109 | } 110 | #[test] 111 | fn test_parser_schema_kitchen_sink_canonical() { 112 | test_case_for_parser!("graphql_rust/schema/kitchen-sink_canonical"); 113 | } 114 | #[test] 115 | fn test_parser_schema_kitchen_sink() { 116 | test_case_for_parser!("graphql_rust/schema/kitchen-sink"); 117 | } 118 | #[test] 119 | fn test_parser_schema_minimal_type() { 120 | test_case_for_parser!("graphql_rust/schema/minimal_type"); 121 | } 122 | #[test] 123 | fn test_parser_schema_minimal() { 124 | test_case_for_parser!("graphql_rust/schema/minimal"); 125 | } 126 | #[test] 127 | fn test_parser_schema_repeatable() { 128 | test_case_for_parser!("graphql_rust/schema/repeatable"); 129 | } 130 | #[test] 131 | fn test_parser_schema_scalar_type() { 132 | test_case_for_parser!("graphql_rust/schema/scalar_type"); 133 | } 134 | #[test] 135 | fn test_parser_schema_simple_object() { 136 | test_case_for_parser!("graphql_rust/schema/simple_object"); 137 | } 138 | #[test] 139 | fn test_parser_schema_union_extension() { 140 | test_case_for_parser!("graphql_rust/schema/union_extension"); 141 | } 142 | #[test] 143 | fn test_parser_schema_union() { 144 | test_case_for_parser!("graphql_rust/schema/union"); 145 | } 146 | } -------------------------------------------------------------------------------- /crates/rustgql_typegen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustgql_typegen" 3 | authors = ["Solo-steven"] 4 | description = "generate typescript file from graphql schma" 5 | version = "0.1.0" 6 | edition = "2021" 7 | license-file = "../../LICENSE" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [dependencies] 12 | rustgql_common = { version = "0.1.0", path = "../rustgql_common"} 13 | 14 | [dev-dependencies] 15 | criterion = { version = "0.4", features = ["html_reports"] } 16 | serde = "1.0.183" 17 | serde_derive = "1.0.183" 18 | serde_json = "1.0.104" 19 | -------------------------------------------------------------------------------- /crates/rustgql_typegen/src/graphql_table.rs: -------------------------------------------------------------------------------- 1 | use rustgql_common::ast::common::*; 2 | use rustgql_common::ast::query::*; 3 | use rustgql_common::ast::schema::*; 4 | use std::collections::HashMap; 5 | use std::collections::HashSet; 6 | use std::borrow::Cow; 7 | 8 | #[derive(Debug, Clone, PartialEq)] 9 | pub struct GrahpQLTable<'a> { 10 | type_table: HashMap, HashMap, VarType<'a>>>, 11 | union_table: HashMap, HashSet>>, 12 | fragment_table: HashMap, SelectSet<'a>>, 13 | interface_table: HashMap, HashMap, VarType<'a>>>, 14 | } 15 | 16 | impl<'a> Default for GrahpQLTable<'a> { 17 | fn default() -> Self { 18 | Self::new() 19 | } 20 | } 21 | /// GraphQL table is generate by schema AST, it is design for query generator to look up 22 | /// table to find the correct type for generate type definition for query generator. 23 | impl<'a> GrahpQLTable<'a> { 24 | pub fn new() -> Self { 25 | Self { 26 | type_table: HashMap::new(), 27 | union_table: HashMap::new(), 28 | fragment_table: HashMap::new(), 29 | interface_table: HashMap::new(), 30 | } 31 | } 32 | pub fn build_table(&mut self, document: &Document<'a>) { 33 | self.accept_document(document); 34 | } 35 | pub fn look_up_property(&self,type_name: &Cow<'a, str>, property_name: &Cow<'a, str>) -> Option<&VarType<'a>> { 36 | if let Some(table_of_type) = self.type_table.get(type_name) { 37 | table_of_type.get(property_name) 38 | }else { 39 | None 40 | } 41 | } 42 | pub fn look_up_fragment(&self, fragment_name: &Cow<'a, str>) -> Option<&SelectSet<'a>> { 43 | self.fragment_table.get(fragment_name) 44 | } 45 | pub fn look_up_union(&self, union_name: &Cow<'a, str>) -> Option<&HashSet>> { 46 | self.union_table.get(union_name) 47 | } 48 | fn accept_document(&mut self, document: &Document<'a>) { 49 | for definition in &document.definations { 50 | if let Defination::InterfaceTypeDefinition(ref interface_def) = *definition { 51 | self.accept_interface_definition(interface_def); 52 | } 53 | } 54 | for definition in &document.definations { 55 | match *definition { 56 | Defination::ObjectTypeDefinition(ref object_def) => self.accept_object_definition(object_def), 57 | Defination::UnionTypeDefinition(ref union_ref) => self.accept_union_definition(union_ref), 58 | Defination::FragmentDefination(ref fragment_def) => self.accept_fragment(fragment_def), 59 | _ => {} 60 | } 61 | } 62 | } 63 | fn accept_fragment(&mut self, definition: &FragmentDefination<'a>) { 64 | self.fragment_table.insert(definition.name.value.clone(), definition.selectionset.clone()); 65 | } 66 | fn accept_union_definition(&mut self, definition: &UnionTypeDefinition<'a>) { 67 | let set = match definition.union_member_types { 68 | Some(ref members) => { 69 | members.iter().map(|member| member.name.clone()).collect() 70 | } 71 | None => HashSet::new(), 72 | }; 73 | self.union_table.insert(definition.name.value.clone(), set); 74 | } 75 | fn accept_object_definition(&mut self, definition: &ObjectTypeDefinition<'a>) { 76 | let mut property_table = HashMap::new(); 77 | if let Some(implement_interfaces) = &definition.implement_interfaces { 78 | for interface in implement_interfaces { 79 | if let Some(interface_hash_table) = self.interface_table.get(&interface.name) { 80 | for (key, value) in interface_hash_table.iter() { 81 | property_table.insert(key.clone(), value.clone()); 82 | } 83 | } 84 | } 85 | } 86 | if let Some(object_fields) = &definition.field_definations { 87 | for object_field in object_fields { 88 | let property_name = object_field.name.value.clone(); 89 | let property_type = object_field.var_type.clone(); 90 | property_table.insert(property_name, property_type); 91 | } 92 | self.type_table.insert(definition.name.value.clone(), property_table); 93 | } 94 | } 95 | fn accept_interface_definition(&mut self, definition: &InterfaceTypeDefinition<'a>) { 96 | if let Some(object_fields) = &definition.field_definations { 97 | let mut property_table = HashMap::new(); 98 | for object_field in object_fields { 99 | let property_name = object_field.name.value.clone(); 100 | let property_type = object_field.var_type.clone(); 101 | property_table.insert(property_name, property_type); 102 | } 103 | self.interface_table.insert(definition.name.value.clone(), property_table); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /crates/rustgql_typegen/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod graphql_table; 2 | pub mod schema_generator; 3 | pub mod query_generator; -------------------------------------------------------------------------------- /fixtures/baseline/query_complex.graphql: -------------------------------------------------------------------------------- 1 | query test( 2 | $devicePicSize: SomeObjectType = { name: 4, size: ENUM } 3 | $devicePicSiz1e: SomeListType = ["test", 4, ENUMvalu, true, ""] 4 | ) { 5 | user(id: 4, name: { value: $size }) 6 | @include(if: $expandedInfo) 7 | @include(if: $expandedInfo) { 8 | id 9 | name 10 | smallPic: profilePic(size: 64) 11 | bigPic: profilePic(size: 1024) 12 | ... inline 13 | ... on Test { 14 | some 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /fixtures/graphql_github/query_simple.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | viewer { 3 | login 4 | } 5 | } -------------------------------------------------------------------------------- /fixtures/graphql_rust/errors/bad_args.graphql: -------------------------------------------------------------------------------- 1 | query MyQuery { 2 | field1([something]) 3 | } -------------------------------------------------------------------------------- /fixtures/graphql_rust/errors/invalid_curly_brace.graphql: -------------------------------------------------------------------------------- 1 | querry MyQuery { 2 | field1 3 | } -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/directive_args.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node @dir(a: 1, b: "2", c: true, d: false, e: null) 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/directive_args_multiline.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node @dir( 3 | a: 1, 4 | b: "2", 5 | c: true, 6 | d: false, 7 | e: null 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/fragment.graphql: -------------------------------------------------------------------------------- 1 | fragment frag on Friend { 2 | node 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/fragment_spread.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node { 3 | id 4 | ...something 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/inline_fragment.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node { 3 | id 4 | ... on User { 5 | name 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/inline_fragment_dir.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node { 3 | id 4 | ... on User @defer { 5 | name 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/kitchen-sink.graphql: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-present, Facebook, Inc. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | query queryName($foo: ComplexType, $site: Site = MOBILE) { 7 | whoever123is: node(id: [123, 456]) { 8 | id , 9 | ... on User @defer { 10 | field2 { 11 | id , 12 | alias: field1(first:10, after:$foo,) @include(if: $foo) { 13 | id, 14 | ...frag 15 | } 16 | } 17 | } 18 | ... @skip(unless: $foo) { 19 | id 20 | } 21 | ... { 22 | id 23 | } 24 | } 25 | } 26 | 27 | mutation likeStory { 28 | like(story: 123) @defer { 29 | story { 30 | id 31 | } 32 | } 33 | } 34 | 35 | subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { 36 | storyLikeSubscribe(input: $input) { 37 | story { 38 | likers { 39 | count 40 | } 41 | likeSentence { 42 | text 43 | } 44 | } 45 | } 46 | } 47 | 48 | fragment frag on Friend { 49 | foo(size: $size, bar: $b, obj: {key: "value", block: """ 50 | 51 | block string uses \""" 52 | 53 | """}) 54 | } 55 | 56 | { 57 | unnamed(truthy: true, falsey: false, nullish: null), 58 | query 59 | } 60 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/kitchen-sink_canonical.graphql: -------------------------------------------------------------------------------- 1 | query queryName($foo: ComplexType, $site: Site = MOBILE) { 2 | whoever123is: node(id: [123, 456]) { 3 | id 4 | ... on User @defer { 5 | field2 { 6 | id 7 | alias: field1(first: 10, after: $foo) @include(if: $foo) { 8 | id 9 | ...frag 10 | } 11 | } 12 | } 13 | ... @skip(unless: $foo) { 14 | id 15 | } 16 | ... { 17 | id 18 | } 19 | } 20 | } 21 | 22 | mutation likeStory { 23 | like(story: 123) @defer { 24 | story { 25 | id 26 | } 27 | } 28 | } 29 | 30 | subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { 31 | storyLikeSubscribe(input: $input) { 32 | story { 33 | likers { 34 | count 35 | } 36 | likeSentence { 37 | text 38 | } 39 | } 40 | } 41 | } 42 | 43 | fragment frag on Friend { 44 | foo(size: $size, bar: $b, obj: {block: """ 45 | 46 | block string uses \""" 47 | 48 | """, key: "value"}) 49 | } 50 | 51 | { 52 | unnamed(truthy: true, falsey: false, nullish: null) 53 | query 54 | } 55 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/minimal.graphql: -------------------------------------------------------------------------------- 1 | { 2 | a 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/minimal_mutation.graphql: -------------------------------------------------------------------------------- 1 | mutation { 2 | notify 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/minimal_query.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/mutation_directive.graphql: -------------------------------------------------------------------------------- 1 | mutation @directive { 2 | node 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/mutation_nameless_vars.graphql: -------------------------------------------------------------------------------- 1 | mutation($first: Int, $second: Int) { 2 | field1(first: $first) 3 | field2(second: $second) 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/named_query.graphql: -------------------------------------------------------------------------------- 1 | query Foo { 2 | field 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/nested_selection.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node { 3 | id 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_aliases.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | an_alias: node 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_arguments.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node(id: 1) 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_arguments_multiline.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node( 3 | id: 1 4 | ) 5 | node( 6 | id: 1, 7 | one: 3 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_array_argument_multiline.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node( 3 | id: [ 4 | 5, 5 | 6, 6 | 7 7 | ] 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_directive.graphql: -------------------------------------------------------------------------------- 1 | query @directive { 2 | node 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_list_argument.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node(id: 1, list: [123, 456]) 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_nameless_vars.graphql: -------------------------------------------------------------------------------- 1 | query($first: Int, $second: Int) { 2 | field1(first: $first) 3 | field2(second: $second) 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_nameless_vars_multiple_fields.graphql: -------------------------------------------------------------------------------- 1 | ,,,,,,,,,,,,,,,,, 2 | query ,,,,,,, ($houseId: String!, $streetNumber: Int!) ,,,,,,,,,,,, { # comment 3 | ,,,,,,,,,,,,,,,,,, # commas should be fine 4 | house(id: $houseId) { 5 | id 6 | name 7 | lat 8 | lng 9 | } 10 | street(number: $streetNumber) { # this is a comment 11 | id 12 | } 13 | houseStreet(id: $houseId, number: $streetNumber) { 14 | id 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_nameless_vars_multiple_fields_canonical.graphql: -------------------------------------------------------------------------------- 1 | query($houseId: String!, $streetNumber: Int!) { 2 | house(id: $houseId) { 3 | id 4 | name 5 | lat 6 | lng 7 | } 8 | street(number: $streetNumber) { 9 | id 10 | } 11 | houseStreet(id: $houseId, number: $streetNumber) { 12 | id 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_object_argument.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node(id: 1, obj: {key1: 123, key2: 456}) 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_object_argument_multiline.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node( 3 | id: 1, 4 | obj: { 5 | key1: 123, 6 | key2: 456 7 | } 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_var_default_float.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site: Float = 0.5) { 2 | field 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_var_default_list.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site: [Int] = [123, 456]) { 2 | field 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_var_default_object.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site: Site = {url: null}) { 2 | field 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_var_default_string.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site: String = "string") { 2 | field 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_var_defaults.graphql: -------------------------------------------------------------------------------- 1 | query Foo($site: Site = MOBILE) { 2 | field 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/query_vars.graphql: -------------------------------------------------------------------------------- 1 | query Foo($arg: SomeType) { 2 | field 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/string_literal.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node(id: "hello") 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/subscription_directive.graphql: -------------------------------------------------------------------------------- 1 | subscription @directive { 2 | node 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/query/triple_quoted_literal.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node(id: """ 3 | Hello, 4 | world! 5 | """) 6 | } 7 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/directive.graphql: -------------------------------------------------------------------------------- 1 | directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 2 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/directive_descriptions.graphql: -------------------------------------------------------------------------------- 1 | """ 2 | Directs the executor to include this field or fragment only when the `if` argument is true. 3 | """ 4 | directive @include( 5 | """ 6 | Included when true. 7 | """ 8 | if: Boolean! 9 | ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 10 | 11 | """ 12 | Directs the executor to skip this field or fragment when the `if` argument is true. 13 | """ 14 | directive @skip( 15 | """ 16 | Skipped when true. 17 | """ 18 | if: Boolean! 19 | ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 20 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/directive_descriptions_canonical.graphql: -------------------------------------------------------------------------------- 1 | """ 2 | Directs the executor to include this field or fragment only when the `if` argument is true. 3 | """ 4 | directive @include(""" 5 | Included when true. 6 | """ if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 7 | 8 | """ 9 | Directs the executor to skip this field or fragment when the `if` argument is true. 10 | """ 11 | directive @skip(""" 12 | Skipped when true. 13 | """ if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 14 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/directive_variable_definition.graphql: -------------------------------------------------------------------------------- 1 | directive @configurable on VARIABLE_DEFINITION 2 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/empty_union.graphql: -------------------------------------------------------------------------------- 1 | union UndefinedUnion 2 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/enum.graphql: -------------------------------------------------------------------------------- 1 | enum Site { 2 | DESKTOP 3 | MOBILE 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/extend_enum.graphql: -------------------------------------------------------------------------------- 1 | extend enum Site { 2 | VR 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/extend_input.graphql: -------------------------------------------------------------------------------- 1 | extend input InputType { 2 | other: Float = 1.23e4 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/extend_input_canonical.graphql: -------------------------------------------------------------------------------- 1 | extend input InputType { 2 | other: Float = 12300 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/extend_interface.graphql: -------------------------------------------------------------------------------- 1 | extend interface Bar { 2 | two(argument: InputType!): Type 3 | } 4 | 5 | extend interface Foo implements IOne & ITwo { 6 | three(argument: [InputType!]!): Type 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/extend_object.graphql: -------------------------------------------------------------------------------- 1 | extend type Foo { 2 | seven(argument: [String]): Type 3 | } 4 | 5 | extend type Bar implements IOne & ITwo { 6 | five(argument: [String!]!): Type 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/extend_scalar.graphql: -------------------------------------------------------------------------------- 1 | extend scalar CustomScalar @onScalar 2 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/implements.graphql: -------------------------------------------------------------------------------- 1 | type Type1 implements IOne 2 | 3 | type Type1 implements IOne & ITwo 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/implements_amp.graphql: -------------------------------------------------------------------------------- 1 | type Type1 implements & IOne & ITwo 2 | type Type2 implements & IOne 3 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/implements_amp_canonical.graphql: -------------------------------------------------------------------------------- 1 | type Type1 implements IOne & ITwo 2 | 3 | type Type2 implements IOne 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/implements_interface.graphql: -------------------------------------------------------------------------------- 1 | interface IOne implements ITwo 2 | 3 | interface IThree implements IFour & IFive 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/input_type.graphql: -------------------------------------------------------------------------------- 1 | input InputType { 2 | key: String! 3 | answer: Int = 42 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/interface.graphql: -------------------------------------------------------------------------------- 1 | interface Bar { 2 | one: Type 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/kitchen-sink.graphql: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-present, Facebook, Inc. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | schema { 7 | query: QueryType 8 | mutation: MutationType 9 | } 10 | 11 | """ 12 | This is a description 13 | of the `Foo` type. 14 | """ 15 | type Foo implements Bar & Baz { 16 | one: Type 17 | two(argument: InputType!): Type 18 | three(argument: InputType, other: String): Int 19 | four(argument: String = "string"): String 20 | five(argument: [String] = ["string", "string"]): String 21 | six(argument: InputType = {key: "value"}): Type 22 | seven(argument: Int = null): Type 23 | } 24 | 25 | type AnnotatedObject @onObject(arg: "value") { 26 | annotatedField(arg: Type = "default" @onArg): Type @onField 27 | } 28 | 29 | type UndefinedType 30 | 31 | extend type Foo { 32 | seven(argument: [String]): Type 33 | } 34 | 35 | extend type Foo @onType 36 | 37 | interface Bar { 38 | one: Type 39 | four(argument: String = "string"): String 40 | } 41 | 42 | interface AnnotatedInterface @onInterface { 43 | annotatedField(arg: Type @onArg): Type @onField 44 | } 45 | 46 | interface UndefinedInterface 47 | 48 | extend interface Bar { 49 | two(argument: InputType!): Type 50 | } 51 | 52 | extend interface Bar @onInterface 53 | 54 | union Feed = Story | Article | Advert 55 | 56 | union AnnotatedUnion @onUnion = A | B 57 | 58 | union AnnotatedUnionTwo @onUnion = | A | B 59 | 60 | union UndefinedUnion 61 | 62 | extend union Feed = Photo | Video 63 | 64 | extend union Feed @onUnion 65 | 66 | scalar CustomScalar 67 | 68 | scalar AnnotatedScalar @onScalar 69 | 70 | extend scalar CustomScalar @onScalar 71 | 72 | enum Site { 73 | DESKTOP 74 | MOBILE 75 | } 76 | 77 | enum AnnotatedEnum @onEnum { 78 | ANNOTATED_VALUE @onEnumValue 79 | OTHER_VALUE 80 | } 81 | 82 | enum UndefinedEnum 83 | 84 | extend enum Site { 85 | VR 86 | } 87 | 88 | extend enum Site @onEnum 89 | 90 | input InputType { 91 | key: String! 92 | answer: Int = 42 93 | } 94 | 95 | input AnnotatedInput @onInputObject { 96 | annotatedField: Type @onField 97 | } 98 | 99 | input UndefinedInput 100 | 101 | extend input InputType { 102 | other: Float = 1.23e4 103 | } 104 | 105 | extend input InputType @onInputObject 106 | 107 | directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 108 | 109 | directive @include(if: Boolean!) 110 | on FIELD 111 | | FRAGMENT_SPREAD 112 | | INLINE_FRAGMENT 113 | 114 | directive @include2(if: Boolean!) on 115 | | FIELD 116 | | FRAGMENT_SPREAD 117 | | INLINE_FRAGMENT 118 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/kitchen-sink_canonical.graphql: -------------------------------------------------------------------------------- 1 | schema { 2 | query: QueryType 3 | mutation: MutationType 4 | } 5 | 6 | """ 7 | This is a description 8 | of the `Foo` type. 9 | """ 10 | type Foo implements Bar & Baz { 11 | one: Type 12 | two(argument: InputType!): Type 13 | three(argument: InputType, other: String): Int 14 | four(argument: String = "string"): String 15 | five(argument: [String] = ["string", "string"]): String 16 | six(argument: InputType = {key: "value"}): Type 17 | seven(argument: Int = null): Type 18 | } 19 | 20 | type AnnotatedObject @onObject(arg: "value") { 21 | annotatedField(arg: Type = "default" @onArg): Type @onField 22 | } 23 | 24 | type UndefinedType 25 | 26 | extend type Foo { 27 | seven(argument: [String]): Type 28 | } 29 | 30 | extend type Foo @onType 31 | 32 | interface Bar { 33 | one: Type 34 | four(argument: String = "string"): String 35 | } 36 | 37 | interface AnnotatedInterface @onInterface { 38 | annotatedField(arg: Type @onArg): Type @onField 39 | } 40 | 41 | interface UndefinedInterface 42 | 43 | extend interface Bar { 44 | two(argument: InputType!): Type 45 | } 46 | 47 | extend interface Bar @onInterface 48 | 49 | union Feed = Story | Article | Advert 50 | 51 | union AnnotatedUnion @onUnion = A | B 52 | 53 | union AnnotatedUnionTwo @onUnion = A | B 54 | 55 | union UndefinedUnion 56 | 57 | extend union Feed = Photo | Video 58 | 59 | extend union Feed @onUnion 60 | 61 | scalar CustomScalar 62 | 63 | scalar AnnotatedScalar @onScalar 64 | 65 | extend scalar CustomScalar @onScalar 66 | 67 | enum Site { 68 | DESKTOP 69 | MOBILE 70 | } 71 | 72 | enum AnnotatedEnum @onEnum { 73 | ANNOTATED_VALUE @onEnumValue 74 | OTHER_VALUE 75 | } 76 | 77 | enum UndefinedEnum 78 | 79 | extend enum Site { 80 | VR 81 | } 82 | 83 | extend enum Site @onEnum 84 | 85 | input InputType { 86 | key: String! 87 | answer: Int = 42 88 | } 89 | 90 | input AnnotatedInput @onInputObject { 91 | annotatedField: Type @onField 92 | } 93 | 94 | input UndefinedInput 95 | 96 | extend input InputType { 97 | other: Float = 12300 98 | } 99 | 100 | extend input InputType @onInputObject 101 | 102 | directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 103 | 104 | directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 105 | 106 | directive @include2(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT 107 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/minimal.graphql: -------------------------------------------------------------------------------- 1 | schema { 2 | query: Query 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/minimal_type.graphql: -------------------------------------------------------------------------------- 1 | type UndefinedType 2 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/repeatable.graphql: -------------------------------------------------------------------------------- 1 | directive @filter(expression: String!) repeatable on FIELD 2 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/scalar_type.graphql: -------------------------------------------------------------------------------- 1 | "This is the best scalar type" 2 | scalar BestType @perfectness(value: 100500) 3 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/simple_object.graphql: -------------------------------------------------------------------------------- 1 | type Foo { 2 | bar: Type 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/union.graphql: -------------------------------------------------------------------------------- 1 | union Feed = Story | Article | Advert 2 | -------------------------------------------------------------------------------- /fixtures/graphql_rust/schema/union_extension.graphql: -------------------------------------------------------------------------------- 1 | extend union Feed = Photo | Video 2 | --------------------------------------------------------------------------------