├── .github ├── FUNDING.yml └── workflows │ ├── auto_comment.yml │ ├── check_pr.yml │ └── publish.yml ├── .gitignore ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── melos.yaml ├── melos_graphql_codegen.iml ├── packages └── graphql_codegen │ ├── .gitignore │ ├── .pubignore │ ├── .vscode │ └── launch.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── build.yaml │ ├── example │ ├── .gitignore │ ├── analysis_options.yaml │ ├── build.yaml │ ├── lib │ │ ├── fragments.graphql │ │ ├── fragments.graphql.dart │ │ ├── main.dart │ │ ├── main.graphql │ │ ├── main.graphql.dart │ │ ├── scalars.dart │ │ ├── schema.graphqls │ │ └── schema.graphqls.dart │ ├── melos_graphql_codegen_example.iml │ ├── pubspec.lock │ ├── pubspec.yaml │ ├── pubspec_overrides.yaml │ └── test │ │ ├── cache_access_test.dart │ │ ├── copy_with_test.dart │ │ ├── equality_test.dart │ │ ├── input_test.dart │ │ └── scalar_parser_test.dart │ ├── lib │ ├── builder.dart │ ├── graphql_codegen.dart │ └── src │ │ ├── config │ │ ├── config.dart │ │ └── config.g.dart │ │ ├── context │ │ ├── context.dart │ │ ├── name.dart │ │ └── schema.dart │ │ ├── errors.dart │ │ ├── printer │ │ ├── base │ │ │ ├── constants.dart │ │ │ ├── copy.dart │ │ │ ├── deep_copy.dart │ │ │ ├── deprecation.dart │ │ │ ├── document.dart │ │ │ ├── enum.dart │ │ │ ├── equality.dart │ │ │ ├── fragment.dart │ │ │ ├── input.dart │ │ │ ├── json.dart │ │ │ ├── operation.dart │ │ │ ├── property.dart │ │ │ ├── schema.dart │ │ │ ├── undefined.dart │ │ │ └── utils.dart │ │ ├── clients │ │ │ ├── graphql.dart │ │ │ ├── graphql_flutter.dart │ │ │ └── utils.dart │ │ ├── context.dart │ │ ├── keywords.dart │ │ ├── printer.dart │ │ └── utils.dart │ │ ├── transform │ │ ├── add_typename_transforming_visitor.dart │ │ ├── fix_unnamed_operations_visitor.dart │ │ ├── transform.dart │ │ └── transforming_visitor.dart │ │ └── visitor │ │ └── context_visitor.dart │ ├── melos_graphql_codegen.iml │ ├── pubspec.lock │ ├── pubspec.yaml │ └── test │ ├── assets │ ├── add_typenames │ │ ├── options.json │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── condition_example │ │ ├── fragments.graphql │ │ ├── fragments.graphql.dart │ │ ├── query.graphql │ │ ├── query.graphql.dart │ │ ├── schema.graphql │ │ ├── schema.graphql.dart │ │ └── test.dart │ ├── copy_with │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── custom_enums │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ ├── document_2.graphql │ │ ├── document_2.graphql.dart │ │ ├── enum.dart │ │ └── options.json │ ├── deprecated │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── disable_copy_with │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── duplicate_names │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── enum_custom_fallback │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── enums │ │ ├── options.json │ │ ├── query.graphql │ │ ├── query.graphql.dart │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── extends │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── first_test │ │ ├── a.graphql │ │ ├── a.graphql.dart │ │ ├── fragments.graphql │ │ ├── fragments.graphql.dart │ │ ├── options.json │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── fragment_and_field │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── fragment_enum_variables │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── fragment_imports │ │ ├── document1.graphql │ │ ├── document1.graphql.dart │ │ ├── document2.graphql │ │ ├── document2.graphql.dart │ │ ├── options.json │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── fragment_override │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── fragment_variables │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── fragment_variables_2 │ │ ├── options.json │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── fragments_and_loose_type_requirements │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── fragments_inheritence │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── fragments_nested_data │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── gql_extensions │ │ ├── document.gql │ │ └── document.gql.dart │ ├── graphql_client │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── graphql_client_nested_fragments │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ ├── document2.graphql │ │ ├── document2.graphql.dart │ │ └── options.json │ ├── graphql_flutter_client_infer_graphql_client │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── graphql_flutter_client_mutation_no_arguments │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── graphql_flutter_client_mutation_optional_arguments │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── graphql_flutter_client_mutation_required_arguments │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── graphql_flutter_client_query_no_arguments │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── graphql_flutter_client_query_optional_arguments │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── graphql_flutter_client_query_required_arguments │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── graphql_flutter_client_subscription │ │ ├── options.json │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── graphql_flutter_naming_config │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── header │ │ ├── options.json │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── include_if_null_input │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── include_skip │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── input │ │ ├── input.graphql │ │ ├── input.graphql.dart │ │ └── options.json │ ├── input_builder │ │ ├── input.graphql │ │ ├── input.graphql.dart │ │ ├── input_test.dart │ │ └── options.json │ ├── input_oneOf │ │ ├── input.graphql │ │ ├── input.graphql.dart │ │ └── options.json │ ├── interface_and_fragments │ │ ├── options.json │ │ ├── query.graphql │ │ ├── query.graphql.dart │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── interfaces_and_concrete_types │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── introspection_schema │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── issue_158 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_160 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_168 │ │ ├── payload_test.dart │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── issue_179 │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── issue_181 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_184 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_191 │ │ ├── mutation.graphql │ │ ├── mutation.graphql.dart │ │ ├── options.json │ │ ├── query.graphql │ │ ├── query.graphql.dart │ │ ├── schema.graphql │ │ ├── schema.graphql.dart │ │ ├── subscription.graphql │ │ └── subscription.graphql.dart │ ├── issue_192 │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── serializer_test.dart │ ├── issue_206 │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── issue_217 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_229 │ │ ├── graphql │ │ │ ├── builder_options.json │ │ │ ├── options.json │ │ │ ├── schemaA │ │ │ │ └── document.graphql │ │ │ └── schemaB │ │ │ │ └── document.graphql │ │ └── lib │ │ │ └── generated │ │ │ ├── schemaA │ │ │ └── document.graphql.dart │ │ │ └── schemaB │ │ │ └── document.graphql.dart │ ├── issue_239 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_288 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_293 │ │ ├── doc_test.dart │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_306 │ │ ├── document.graphqls │ │ └── document.graphqls.dart │ ├── issue_309 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_318 │ │ ├── builder_options.json │ │ ├── graphql │ │ │ ├── query1 │ │ │ │ └── q.graphql │ │ │ ├── query2 │ │ │ │ └── q.graphql │ │ │ └── schema.graphql │ │ ├── lib │ │ │ ├── query1 │ │ │ │ └── q.graphql.dart │ │ │ ├── query2 │ │ │ │ └── q.graphql.dart │ │ │ └── schema.graphql.dart │ │ └── options.json │ ├── issue_331 │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── issue_348 │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ ├── options.json │ │ └── scalar_import.dart │ ├── issue_370 │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── test.dart │ ├── issue_388 │ │ ├── options.json │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── json_converters │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── lots_of_fragments │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── multiple_interfaces │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── naming_config │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── nested_inline_and_fragment_spread │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── operation_name_collision │ │ ├── mutation.graphql │ │ ├── mutation.graphql.dart │ │ ├── options.json │ │ ├── query.graphql │ │ ├── query.graphql.dart │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── output_directory │ │ ├── __generated │ │ │ └── folder │ │ │ │ └── document.graphql.dart │ │ ├── document.graphql │ │ └── options.json │ ├── output_directory_2 │ │ ├── f1 │ │ │ ├── __generated__ │ │ │ │ └── schema.graphql.dart │ │ │ └── schema.graphql │ │ ├── f2 │ │ │ ├── __generated__ │ │ │ │ └── document.graphql.dart │ │ │ └── document.graphql │ │ └── options.json │ ├── possible_types_map │ │ ├── options.json │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── private_enum_literals │ │ ├── schema.graphql │ │ └── schema.graphql.dart │ ├── query_with_single_fragment │ │ ├── document.graphql │ │ └── document.graphql.dart │ ├── root_relative_in_lib_output │ │ ├── builder_options.json │ │ ├── lib │ │ │ ├── __generated__ │ │ │ │ ├── fragments │ │ │ │ │ └── document.graphql.dart │ │ │ │ ├── queries │ │ │ │ │ └── document.graphql.dart │ │ │ │ └── schema │ │ │ │ │ └── document.graphql.dart │ │ │ ├── fragments │ │ │ │ └── document.graphql │ │ │ ├── queries │ │ │ │ └── document.graphql │ │ │ └── schema │ │ │ │ └── document.graphql │ │ └── options.json │ ├── root_relative_output │ │ ├── builder_options.json │ │ ├── graphql │ │ │ ├── fragments │ │ │ │ └── document.graphql │ │ │ ├── queries │ │ │ │ └── document.graphql │ │ │ └── schema │ │ │ │ └── document.graphql │ │ ├── lib │ │ │ └── __generated__ │ │ │ │ ├── fragments │ │ │ │ └── document.graphql.dart │ │ │ │ ├── queries │ │ │ │ └── document.graphql.dart │ │ │ │ └── schema │ │ │ │ └── document.graphql.dart │ │ └── options.json │ ├── scalars │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ ├── fobbob.dart │ │ ├── options.json │ │ └── scalar_import.dart │ ├── scopes │ │ ├── a.query.graphql │ │ ├── a.query.graphql.dart │ │ ├── a.schema.graphql │ │ ├── a.schema.graphql.dart │ │ ├── b.query.graphql │ │ ├── b.query.graphql.dart │ │ ├── b.schema.graphql │ │ ├── b.schema.graphql.dart │ │ └── options.json │ ├── string_input_bug │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── unions │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── options.json │ ├── unions_and_interfaces │ │ ├── options.json │ │ ├── schema.graphql │ │ ├── schema.graphql.dart │ │ ├── schema2.graphql │ │ └── schema2.graphql.dart │ ├── variables │ │ ├── options.json │ │ ├── schema.graphql │ │ ├── schema.graphql.dart │ │ ├── variables.graphql │ │ └── variables.graphql.dart │ └── when_extensions │ │ ├── document.graphql │ │ ├── document.graphql.dart │ │ └── when_extensions_test.dart │ ├── builder_test.dart │ └── transform_test.dart ├── pubspec.lock └── pubspec.yaml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: heftapp 2 | -------------------------------------------------------------------------------- /.github/workflows/auto_comment.yml: -------------------------------------------------------------------------------- 1 | name: Auto Comment 2 | on: [issues] 3 | jobs: 4 | run: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: wow-actions/auto-comment@v1 8 | with: 9 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 10 | issuesOpened: | 11 | 👋 @{{ author }} 12 | Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible. 13 | Please make sure you have provided enough context. 14 | 15 | This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating [here](https://github.com/sponsors/heftapp). 16 | -------------------------------------------------------------------------------- /.github/workflows/check_pr.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Check PR 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | schedule: 9 | - cron: "0 0 * * 0" 10 | 11 | jobs: 12 | # verify_commits: 13 | # runs-on: ubuntu-latest 14 | # steps: 15 | # - name: Conventional PRs 16 | # uses: Namchee/conventional-pr@v0.10.1 17 | # with: 18 | # access_token: ${{ secrets.GITHUB_TOKEN }} 19 | # issue: false 20 | # verified_commits: true 21 | # close: false 22 | # report: false 23 | 24 | check-release: 25 | runs-on: ubuntu-latest 26 | steps: 27 | - uses: actions/checkout@v2 28 | - uses: subosito/flutter-action@v2 29 | with: 30 | channel: stable 31 | - name: Activate melos 32 | run: | 33 | dart pub get 34 | dart pub global activate melos 35 | - name: Validate publish 36 | run: melos publish --dry-run --yes | tee ./out 37 | - name: Test if changed 38 | run: | 39 | if grep -q "The following packages will be validated only" out; then 40 | PACKAGES=$(cat out | grep -E "Publishing [a-z]" | sed -E 's/Publishing ([a-z_]+).+/\1/g') 41 | for package in $PACKAGES; do 42 | melos exec --scope="$package" -- "dart pub get" 43 | melos exec --scope="$package" -- "dart analyze --fatal-infos ." 44 | melos exec --scope="$package" --dir-exists=test -- "dart test" 45 | done 46 | else 47 | echo "Packages will not be published. Skipping tests." 48 | fi 49 | analyze: 50 | runs-on: ubuntu-latest 51 | strategy: 52 | matrix: 53 | channel: 54 | - beta 55 | - stable 56 | # - dev 57 | steps: 58 | - uses: actions/checkout@v2 59 | - uses: subosito/flutter-action@v2 60 | with: 61 | channel: ${{ matrix.channel }} 62 | - name: Activate melos 63 | run: | 64 | dart pub get 65 | dart pub global activate melos 66 | - name: Bootstrap melos 67 | run: melos bs 68 | - name: Analyze package 69 | run: melos run analyze --no-select 70 | 71 | build: 72 | runs-on: ubuntu-latest 73 | strategy: 74 | matrix: 75 | channel: 76 | - beta 77 | - stable 78 | # - dev 79 | 80 | timeout-minutes: 5 81 | steps: 82 | - uses: actions/checkout@v2 83 | - uses: subosito/flutter-action@v2 84 | with: 85 | channel: ${{ matrix.channel }} 86 | - name: Activate melos 87 | run: | 88 | dart pub get 89 | dart pub global activate melos 90 | - name: Bootstrap melos 91 | run: melos bs 92 | - name: Build dart 93 | run: melos run build_dart --no-select 94 | - name: Build fluter 95 | run: melos run build_flutter --no-select 96 | - name: Bootstrap melos 97 | run: melos bs 98 | - name: Check if changed 99 | run: git diff --exit-code ':!**/pubspec.lock' 100 | 101 | test: 102 | runs-on: ubuntu-latest 103 | strategy: 104 | matrix: 105 | channel: 106 | - beta 107 | - stable 108 | # - dev 109 | 110 | steps: 111 | - uses: actions/checkout@v2 112 | - uses: subosito/flutter-action@v2 113 | with: 114 | channel: ${{ matrix.channel }} 115 | - name: Activate melos 116 | run: | 117 | dart pub get 118 | dart pub global activate melos 119 | - name: Bootstrap melos 120 | run: melos bs 121 | - name: Run tests dart 122 | run: melos run test_dart --no-select 123 | - name: Run tests flutter 124 | run: melos run test_flutter --no-select 125 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Publish 3 | on: 4 | push: 5 | branches: 6 | - main 7 | jobs: 8 | release: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - uses: subosito/flutter-action@v2 13 | with: 14 | channel: stable 15 | - name: Activate melos 16 | run: | 17 | dart pub get 18 | dart pub global activate melos 19 | - name: Login pub 20 | run: | 21 | mkdir -p "$XDG_CONFIG_HOME/dart/" 22 | echo "${{ secrets.PUB_CREDENTIALS}}" | base64 -d > "$XDG_CONFIG_HOME/dart/pub-credentials.json" 23 | - name: Validate publish 24 | run: dart run melos publish --dry-run --yes 25 | - name: Publish 26 | run: dart run melos publish --no-dry-run --yes 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | # pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | /.dart_tool 23 | .idea 24 | 25 | pubspec_overrides.yaml.DS_Store 26 | .DS_Store 27 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Dart: Run all Tests", 9 | "type": "dart", 10 | "request": "launch", 11 | "program": "./test/" 12 | }, 13 | ] 14 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Heft 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 | # GraphQL Codegen 2 | 3 | This project contains a codegeneration tool for GraphQL in Dart. It allows you 4 | to generate type-safe Dart classes for your GraphQL operations. 5 | 6 | It contains the following packages 7 | 8 | * [graphql_codegen](/packages/graphql_codegen) - The build runner generating the Dart classes. 9 | 10 | You'll probably only need `graphql_codegen`. 11 | -------------------------------------------------------------------------------- /melos.yaml: -------------------------------------------------------------------------------- 1 | name: graphql_codegen 2 | 3 | packages: 4 | - packages/** 5 | 6 | scripts: 7 | analyze: 8 | run: melos exec -- "dart analyze --fatal-infos ." 9 | test_dart: 10 | exec: dart test 11 | packageFilters: 12 | flutter: false 13 | dirExists: "test" 14 | test_flutter: 15 | exec: flutter test 16 | packageFilters: 17 | flutter: true 18 | dirExists: "test" 19 | build_dart: 20 | exec: dart run build_runner build --delete-conflicting-outputs 21 | packageFilters: 22 | flutter: false 23 | build_flutter: 24 | exec: flutter pub run build_runner build --delete-conflicting-outputs 25 | packageFilters: 26 | flutter: true 27 | format: 28 | exec: dart format 29 | 30 | command: 31 | bootstrap: 32 | usePubspecOverrides: true -------------------------------------------------------------------------------- /melos_graphql_codegen.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /packages/graphql_codegen/.gitignore: -------------------------------------------------------------------------------- 1 | /generator 2 | /test/**/*.expected 3 | -------------------------------------------------------------------------------- /packages/graphql_codegen/.pubignore: -------------------------------------------------------------------------------- 1 | test 2 | generator 3 | -------------------------------------------------------------------------------- /packages/graphql_codegen/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Dart: Run all Tests", 9 | "type": "dart", 10 | "request": "launch", 11 | "program": "./test/" 12 | }, 13 | ] 14 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Heft 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 | -------------------------------------------------------------------------------- /packages/graphql_codegen/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:lints/core.yaml 2 | analyzer: 3 | language: 4 | strict-casts: true 5 | strict-inference: true 6 | strict-raw-types: true 7 | exclude: 8 | - test/assets 9 | - example/ 10 | -------------------------------------------------------------------------------- /packages/graphql_codegen/build.yaml: -------------------------------------------------------------------------------- 1 | builders: 2 | graphql_codegen: 3 | import: 'package:graphql_codegen/builder.dart' 4 | builder_factories: ['GraphQLBuilder.builder'] 5 | build_extensions: {'$lib$': ['.graphql.dart']} 6 | auto_apply: dependents 7 | build_to: source 8 | runs_before: 9 | - json_serializable:json_serializable 10 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/.gitignore: -------------------------------------------------------------------------------- 1 | .flutter-plugins 2 | .flutter-plugins-dependencies 3 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | analyzer: 2 | language: 3 | strict-casts: true 4 | strict-inference: true 5 | strict-raw-types: true 6 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/build.yaml: -------------------------------------------------------------------------------- 1 | targets: 2 | $default: 3 | builders: 4 | graphql_codegen: 5 | options: 6 | scalars: 7 | URL: 8 | type: String 9 | ISODateTime: 10 | type: DateTime 11 | fromJsonFunctionName: dateTimeFromJson 12 | toJsonFunctionName: dateTimeToJson 13 | import: package:graphql_codegen_example/scalars.dart 14 | clients: 15 | - graphql 16 | - graphql_flutter 17 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/lib/fragments.graphql: -------------------------------------------------------------------------------- 1 | 2 | fragment PersonSummary on Person { 3 | nickname 4 | name: full_name 5 | dob 6 | events 7 | eventsOfEvents: events_of_events 8 | parents { 9 | ...PersonParent 10 | } 11 | favParent: favorite_parent { 12 | ...PersonParent 13 | } 14 | } 15 | 16 | 17 | fragment PersonParent on Person { 18 | name: full_name 19 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:graphql/client.dart'; 2 | 3 | import 'main.graphql.dart'; 4 | 5 | void main() async { 6 | final client = GraphQLClient( 7 | link: HttpLink("https://example.com"), 8 | cache: GraphQLCache(store: InMemoryStore()), 9 | ); 10 | final result = await client.query$FetchPerson( 11 | Options$Query$FetchPerson( 12 | variables: Variables$Query$FetchPerson( 13 | id: "id1", 14 | ), 15 | ), 16 | ); 17 | final parased = result.parsedData; 18 | print(parased?.fetchPerson?.name); 19 | } 20 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/lib/main.graphql: -------------------------------------------------------------------------------- 1 | query FetchPerson ($id: ID!) { 2 | fetchPerson: fetch_person(id: $id) { 3 | ...PersonSummary 4 | parents { 5 | ...PersonSummary 6 | } 7 | children { 8 | ...PersonSummary 9 | } 10 | } 11 | } 12 | 13 | mutation UpdatePerson($id: ID!) { 14 | updatePerson: update_person(id: $id) { 15 | full_name 16 | } 17 | } 18 | 19 | subscription WatchPerson($id: ID) { 20 | watchPerson: watch_person(id: $id) { 21 | full_name 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/lib/scalars.dart: -------------------------------------------------------------------------------- 1 | String dateTimeToJson(DateTime data) { 2 | return data.toIso8601String(); 3 | } 4 | 5 | DateTime dateTimeFromJson(dynamic data) { 6 | return DateTime.parse(data as String); 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/lib/schema.graphqls: -------------------------------------------------------------------------------- 1 | type Query { 2 | fetch_person(id: ID!): Person 3 | } 4 | 5 | type Person { 6 | full_name: String! 7 | nickname: String 8 | website: URL 9 | date_of_birth: ISODateTime 10 | favorite_parent: Person 11 | parents: [Person!] 12 | siblings: [Person!] 13 | children: [Person!] 14 | dob: ISODateTime 15 | events: [ISODateTime] 16 | events_of_events: [[ISODateTime]] 17 | } 18 | 19 | scalar ISODateTime 20 | 21 | scalar URL 22 | 23 | type Mutation { 24 | update_person(id: ID! full_name: String): Person 25 | update_person_advanced(input: UpdatePersonInput!): Person 26 | } 27 | 28 | type Subscription { 29 | watch_person(id: ID): Person 30 | } 31 | 32 | input UpdatePersonInput { 33 | id: ID! 34 | full_name: String 35 | nickname: String 36 | website: URL 37 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/example/melos_graphql_codegen_example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: graphql_codegen_example 2 | 3 | environment: 4 | sdk: ">=2.17.0 <3.0.0" 5 | 6 | dependencies: 7 | graphql_flutter: 5.2.0-beta.8 8 | graphql: 5.2.0-beta.10 9 | flutter: 10 | sdk: flutter 11 | 12 | dev_dependencies: 13 | graphql_codegen: 14 | path: "../" 15 | build_runner: ^2.0.3 16 | test: ^1.17.4 17 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/pubspec_overrides.yaml: -------------------------------------------------------------------------------- 1 | # melos_managed_dependency_overrides: graphql_codegen 2 | dependency_overrides: 3 | graphql_codegen: 4 | path: .. 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/test/cache_access_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:graphql_codegen_example/fragments.graphql.dart'; 2 | import 'package:test/expect.dart'; 3 | import 'package:test/scaffolding.dart'; 4 | 5 | void main() { 6 | group("Serialize fragments", () { 7 | test("Can serialize nested fragments", () { 8 | final fragment = Fragment$PersonSummary( 9 | $__typename: "Person", 10 | name: "Lars", 11 | parents: [ 12 | Fragment$PersonParent( 13 | name: "Father", 14 | $__typename: "Person", 15 | ), 16 | Fragment$PersonParent( 17 | name: "Mother", 18 | $__typename: "Person", 19 | ), 20 | ], 21 | ).toJson(); 22 | expect( 23 | fragment, 24 | equals({ 25 | 'nickname': null, 26 | 'name': 'Lars', 27 | 'dob': null, 28 | 'events': null, 29 | 'eventsOfEvents': null, 30 | 'favParent': null, 31 | 'parents': [ 32 | {'name': 'Father', '__typename': 'Person'}, 33 | {'name': 'Mother', '__typename': 'Person'}, 34 | ], 35 | '__typename': 'Person' 36 | })); 37 | }); 38 | test("Can mutate fragments", () { 39 | final fragment = Fragment$PersonSummary( 40 | $__typename: "Person", 41 | name: "Lars", 42 | parents: [ 43 | Fragment$PersonParent( 44 | name: "Father", 45 | $__typename: "Person", 46 | ), 47 | Fragment$PersonParent( 48 | name: "Mother", 49 | $__typename: "Person", 50 | ), 51 | ], 52 | ); 53 | expect( 54 | fragment.copyWith(name: "Kurt").copyWith(nickname: "Bob").toJson(), 55 | equals({ 56 | 'nickname': "Bob", 57 | 'name': 'Kurt', 58 | 'dob': null, 59 | 'events': null, 60 | 'eventsOfEvents': null, 61 | 'favParent': null, 62 | 'parents': [ 63 | {'name': 'Father', '__typename': 'Person'}, 64 | {'name': 'Mother', '__typename': 'Person'}, 65 | ], 66 | '__typename': 'Person' 67 | })); 68 | }); 69 | }); 70 | } 71 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/test/copy_with_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:graphql_codegen_example/fragments.graphql.dart'; 2 | import 'package:test/expect.dart'; 3 | import 'package:test/scaffolding.dart'; 4 | 5 | void main() { 6 | group("copyWith", () { 7 | test("null on required param", () { 8 | final fragment1 = Fragment$PersonSummary( 9 | name: "Lars", 10 | $__typename: "Person", 11 | nickname: "Lille lars", 12 | ); 13 | final fragment2 = Fragment$PersonSummary( 14 | name: "Lars", 15 | $__typename: "Person", 16 | nickname: "Lille lars 2", 17 | ); 18 | expect( 19 | fragment1.copyWith(name: null, nickname: 'Lille lars 2'), 20 | fragment2, 21 | ); 22 | }); 23 | test("can deep copy null", () { 24 | final fragment1 = Fragment$PersonSummary( 25 | name: "Lars", 26 | $__typename: "Person", 27 | nickname: "Lille lars", 28 | ); 29 | expect( 30 | fragment1.copyWith.favParent(name: 'Lone'), 31 | fragment1, 32 | ); 33 | }); 34 | test("can deep copy can deep copy", () { 35 | final fragment1 = Fragment$PersonSummary( 36 | name: "Lars", 37 | $__typename: "Person", 38 | nickname: "Lille lars", 39 | favParent: Fragment$PersonParent($__typename: 'Person', name: 'Lone'), 40 | ); 41 | final fragment2 = Fragment$PersonSummary( 42 | name: "Lars", 43 | $__typename: "Person", 44 | nickname: "Lille lars", 45 | favParent: Fragment$PersonParent($__typename: 'Person', name: 'Lene'), 46 | ); 47 | expect( 48 | fragment1.copyWith.favParent(name: 'Lene'), 49 | fragment2, 50 | ); 51 | }); 52 | }); 53 | } 54 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/test/equality_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:graphql_codegen_example/main.graphql.dart'; 2 | import 'package:test/expect.dart'; 3 | import 'package:test/scaffolding.dart'; 4 | 5 | void main() { 6 | group('equality', () { 7 | test('MutationOptions considered equal', () { 8 | final o1 = Options$Mutation$UpdatePerson( 9 | variables: Variables$Mutation$UpdatePerson(id: '12134'), 10 | ); 11 | final o2 = Options$Mutation$UpdatePerson( 12 | variables: Variables$Mutation$UpdatePerson(id: '12134'), 13 | ); 14 | expect(o1, equals(o2)); 15 | }); 16 | test('MutationOptions considered equal with callback', () { 17 | final callback = (_d1, _d2) {}; 18 | final o1 = Options$Mutation$UpdatePerson( 19 | variables: Variables$Mutation$UpdatePerson(id: '12134'), 20 | onCompleted: callback, 21 | ); 22 | final o2 = Options$Mutation$UpdatePerson( 23 | variables: Variables$Mutation$UpdatePerson(id: '12134'), 24 | onCompleted: callback, 25 | ); 26 | expect(o1, equals(o2)); 27 | }); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/test/input_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:graphql_codegen_example/schema.graphqls.dart'; 2 | import 'package:test/expect.dart'; 3 | import 'package:test/scaffolding.dart'; 4 | 5 | void main() { 6 | group('Input', () { 7 | test('Equality w/wo null', () { 8 | final i1 = Input$UpdatePersonInput(id: 'id1').copyWith( 9 | full_name: null, 10 | nickname: null, 11 | website: null, 12 | ); 13 | final i2 = Input$UpdatePersonInput(id: 'id1'); 14 | expect(i1, equals(i1)); 15 | expect(i1, isNot(equals(i2))); 16 | expect(i1.hashCode, equals(i1.hashCode)); 17 | expect(i1.hashCode, isNot(equals(i2.hashCode))); 18 | expect( 19 | i1.toJson(), 20 | equals({ 21 | 'id': 'id1', 22 | 'full_name': null, 23 | 'nickname': null, 24 | 'website': null 25 | }), 26 | ); 27 | expect( 28 | i2.toJson(), 29 | equals({ 30 | 'id': 'id1', 31 | }), 32 | ); 33 | }); 34 | test('Copy', () { 35 | final i1 = Input$UpdatePersonInput(id: 'id1', full_name: 'Bob'); 36 | final i2 = Input$UpdatePersonInput(id: 'id1').copyWith(full_name: 'Bob'); 37 | expect(i1, equals(i2)); 38 | expect(i1.hashCode, equals(i2.hashCode)); 39 | }); 40 | }); 41 | } 42 | -------------------------------------------------------------------------------- /packages/graphql_codegen/example/test/scalar_parser_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:graphql_codegen_example/main.graphql.dart'; 4 | import 'package:test/expect.dart'; 5 | import 'package:test/scaffolding.dart'; 6 | 7 | void main() { 8 | group("Can parse custom enum", () { 9 | test("it parses", () { 10 | const json = """ 11 | { 12 | "__typename": "Query", 13 | "fetchPerson": { 14 | "__typename": "Person", 15 | "name": "Bob", 16 | "dob": "1990-03-16T10:07:29.362Z", 17 | "events": [ 18 | "1990-03-16T10:07:29.362Z", 19 | "1990-03-16T10:08:29.362Z", 20 | "1990-03-16T10:09:29.362Z" 21 | ], 22 | "eventsOfEvents": [ 23 | [ 24 | "1990-03-16T10:07:29.362Z" 25 | ], 26 | null 27 | ] 28 | } 29 | } 30 | """; 31 | final parsed = Query$FetchPerson.fromJson( 32 | jsonDecode(json) as Map, 33 | ); 34 | expect( 35 | parsed, 36 | equals( 37 | Query$FetchPerson( 38 | fetchPerson: Query$FetchPerson$fetchPerson( 39 | dob: DateTime.parse("1990-03-16T10:07:29.362Z"), 40 | $__typename: 'Person', 41 | name: 'Bob', 42 | events: [ 43 | DateTime.parse("1990-03-16T10:07:29.362Z"), 44 | DateTime.parse("1990-03-16T10:08:29.362Z"), 45 | DateTime.parse("1990-03-16T10:09:29.362Z") 46 | ], 47 | eventsOfEvents: [ 48 | [ 49 | DateTime.parse("1990-03-16T10:07:29.362Z"), 50 | ], 51 | null, 52 | ]), 53 | $__typename: "Query", 54 | ), 55 | ), 56 | ); 57 | }); 58 | }); 59 | } 60 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/graphql_codegen.dart: -------------------------------------------------------------------------------- 1 | import 'package:built_collection/built_collection.dart'; 2 | import 'package:code_builder/code_builder.dart'; 3 | import 'package:gql/ast.dart'; 4 | import 'package:graphql_codegen/src/config/config.dart'; 5 | import 'package:graphql_codegen/src/printer/context.dart'; 6 | import 'package:graphql_codegen/src/printer/printer.dart'; 7 | import 'package:graphql_codegen/src/context/context.dart'; 8 | import 'package:graphql_codegen/src/visitor/context_visitor.dart'; 9 | 10 | import 'src/context/schema.dart'; 11 | 12 | export 'src/errors.dart'; 13 | export 'src/config/config.dart'; 14 | 15 | Library _generateDocument( 16 | Schema schema, 17 | DocumentNode entry, 18 | TKey key, 19 | GraphQLCodegenConfig config, 20 | ) { 21 | final context = ContextRoot( 22 | schema: schema, 23 | key: key, 24 | config: config, 25 | ); 26 | entry.accept(ContextVisitor(context: context)); 27 | return printRootContext(PrintContext(context)); 28 | } 29 | 30 | /// A schema config containing entries and lookup. 31 | class SchemaConfig { 32 | /// Entries mapped from a key to the DocumentNode 33 | final BuiltMap entries; 34 | 35 | /// A method to lookup a path from the key. 36 | final String Function(TKey) lookupPath; 37 | 38 | /// Self explainatory 39 | SchemaConfig({ 40 | required this.entries, 41 | required this.lookupPath, 42 | }); 43 | 44 | TKey get mainKey { 45 | final defaultOperationDefinitionMap = { 46 | OperationType.query: 'Query', 47 | OperationType.mutation: 'Mutation', 48 | OperationType.subscription: 'Subscription', 49 | }; 50 | final operationDefinitionMap = Map.fromEntries( 51 | entries.entries.expand( 52 | (element) => 53 | element.value.definitions.expand>( 54 | (element) { 55 | if (element is SchemaDefinitionNode) { 56 | return element.operationTypes.map( 57 | (e) => MapEntry( 58 | e.operation, 59 | e.type.name.value, 60 | ), 61 | ); 62 | } 63 | if (element is SchemaExtensionNode) { 64 | return element.operationTypes.map( 65 | (e) => MapEntry( 66 | e.operation, 67 | e.type.name.value, 68 | ), 69 | ); 70 | } 71 | return []; 72 | }, 73 | ), 74 | ), 75 | ); 76 | return [ 77 | OperationType.query, 78 | OperationType.mutation, 79 | OperationType.subscription 80 | ].expand((e) { 81 | final name = 82 | operationDefinitionMap[e] ?? defaultOperationDefinitionMap[e]; 83 | if (name == null) { 84 | return []; 85 | } 86 | return entries.entries 87 | .where( 88 | (element) => element.value.definitions 89 | .whereType() 90 | .where((element) => element.name.value == name) 91 | .isNotEmpty, 92 | ) 93 | .map((documentEntry) => documentEntry.key); 94 | }).firstWhere( 95 | (element) => true, 96 | orElse: () => null, 97 | ) ?? 98 | entries.keys.last; 99 | } 100 | } 101 | 102 | /// This is where the magic happens! It generates 103 | /// programs from GraphQL documents. 104 | Library generate( 105 | TKey key, 106 | 107 | /// Schema containing a mapping from TKey to graphql documents 108 | SchemaConfig schemaConfig, 109 | 110 | /// Configrations containing e.g. clients and scalars. 111 | GraphQLCodegenConfig config, 112 | ) { 113 | final schema = Schema( 114 | schemaConfig.mainKey, 115 | schemaConfig.entries, 116 | schemaConfig.lookupPath, 117 | ); 118 | return _generateDocument( 119 | schema, 120 | schema.lookupDocument(key)!, 121 | key, 122 | config, 123 | ); 124 | } 125 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/config/config.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | part 'config.g.dart'; 3 | 4 | enum GraphQLCodegenConfigClient { 5 | @JsonValue('graphql') 6 | graphql, 7 | @JsonValue('graphql_flutter') 8 | graphqlFlutter 9 | } 10 | 11 | @JsonSerializable() 12 | class GraphQLCodegenConfigScalar { 13 | final String type; 14 | final String? import; 15 | final String? fromJsonFunctionName; 16 | final String? toJsonFunctionName; 17 | 18 | const GraphQLCodegenConfigScalar({ 19 | required this.type, 20 | this.import, 21 | this.fromJsonFunctionName, 22 | this.toJsonFunctionName, 23 | }); 24 | 25 | @override 26 | factory GraphQLCodegenConfigScalar.fromJson(Map json) => 27 | _$GraphQLCodegenConfigScalarFromJson(json); 28 | 29 | Map toJson() => _$GraphQLCodegenConfigScalarToJson(this); 30 | } 31 | 32 | @JsonSerializable() 33 | class GraphQLCodegenConfigEnum { 34 | final String? type; 35 | final String? import; 36 | final String? fromJsonFunctionName; 37 | final String? toJsonFunctionName; 38 | final String? fallbackEnumValue; 39 | 40 | const GraphQLCodegenConfigEnum({ 41 | required this.type, 42 | required this.import, 43 | required this.fromJsonFunctionName, 44 | required this.toJsonFunctionName, 45 | required this.fallbackEnumValue, 46 | }); 47 | 48 | @override 49 | factory GraphQLCodegenConfigEnum.fromJson(Map json) => 50 | _$GraphQLCodegenConfigEnumFromJson(json); 51 | 52 | Map toJson() => _$GraphQLCodegenConfigEnumToJson(this); 53 | } 54 | 55 | @JsonSerializable() 56 | class GraphQLCodegenConfig { 57 | final Set clients; 58 | final Map scalars; 59 | final Map enums; 60 | final bool addTypename; 61 | final String assetsPath; 62 | final List scopes; 63 | final List addTypenameExcludedPaths; 64 | final String generatedFileHeader; 65 | final String namingSeparator; 66 | final List extraKeywords; 67 | final String outputDirectory; 68 | final bool disableContextReplacement; 69 | final bool disableCopyWithGeneration; 70 | final bool allowMissingNullableKeysInFromJson; 71 | final bool setOperationName; 72 | 73 | @JsonKey(name: 'EXPERIMENTAL_enable_input_builders') 74 | final bool enableInputBuilders; 75 | 76 | GraphQLCodegenConfig({ 77 | this.clients = const {}, 78 | this.disableContextReplacement = false, 79 | this.scalars = const {}, 80 | this.enums = const {}, 81 | this.addTypename = true, 82 | this.assetsPath = "lib/**{.graphql,.gql,.graphqls}", 83 | this.scopes = const ["**{.graphql,.gql,.graphqls}"], 84 | this.addTypenameExcludedPaths = const [], 85 | this.generatedFileHeader = "", 86 | this.namingSeparator = r"$", 87 | this.extraKeywords = const [], 88 | this.outputDirectory = '.', 89 | this.disableCopyWithGeneration = false, 90 | this.enableInputBuilders = false, 91 | this.allowMissingNullableKeysInFromJson = false, 92 | this.setOperationName = false, 93 | }); 94 | 95 | @override 96 | factory GraphQLCodegenConfig.fromJson(Map json) => 97 | _$GraphQLCodegenConfigFromJson(json); 98 | 99 | Map toJson() => _$GraphQLCodegenConfigToJson(this); 100 | } 101 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/config/config.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'config.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | GraphQLCodegenConfigScalar _$GraphQLCodegenConfigScalarFromJson( 10 | Map json) => 11 | GraphQLCodegenConfigScalar( 12 | type: json['type'] as String, 13 | import: json['import'] as String?, 14 | fromJsonFunctionName: json['fromJsonFunctionName'] as String?, 15 | toJsonFunctionName: json['toJsonFunctionName'] as String?, 16 | ); 17 | 18 | Map _$GraphQLCodegenConfigScalarToJson( 19 | GraphQLCodegenConfigScalar instance) => 20 | { 21 | 'type': instance.type, 22 | 'import': instance.import, 23 | 'fromJsonFunctionName': instance.fromJsonFunctionName, 24 | 'toJsonFunctionName': instance.toJsonFunctionName, 25 | }; 26 | 27 | GraphQLCodegenConfigEnum _$GraphQLCodegenConfigEnumFromJson( 28 | Map json) => 29 | GraphQLCodegenConfigEnum( 30 | type: json['type'] as String?, 31 | import: json['import'] as String?, 32 | fromJsonFunctionName: json['fromJsonFunctionName'] as String?, 33 | toJsonFunctionName: json['toJsonFunctionName'] as String?, 34 | fallbackEnumValue: json['fallbackEnumValue'] as String?, 35 | ); 36 | 37 | Map _$GraphQLCodegenConfigEnumToJson( 38 | GraphQLCodegenConfigEnum instance) => 39 | { 40 | 'type': instance.type, 41 | 'import': instance.import, 42 | 'fromJsonFunctionName': instance.fromJsonFunctionName, 43 | 'toJsonFunctionName': instance.toJsonFunctionName, 44 | 'fallbackEnumValue': instance.fallbackEnumValue, 45 | }; 46 | 47 | GraphQLCodegenConfig _$GraphQLCodegenConfigFromJson( 48 | Map json) => 49 | GraphQLCodegenConfig( 50 | clients: (json['clients'] as List?) 51 | ?.map((e) => $enumDecode(_$GraphQLCodegenConfigClientEnumMap, e)) 52 | .toSet() ?? 53 | const {}, 54 | disableContextReplacement: 55 | json['disableContextReplacement'] as bool? ?? false, 56 | scalars: (json['scalars'] as Map?)?.map( 57 | (k, e) => MapEntry(k, 58 | GraphQLCodegenConfigScalar.fromJson(e as Map)), 59 | ) ?? 60 | const {}, 61 | enums: (json['enums'] as Map?)?.map( 62 | (k, e) => MapEntry(k, 63 | GraphQLCodegenConfigEnum.fromJson(e as Map)), 64 | ) ?? 65 | const {}, 66 | addTypename: json['addTypename'] as bool? ?? true, 67 | assetsPath: 68 | json['assetsPath'] as String? ?? "lib/**{.graphql,.gql,.graphqls}", 69 | scopes: (json['scopes'] as List?) 70 | ?.map((e) => e as String) 71 | .toList() ?? 72 | const ["**{.graphql,.gql,.graphqls}"], 73 | addTypenameExcludedPaths: 74 | (json['addTypenameExcludedPaths'] as List?) 75 | ?.map((e) => e as String) 76 | .toList() ?? 77 | const [], 78 | generatedFileHeader: json['generatedFileHeader'] as String? ?? "", 79 | namingSeparator: json['namingSeparator'] as String? ?? r"$", 80 | extraKeywords: (json['extraKeywords'] as List?) 81 | ?.map((e) => e as String) 82 | .toList() ?? 83 | const [], 84 | outputDirectory: json['outputDirectory'] as String? ?? '.', 85 | disableCopyWithGeneration: 86 | json['disableCopyWithGeneration'] as bool? ?? false, 87 | enableInputBuilders: 88 | json['EXPERIMENTAL_enable_input_builders'] as bool? ?? false, 89 | allowMissingNullableKeysInFromJson: 90 | json['allowMissingNullableKeysInFromJson'] as bool? ?? false, 91 | setOperationName: json['setOperationName'] as bool? ?? false, 92 | ); 93 | 94 | Map _$GraphQLCodegenConfigToJson( 95 | GraphQLCodegenConfig instance) => 96 | { 97 | 'clients': instance.clients 98 | .map((e) => _$GraphQLCodegenConfigClientEnumMap[e]!) 99 | .toList(), 100 | 'scalars': instance.scalars, 101 | 'enums': instance.enums, 102 | 'addTypename': instance.addTypename, 103 | 'assetsPath': instance.assetsPath, 104 | 'scopes': instance.scopes, 105 | 'addTypenameExcludedPaths': instance.addTypenameExcludedPaths, 106 | 'generatedFileHeader': instance.generatedFileHeader, 107 | 'namingSeparator': instance.namingSeparator, 108 | 'extraKeywords': instance.extraKeywords, 109 | 'outputDirectory': instance.outputDirectory, 110 | 'disableContextReplacement': instance.disableContextReplacement, 111 | 'disableCopyWithGeneration': instance.disableCopyWithGeneration, 112 | 'allowMissingNullableKeysInFromJson': 113 | instance.allowMissingNullableKeysInFromJson, 114 | 'setOperationName': instance.setOperationName, 115 | 'EXPERIMENTAL_enable_input_builders': instance.enableInputBuilders, 116 | }; 117 | 118 | const _$GraphQLCodegenConfigClientEnumMap = { 119 | GraphQLCodegenConfigClient.graphql: 'graphql', 120 | GraphQLCodegenConfigClient.graphqlFlutter: 'graphql_flutter', 121 | }; 122 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/context/name.dart: -------------------------------------------------------------------------------- 1 | import 'package:built_collection/built_collection.dart'; 2 | import 'package:gql/ast.dart'; 3 | 4 | class Name { 5 | final BuiltList segments; 6 | final BaseNameSegment baseNameSegment; 7 | 8 | Name(this.segments, this.baseNameSegment); 9 | 10 | factory Name.fromSegment(BaseNameSegment segment) => Name( 11 | BuiltList.of([segment]), 12 | segment, 13 | ); 14 | 15 | String get _key => segments.map((e) => e._key).join(r"$"); 16 | 17 | Name withSegment(NameSegment segment) => Name( 18 | (segments.toBuilder()..add(segment)).build(), 19 | baseNameSegment, 20 | ); 21 | 22 | bool get isRoot => segments.length == 1; 23 | 24 | bool operator ==(Object other) => other is Name && other._key == _key; 25 | 26 | @override 27 | int get hashCode => _key.hashCode; 28 | } 29 | 30 | abstract class NameSegment { 31 | final NameNode name; 32 | 33 | NameSegment(this.name); 34 | 35 | String get _key; 36 | 37 | bool operator ==(Object other) => other is NameSegment && other._key == _key; 38 | 39 | @override 40 | int get hashCode => _key.hashCode; 41 | } 42 | 43 | abstract class BaseNameSegment 44 | extends NameSegment { 45 | final TDefinitionNode node; 46 | BaseNameSegment(NameNode name, this.node) : super(name); 47 | } 48 | 49 | class EnumNameSegment extends BaseNameSegment { 50 | EnumNameSegment(EnumTypeDefinitionNode tpe) : super(tpe.name, tpe); 51 | 52 | @override 53 | String get _key => "E${name.value}"; 54 | } 55 | 56 | class InputNameSegment extends BaseNameSegment { 57 | InputNameSegment(InputObjectTypeDefinitionNode tpe) : super(tpe.name, tpe); 58 | 59 | @override 60 | String get _key => "I${name.value}"; 61 | } 62 | 63 | class FieldNameSegment extends NameSegment { 64 | FieldNameSegment(FieldNode name) : super(name.alias ?? name.name); 65 | 66 | @override 67 | String get _key => "f${name.value}"; 68 | } 69 | 70 | class TypeNameSegment extends NameSegment { 71 | TypeNameSegment(NameNode typeCondition) : super(typeCondition); 72 | 73 | @override 74 | String get _key => "t${name.value}"; 75 | } 76 | 77 | class OperationNameSegment extends BaseNameSegment { 78 | OperationNameSegment(OperationDefinitionNode name) : super(name.name!, name); 79 | 80 | @override 81 | String get _key { 82 | switch (node.type) { 83 | case OperationType.mutation: 84 | return "M${name.value}"; 85 | case OperationType.query: 86 | return "Q${name.value}"; 87 | case OperationType.subscription: 88 | return "S${name.value}"; 89 | } 90 | } 91 | } 92 | 93 | class FragmentNameSegment extends BaseNameSegment { 94 | FragmentNameSegment(FragmentDefinitionNode node) : super(node.name, node); 95 | 96 | @override 97 | String get _key => "F${name.value}"; 98 | } 99 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/errors.dart: -------------------------------------------------------------------------------- 1 | /// An error that occurs during parsing of the GraphQL Document. 2 | /// This may happen if type definitions or fields are missing. 3 | class InvalidGraphQLDocumentError extends Error { 4 | /// The message 5 | final String message; 6 | 7 | InvalidGraphQLDocumentError(this.message); 8 | 9 | @override 10 | String toString() => "Invalid GraphQL: $message"; 11 | } 12 | 13 | /// An error that occurs during printing 14 | class PrinterError extends Error { 15 | /// The message 16 | final String message; 17 | 18 | PrinterError(this.message); 19 | 20 | @override 21 | String toString() => "Printer error: $message"; 22 | } 23 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/base/constants.dart: -------------------------------------------------------------------------------- 1 | const kUnknowkEnumValue = "\$unknown"; 2 | const kImplInstanceFieldName = r'$impl'; 3 | const kDataVariableName = r'_$data'; 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/base/deprecation.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | 3 | const kDefaultDepreactionReason = 'No longer supported'; 4 | 5 | String? extractDeprecatedReason(List directives) { 6 | final directive = directives.whereType().firstWhere( 7 | (e) => e?.name.value == 'deprecated', 8 | orElse: () => null, 9 | ); 10 | if (directive == null) { 11 | return null; 12 | } 13 | final reason = directive.arguments.whereType().firstWhere( 14 | (e) => e?.name.value == 'reason', 15 | orElse: () => null, 16 | ); 17 | if (reason == null) { 18 | return kDefaultDepreactionReason; 19 | } 20 | final value = reason.value; 21 | if (value is StringValueNode) { 22 | return value.value; 23 | } 24 | return kDefaultDepreactionReason; 25 | } 26 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/base/enum.dart: -------------------------------------------------------------------------------- 1 | import 'package:built_collection/built_collection.dart'; 2 | import 'package:code_builder/code_builder.dart'; 3 | import 'package:gql/schema.dart' as gql; 4 | import 'package:graphql_codegen/graphql_codegen.dart'; 5 | import 'package:graphql_codegen/src/context/context.dart'; 6 | import 'package:graphql_codegen/src/printer/base/constants.dart'; 7 | import 'package:graphql_codegen/src/printer/base/deprecation.dart'; 8 | import 'package:graphql_codegen/src/printer/context.dart'; 9 | 10 | class _EnumMappedValue { 11 | final String graphQLName; 12 | final String dartName; 13 | final String? deprecatedReason; 14 | 15 | _EnumMappedValue({ 16 | required this.graphQLName, 17 | required this.dartName, 18 | required this.deprecatedReason, 19 | }); 20 | } 21 | 22 | List printEnum(PrintContext context) { 23 | final config = 24 | context.context.config.enums[context.context.currentTypeName.value]; 25 | if (config?.type != null) { 26 | return []; 27 | } 28 | 29 | final fallbackEnumValue = config?.fallbackEnumValue; 30 | 31 | if (fallbackEnumValue != null && 32 | context.context.values.whereType().firstWhere( 33 | (element) => element?.name == fallbackEnumValue, 34 | orElse: () => null) != 35 | null) { 36 | throw PrinterError( 37 | "Enum fallback value for enum \"${context.context.currentType.name.value}\" is not a valid value.", 38 | ); 39 | } 40 | 41 | final values = [ 42 | for (final v in context.context.values) 43 | _EnumMappedValue( 44 | graphQLName: v.name.value, 45 | dartName: context.namePrinter.printEnumValueName(v.name), 46 | deprecatedReason: extractDeprecatedReason(v.directives), 47 | ), 48 | if (fallbackEnumValue == null) 49 | _EnumMappedValue( 50 | graphQLName: kUnknowkEnumValue, 51 | dartName: kUnknowkEnumValue, 52 | deprecatedReason: null), 53 | ]; 54 | final className = context.namePrinter.printClassName(context.path); 55 | final specs = [ 56 | Enum( 57 | (b) => b 58 | ..name = className 59 | ..constructors = ListBuilder( 60 | [ 61 | Constructor( 62 | (b) => b 63 | ..name = 'fromJson' 64 | ..factory = true 65 | ..requiredParameters = ListBuilder( 66 | [ 67 | Parameter( 68 | (b) => b 69 | ..name = 'value' 70 | ..type = refer('String'), 71 | ) 72 | ], 73 | ) 74 | ..body = refer( 75 | context.namePrinter.printFromJsonConverterFunctionName( 76 | context.path, 77 | ), 78 | ).call([refer('value')]).code 79 | ..lambda = true, 80 | ), 81 | ], 82 | ) 83 | ..methods = ListBuilder( 84 | [ 85 | Method( 86 | (b) => b 87 | ..name = 'toJson' 88 | ..returns = refer('String') 89 | ..body = refer( 90 | context.namePrinter.printToJsonConverterFunctionName( 91 | context.path, 92 | ), 93 | ).call([refer('this')]).code 94 | ..lambda = true, 95 | ), 96 | ], 97 | ) 98 | ..values = ListBuilder( 99 | values.map( 100 | (e) { 101 | final reason = e.deprecatedReason; 102 | return EnumValue( 103 | (b) => b 104 | ..name = e.dartName 105 | ..annotations = ListBuilder( 106 | [ 107 | if (reason != null) 108 | refer( 109 | 'Deprecated(\'${reason.replaceAll("'", r"\'")}\')', 110 | ), 111 | ], 112 | ), 113 | ); 114 | }, 115 | ).toList(growable: false), 116 | ), 117 | ), 118 | Method( 119 | (b) => b 120 | ..name = 121 | context.namePrinter.printToJsonConverterFunctionName(context.path) 122 | ..returns = refer('String') 123 | ..requiredParameters = ListBuilder([ 124 | Parameter( 125 | (b) => b 126 | ..name = 'e' 127 | ..type = refer(className), 128 | ) 129 | ]) 130 | ..body = Block.of([ 131 | Code('switch(e) {'), 132 | for (final value in values) 133 | Code( 134 | 'case ${className}.${value.dartName}: return r\'${value.graphQLName}\';'), 135 | Code('}') 136 | ]), 137 | ), 138 | Method( 139 | (b) => b 140 | ..name = 141 | context.namePrinter.printFromJsonConverterFunctionName(context.path) 142 | ..returns = refer(className) 143 | ..requiredParameters = ListBuilder([ 144 | Parameter( 145 | (b) => b 146 | ..name = 'value' 147 | ..type = refer('String'), 148 | ) 149 | ]) 150 | ..body = Block.of([ 151 | Code('switch(value) {'), 152 | for (final value in values) 153 | if (value.graphQLName != kUnknowkEnumValue) 154 | Code( 155 | 'case r\'${value.graphQLName}\': return ${className}.${value.dartName};'), 156 | Code( 157 | 'default: return ${className}.${fallbackEnumValue ?? kUnknowkEnumValue};'), 158 | Code('}') 159 | ]), 160 | ) 161 | ]; 162 | return specs; 163 | } 164 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/base/fragment.dart: -------------------------------------------------------------------------------- 1 | import 'package:code_builder/code_builder.dart'; 2 | import 'package:gql/ast.dart'; 3 | import 'package:graphql_codegen/src/config/config.dart'; 4 | import 'package:graphql_codegen/src/context/context.dart'; 5 | import 'package:graphql_codegen/src/printer/base/document.dart'; 6 | import 'package:graphql_codegen/src/printer/base/input.dart'; 7 | import 'package:graphql_codegen/src/printer/clients/graphql.dart'; 8 | import 'package:graphql_codegen/src/printer/context.dart'; 9 | import 'package:gql_code_builder/src/ast.dart' as gql_builder; 10 | 11 | List printFragmentSpecs(PrintContext elementContext) { 12 | final fragmentNode = elementContext.context.fragment; 13 | final context = elementContext.context; 14 | final clients = context.config.clients; 15 | return [ 16 | if (context.hasVariables) ...printVariableClasses(elementContext), 17 | printContext(elementContext), 18 | ...printContextExtension(elementContext), 19 | if (fragmentNode != null) ...[ 20 | _printFragmentDefinition( 21 | elementContext, 22 | fragmentNode, 23 | ), 24 | printDocument( 25 | elementContext, 26 | fragmentNode, 27 | refer(elementContext.namePrinter 28 | .printFragmentDefinitionNodeName(elementContext.path)) 29 | .code, 30 | ), 31 | ], 32 | if (clients.contains(GraphQLCodegenConfigClient.graphql) || 33 | clients.contains(GraphQLCodegenConfigClient.graphqlFlutter)) 34 | ...printGraphQLClientFragmentSpecs(elementContext) 35 | ]; 36 | } 37 | 38 | Spec _printFragmentDefinition( 39 | PrintContext context, 40 | FragmentDefinitionNode node, 41 | ) { 42 | context.addPackage('package:gql/ast.dart'); 43 | return Block( 44 | (b) => b.statements.addAll([ 45 | Code( 46 | "const ${context.namePrinter.printFragmentDefinitionNodeName(context.context.path)} = ", 47 | ), 48 | gql_builder.fromNode(node).code, 49 | Code(";") 50 | ]), 51 | ); 52 | } 53 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/base/operation.dart: -------------------------------------------------------------------------------- 1 | import 'package:code_builder/code_builder.dart'; 2 | import 'package:graphql_codegen/src/context/context.dart'; 3 | import 'package:graphql_codegen/src/printer/base/document.dart'; 4 | import 'package:graphql_codegen/src/printer/base/input.dart'; 5 | import 'package:graphql_codegen/src/printer/clients/graphql.dart'; 6 | import 'package:graphql_codegen/src/printer/clients/graphql_flutter.dart'; 7 | import 'package:graphql_codegen/src/printer/context.dart'; 8 | import 'package:graphql_codegen/src/config/config.dart'; 9 | 10 | List printOperationSpecs(PrintContext elementContext) { 11 | final context = elementContext.context; 12 | final operation = context.operation; 13 | final clients = context.config.clients; 14 | return [ 15 | if (context.hasVariables) ...printVariableClasses(elementContext), 16 | printContext(elementContext), 17 | ...printContextExtension(elementContext), 18 | if (operation != null) 19 | printDocument( 20 | elementContext, 21 | operation, 22 | ), 23 | if (clients.contains(GraphQLCodegenConfigClient.graphql) || 24 | clients.contains(GraphQLCodegenConfigClient.graphqlFlutter)) 25 | ...printGraphQLClientSpecs(elementContext), 26 | if (clients.contains(GraphQLCodegenConfigClient.graphqlFlutter)) 27 | ...printGraphQLFlutterSpecs(elementContext), 28 | ]; 29 | } 30 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/base/schema.dart: -------------------------------------------------------------------------------- 1 | import 'package:built_collection/built_collection.dart'; 2 | import 'package:code_builder/code_builder.dart'; 3 | import 'package:graphql_codegen/src/context/context.dart'; 4 | import 'package:graphql_codegen/src/printer/context.dart'; 5 | 6 | Spec printPossibleTypesMap(PrintContext context) { 7 | return Block( 8 | (b) => b.statements.addAll([ 9 | Code( 10 | "const ${context.namePrinter.printPossibleTypesMapName()} = ", 11 | ), 12 | literalMap( 13 | context.context.possibleTypesMap, 14 | refer('String'), 15 | TypeReference( 16 | (b) => b 17 | ..symbol = 'Set' 18 | ..types = ListBuilder([refer('String')]), 19 | ), 20 | ).code, 21 | Code(";") 22 | ]), 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/base/undefined.dart: -------------------------------------------------------------------------------- 1 | import 'package:code_builder/code_builder.dart'; 2 | 3 | const kUndefinedFieldName = '_undefined'; 4 | 5 | Field printUndefinedField() { 6 | return Field( 7 | (b) => b 8 | ..name = kUndefinedFieldName 9 | ..static = true 10 | ..modifier = FieldModifier.constant 11 | ..assignment = literalMap( 12 | {}, 13 | refer('dynamic'), 14 | refer('dynamic'), 15 | ).code, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/base/utils.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | 3 | TypeNode typeNodeAsNullable(TypeNode node) { 4 | if (!node.isNonNull) { 5 | return node; 6 | } 7 | if (node is ListTypeNode) { 8 | return ListTypeNode( 9 | type: node.type, 10 | isNonNull: false, 11 | ); 12 | } 13 | if (node is NamedTypeNode) { 14 | return NamedTypeNode( 15 | name: node.name, 16 | isNonNull: false, 17 | ); 18 | } 19 | return node; 20 | } 21 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/clients/utils.dart: -------------------------------------------------------------------------------- 1 | import 'package:built_collection/built_collection.dart'; 2 | import 'package:code_builder/code_builder.dart'; 3 | 4 | Reference generic(String symbol, Reference type, {bool isNullable = false}) => 5 | TypeReference((b) => b 6 | ..symbol = symbol 7 | ..isNullable = isNullable 8 | ..types = ListBuilder([type])); 9 | 10 | final dynamicMap = TypeReference( 11 | (b) => b 12 | ..symbol = 'Map' 13 | ..types = ListBuilder([refer('String'), refer('dynamic')]), 14 | ); 15 | 16 | final nullableDynamicMap = TypeReference( 17 | (b) => b 18 | ..symbol = 'Map' 19 | ..isNullable = true 20 | ..types = ListBuilder([refer('String'), refer('dynamic')]), 21 | ); 22 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/context.dart: -------------------------------------------------------------------------------- 1 | import 'package:code_builder/code_builder.dart'; 2 | import 'package:graphql_codegen/src/context/context.dart'; 3 | import 'package:graphql_codegen/src/context/name.dart'; 4 | import 'package:graphql_codegen/src/context/schema.dart'; 5 | import 'package:graphql_codegen/src/printer/utils.dart'; 6 | import 'package:path/path.dart' as path; 7 | 8 | final p = path.Context(style: path.Style.posix); 9 | 10 | class _Value { 11 | TValue value; 12 | 13 | _Value(this.value); 14 | } 15 | 16 | class _Package { 17 | final String import; 18 | final String? alias; 19 | 20 | _Package(this.import, this.alias); 21 | 22 | operator ==(Object other) => 23 | other is _Package && other.alias == alias && other.import == import; 24 | 25 | @override 26 | int get hashCode => import.hashCode & alias.hashCode; 27 | } 28 | 29 | class PrintContext { 30 | final TContext context; 31 | final _Value _jsonSerializable; 32 | final Set _dependencies; 33 | final Set<_Package> _packages; 34 | final Set _badScalars; 35 | final Map _converters; 36 | final NamePrinter namePrinter; 37 | 38 | Schema get schema => context.schema; 39 | 40 | Iterable get converters => _converters.values; 41 | 42 | Iterable get directives { 43 | final currentFile = context.filePath; 44 | final currentPath = p.dirname(currentFile); 45 | final imports = [ 46 | ..._packages.map((e) => Directive.import(e.import, as: e.alias)), 47 | ..._dependencies 48 | .where((element) => element != currentFile) 49 | .map((e) => Directive.import(p.relative(e, from: currentPath))), 50 | ]; 51 | imports.sort((e1, e2) => e1.url.compareTo(e2.url)); 52 | return [ 53 | ...imports, 54 | ]; 55 | } 56 | 57 | factory PrintContext(TContext context) => PrintContext._( 58 | context, 59 | _Value(false), 60 | {}, 61 | {}, 62 | {}, 63 | {}, 64 | ); 65 | 66 | PrintContext._( 67 | this.context, 68 | _Value jsonSerializable, 69 | Set dependencies, 70 | Set<_Package> packages, 71 | Set badScalars, 72 | Map converters, 73 | ) : this._jsonSerializable = jsonSerializable, 74 | this._dependencies = dependencies, 75 | this._packages = packages, 76 | this._badScalars = badScalars, 77 | this._converters = converters, 78 | this.namePrinter = NamePrinter(context.config); 79 | 80 | PrintContext withContext( 81 | TNewContext context, 82 | ) => 83 | PrintContext._( 84 | context, 85 | _jsonSerializable, 86 | _dependencies, 87 | _packages, 88 | _badScalars, 89 | _converters, 90 | ); 91 | 92 | Name get path => context.path; 93 | 94 | void markAsJsonSerializable() { 95 | _jsonSerializable.value = true; 96 | } 97 | 98 | void addDependency(Name name) { 99 | final lookupPath = 100 | context.schema.lookupPathFromDefinitionNode(name.baseNameSegment.node); 101 | if (lookupPath == null) return; 102 | _dependencies.add(lookupPath); 103 | } 104 | 105 | void maybeAddDependency(Name? name) { 106 | if (name == null) { 107 | return; 108 | } 109 | addDependency(name); 110 | } 111 | 112 | void addDependencies(Iterable names) { 113 | for (final name in names) { 114 | addDependency(name); 115 | } 116 | } 117 | 118 | void addPackage(String import, [String? alias]) { 119 | _packages.add(_Package(import, alias)); 120 | } 121 | 122 | void addConverters(Map converters) { 123 | _converters.addAll(converters); 124 | } 125 | 126 | void markScalarAsBad(String name) { 127 | _badScalars.add(name); 128 | } 129 | 130 | void printWarnings() { 131 | for (final scalar in _badScalars) { 132 | print("Missing scalar ${scalar}. Defaulting to String"); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/keywords.dart: -------------------------------------------------------------------------------- 1 | const staticKeywords = { 2 | "call", 3 | "abstract", 4 | "else", 5 | "import", 6 | "super", 7 | "as", 8 | "enum", 9 | "in", 10 | "switch", 11 | "assert", 12 | "export", 13 | "interface", 14 | "sync", 15 | "async", 16 | "extends", 17 | "is", 18 | "this", 19 | "await", 20 | "extension", 21 | "library", 22 | "throw", 23 | "break", 24 | "external", 25 | "mixin", 26 | "true", 27 | "case", 28 | "factory", 29 | "new", 30 | "try", 31 | "catch", 32 | "false", 33 | "null", 34 | "typedef", 35 | "class", 36 | "final", 37 | "on", 38 | "var", 39 | "const", 40 | "finally", 41 | "operator", 42 | "void", 43 | "continue", 44 | "for", 45 | "part", 46 | "while", 47 | "covariant", 48 | "Function", 49 | "rethrow", 50 | "with", 51 | "default", 52 | "get", 53 | "return", 54 | "yield", 55 | "deferred", 56 | "hide", 57 | "set", 58 | "do", 59 | "if", 60 | "show", 61 | "dynamic", 62 | "implements", 63 | "static", 64 | // Built-in types 65 | "int", 66 | "double", 67 | "bool", 68 | "List", 69 | "Set", 70 | "Map", 71 | "Runes", 72 | "Symbol", 73 | "String", 74 | "Null", 75 | "num" 76 | }; 77 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/printer/printer.dart: -------------------------------------------------------------------------------- 1 | import 'package:built_collection/built_collection.dart'; 2 | import 'package:code_builder/code_builder.dart'; 3 | import 'package:graphql_codegen/src/printer/base/fragment.dart'; 4 | import 'package:graphql_codegen/src/printer/base/operation.dart'; 5 | import 'package:graphql_codegen/src/printer/base/enum.dart'; 6 | import 'package:graphql_codegen/src/printer/base/input.dart'; 7 | import 'package:graphql_codegen/src/printer/context.dart'; 8 | import 'package:graphql_codegen/src/context/context.dart'; 9 | 10 | import 'base/schema.dart'; 11 | 12 | bool _shouldPrintContext(Context c) { 13 | return (c.replacementContext == null) || 14 | (c.extendsContext != null && 15 | c.extendsContext?.replacementContext == null); 16 | } 17 | 18 | Library printRootContext( 19 | PrintContext> c) { 20 | final context = c.context; 21 | final body = ListBuilder([ 22 | ...context.contextInputs.expand( 23 | (context) => printInputClasses(c.withContext(context)), 24 | ), 25 | ...context.contextEnums 26 | .expand((context) => printEnum(c.withContext(context))), 27 | ...context.contextFragments 28 | .where(_shouldPrintContext) 29 | .expand((context) => printFragmentSpecs(c.withContext(context))), 30 | ...context.contextOperations 31 | .where(_shouldPrintContext) 32 | .expand((context) => printOperationSpecs(c.withContext(context))), 33 | if (context.isMainContext) printPossibleTypesMap(c), 34 | ...c.converters, 35 | ]); 36 | 37 | final library = Library( 38 | (b) => b 39 | ..directives = ListBuilder(c.directives) 40 | ..body = body, 41 | ); 42 | c.printWarnings(); 43 | return library; 44 | } 45 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/transform/add_typename_transforming_visitor.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | import 'package:graphql_codegen/src/config/config.dart'; 3 | import 'package:graphql_codegen/src/transform/transforming_visitor.dart'; 4 | 5 | const typenameFieldName = '__typename'; 6 | 7 | const _MATCH_WILDCARD = '*'; 8 | const _MATCH_DOUBLE_WILDCARD = '**'; 9 | 10 | class AddTypenameTransformationVisitor extends RecursiveTransformingVisitor { 11 | final Iterable> _excludedPatterns; 12 | 13 | AddTypenameTransformationVisitor({ 14 | required GraphQLCodegenConfig config, 15 | }) : _excludedPatterns = 16 | config.addTypenameExcludedPaths.map((e) => e.split(".")).toList(); 17 | 18 | AddTypenameTransformationVisitor._internal(this._excludedPatterns); 19 | 20 | @override 21 | OperationDefinitionNode visitOperationDefinitionNode( 22 | OperationDefinitionNode node, 23 | ) { 24 | final Set matches = Set.of([node.name?.value].whereType()); 25 | switch (node.type) { 26 | case OperationType.mutation: 27 | matches.add('mutation'); 28 | break; 29 | case OperationType.subscription: 30 | matches.add('subscription'); 31 | break; 32 | case OperationType.query: 33 | matches.add('query'); 34 | } 35 | final visitor = _matchAndSkip(matches); 36 | 37 | return OperationDefinitionNode( 38 | name: visitor.visitOne(node.name), 39 | directives: visitor.visitAll(node.directives), 40 | type: node.type, 41 | selectionSet: visitor.visitOne(node.selectionSet), 42 | variableDefinitions: visitor.visitAll(node.variableDefinitions), 43 | ); 44 | } 45 | 46 | @override 47 | FragmentDefinitionNode visitFragmentDefinitionNode( 48 | FragmentDefinitionNode node, 49 | ) { 50 | final visitor = _matchAndSkip(Set.of([ 51 | node.name.value, 52 | 'fragment', 53 | ])); 54 | return FragmentDefinitionNode( 55 | name: visitor.visitOne(node.name), 56 | directives: visitor.visitAll(node.directives), 57 | selectionSet: visitor.visitOne(node.selectionSet), 58 | typeCondition: visitor.visitOne(node.typeCondition), 59 | ); 60 | } 61 | 62 | @override 63 | FieldNode visitFieldNode( 64 | FieldNode node, 65 | ) { 66 | final visitor = 67 | _matchAndSkip(Set.of([node.alias?.value ?? node.name.value])); 68 | return FieldNode( 69 | name: visitor.visitOne(node.name), 70 | directives: visitor.visitAll(node.directives), 71 | alias: visitor.visitOne(node.alias), 72 | arguments: visitor.visitAll(node.arguments), 73 | selectionSet: visitor.visitOne(node.selectionSet), 74 | ); 75 | } 76 | 77 | AddTypenameTransformationVisitor _matchAndSkip(Set matches) { 78 | final processedPatterns = _excludedPatterns 79 | .expand( 80 | (element) => 81 | element.isNotEmpty && element.first == _MATCH_DOUBLE_WILDCARD 82 | ? [element.skip(1), element] 83 | : [element], 84 | ) 85 | .where( 86 | (element) => 87 | element.isNotEmpty && 88 | (element.first == _MATCH_WILDCARD || 89 | element.first == _MATCH_DOUBLE_WILDCARD || 90 | matches.contains(element.first)), 91 | ) 92 | .map((element) => 93 | element.isNotEmpty && element.first == _MATCH_DOUBLE_WILDCARD 94 | ? element 95 | : element.skip(1)); 96 | return AddTypenameTransformationVisitor._internal(processedPatterns); 97 | } 98 | 99 | bool get _isExcluded => _excludedPatterns.any((element) => element.isEmpty); 100 | 101 | @override 102 | SelectionSetNode visitSelectionSetNode(SelectionSetNode node) { 103 | final hasTypename = node.selections.whereType().any((element) => 104 | element.alias?.value == typenameFieldName || 105 | (element.alias == null && element.name.value == typenameFieldName)); 106 | 107 | var selections = List.of(node.selections); 108 | 109 | if (!hasTypename && !_isExcluded) { 110 | final newField = FieldNode(name: NameNode(value: typenameFieldName)); 111 | selections.add(newField); 112 | } 113 | 114 | return SelectionSetNode( 115 | selections: visitAll(selections), 116 | ); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/transform/fix_unnamed_operations_visitor.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | import 'package:graphql_codegen/src/transform/transforming_visitor.dart'; 3 | 4 | class FixUnnamedOperationsVisitor extends RecursiveTransformingVisitor { 5 | @override 6 | DocumentNode visitDocumentNode(DocumentNode node) { 7 | final filteredDefinitions = node.definitions 8 | .where( 9 | (element) => 10 | element is! OperationDefinitionNode || element.name != null, 11 | ) 12 | .toList(); 13 | return DocumentNode( 14 | definitions: filteredDefinitions, 15 | ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/graphql_codegen/lib/src/transform/transform.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart' as ast; 2 | import 'package:gql/ast.dart'; 3 | import 'package:graphql_codegen/src/config/config.dart'; 4 | import 'package:graphql_codegen/src/transform/add_typename_transforming_visitor.dart'; 5 | 6 | import 'fix_unnamed_operations_visitor.dart'; 7 | 8 | ast.DocumentNode transform( 9 | GraphQLCodegenConfig config, 10 | ast.DocumentNode node, 11 | ) => 12 | [ 13 | if (config.addTypename) AddTypenameTransformationVisitor(config: config), 14 | FixUnnamedOperationsVisitor() 15 | ].fold( 16 | node, 17 | (previousValue, element) => previousValue.accept(element), 18 | ) as ast.DocumentNode; 19 | -------------------------------------------------------------------------------- /packages/graphql_codegen/melos_graphql_codegen.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /packages/graphql_codegen/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: graphql_codegen 2 | description: | 3 | Simple, opinionated, codegen library for GraphQL. It allows you to 4 | generate serializers and client helpers to easily call and parse your data. 5 | 6 | version: 1.2.3 7 | homepage: https://github.com/heftapp/graphql_codegen/tree/main/packages/graphql_codegen 8 | repository: https://github.com/heftapp/graphql_codegen/tree/main/packages/graphql_codegen 9 | 10 | environment: 11 | sdk: ">=3.6.0 <4.0.0" 12 | 13 | dependencies: 14 | gql: ^1.0.0 15 | build: ^2.0.1 16 | glob: ^2.0.1 17 | code_builder: ^4.2.0 18 | dart_style: ^3.0.0 19 | built_collection: ^5.0.0 20 | path: ^1.8.0 21 | gql_code_builder: ^0.13.1 22 | recase: ^4.0.0 23 | json_annotation: ^4.9.0 24 | dev_dependencies: 25 | test: ^1.17.4 26 | build_test: ^2.1.0 27 | build_runner: ^2.0.3 28 | json_serializable: ^6.1.5 29 | graphql: ^5.2.0-beta.3 30 | lints: ^5.1.1 31 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/add_typenames/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": true 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/add_typenames/schema.graphql: -------------------------------------------------------------------------------- 1 | interface Document { 2 | title: String 3 | numPages: Int 4 | 5 | } 6 | 7 | type Contract implements Document { 8 | title: String 9 | numPages: Int 10 | } 11 | 12 | type Report implements Document { 13 | title: String 14 | numPages: Int 15 | } 16 | 17 | type Query { 18 | documents: [Document] 19 | } 20 | 21 | query Q { 22 | docsWithTypename: documents { 23 | __typename 24 | } 25 | docsWihtoutTypename: documents { 26 | title 27 | } 28 | docsWithAliasedTypename: documents { 29 | __typename: title 30 | } 31 | docsWithFragment: documents { 32 | ... on Contract { 33 | title 34 | } 35 | ...FReport 36 | } 37 | } 38 | 39 | 40 | fragment FReport on Report { 41 | title 42 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/condition_example/fragments.graphql: -------------------------------------------------------------------------------- 1 | 2 | fragment Condition on Condition { 3 | name 4 | } 5 | 6 | fragment AndCondition on AndCondition { 7 | left { 8 | ...NonCompositeCondition 9 | } 10 | right { 11 | ...NonCompositeCondition 12 | } 13 | ...Condition 14 | } 15 | 16 | fragment CompositeCondition on Condition { 17 | ...TimeCondition 18 | ...AndCondition 19 | ...Condition 20 | } 21 | 22 | fragment NonCompositeCondition on Condition { 23 | ...Condition 24 | ...TimeCondition 25 | } 26 | 27 | fragment TimeCondition on TimeCondition { 28 | ...Condition 29 | before 30 | } 31 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/condition_example/query.graphql: -------------------------------------------------------------------------------- 1 | 2 | query FetchShouldRender { 3 | shouldRender { 4 | ...CompositeCondition 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/condition_example/query.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'fragments.graphql.dart'; 2 | import 'package:gql/ast.dart'; 3 | 4 | class Query$FetchShouldRender { 5 | Query$FetchShouldRender({ 6 | required this.shouldRender, 7 | this.$__typename = 'Query', 8 | }); 9 | 10 | factory Query$FetchShouldRender.fromJson(Map json) { 11 | final l$shouldRender = json['shouldRender']; 12 | final l$$__typename = json['__typename']; 13 | return Query$FetchShouldRender( 14 | shouldRender: Fragment$CompositeCondition.fromJson( 15 | (l$shouldRender as Map)), 16 | $__typename: (l$$__typename as String), 17 | ); 18 | } 19 | 20 | final Fragment$CompositeCondition shouldRender; 21 | 22 | final String $__typename; 23 | 24 | Map toJson() { 25 | final _resultData = {}; 26 | final l$shouldRender = shouldRender; 27 | _resultData['shouldRender'] = l$shouldRender.toJson(); 28 | final l$$__typename = $__typename; 29 | _resultData['__typename'] = l$$__typename; 30 | return _resultData; 31 | } 32 | 33 | @override 34 | int get hashCode { 35 | final l$shouldRender = shouldRender; 36 | final l$$__typename = $__typename; 37 | return Object.hashAll([ 38 | l$shouldRender, 39 | l$$__typename, 40 | ]); 41 | } 42 | 43 | @override 44 | bool operator ==(Object other) { 45 | if (identical(this, other)) { 46 | return true; 47 | } 48 | if (other is! Query$FetchShouldRender || runtimeType != other.runtimeType) { 49 | return false; 50 | } 51 | final l$shouldRender = shouldRender; 52 | final lOther$shouldRender = other.shouldRender; 53 | if (l$shouldRender != lOther$shouldRender) { 54 | return false; 55 | } 56 | final l$$__typename = $__typename; 57 | final lOther$$__typename = other.$__typename; 58 | if (l$$__typename != lOther$$__typename) { 59 | return false; 60 | } 61 | return true; 62 | } 63 | } 64 | 65 | extension UtilityExtension$Query$FetchShouldRender on Query$FetchShouldRender { 66 | CopyWith$Query$FetchShouldRender get copyWith => 67 | CopyWith$Query$FetchShouldRender( 68 | this, 69 | (i) => i, 70 | ); 71 | } 72 | 73 | abstract class CopyWith$Query$FetchShouldRender { 74 | factory CopyWith$Query$FetchShouldRender( 75 | Query$FetchShouldRender instance, 76 | TRes Function(Query$FetchShouldRender) then, 77 | ) = _CopyWithImpl$Query$FetchShouldRender; 78 | 79 | factory CopyWith$Query$FetchShouldRender.stub(TRes res) = 80 | _CopyWithStubImpl$Query$FetchShouldRender; 81 | 82 | TRes call({ 83 | Fragment$CompositeCondition? shouldRender, 84 | String? $__typename, 85 | }); 86 | CopyWith$Fragment$CompositeCondition get shouldRender; 87 | } 88 | 89 | class _CopyWithImpl$Query$FetchShouldRender 90 | implements CopyWith$Query$FetchShouldRender { 91 | _CopyWithImpl$Query$FetchShouldRender( 92 | this._instance, 93 | this._then, 94 | ); 95 | 96 | final Query$FetchShouldRender _instance; 97 | 98 | final TRes Function(Query$FetchShouldRender) _then; 99 | 100 | static const _undefined = {}; 101 | 102 | TRes call({ 103 | Object? shouldRender = _undefined, 104 | Object? $__typename = _undefined, 105 | }) => 106 | _then(Query$FetchShouldRender( 107 | shouldRender: shouldRender == _undefined || shouldRender == null 108 | ? _instance.shouldRender 109 | : (shouldRender as Fragment$CompositeCondition), 110 | $__typename: $__typename == _undefined || $__typename == null 111 | ? _instance.$__typename 112 | : ($__typename as String), 113 | )); 114 | 115 | CopyWith$Fragment$CompositeCondition get shouldRender { 116 | final local$shouldRender = _instance.shouldRender; 117 | return CopyWith$Fragment$CompositeCondition( 118 | local$shouldRender, (e) => call(shouldRender: e)); 119 | } 120 | } 121 | 122 | class _CopyWithStubImpl$Query$FetchShouldRender 123 | implements CopyWith$Query$FetchShouldRender { 124 | _CopyWithStubImpl$Query$FetchShouldRender(this._res); 125 | 126 | TRes _res; 127 | 128 | call({ 129 | Fragment$CompositeCondition? shouldRender, 130 | String? $__typename, 131 | }) => 132 | _res; 133 | 134 | CopyWith$Fragment$CompositeCondition get shouldRender => 135 | CopyWith$Fragment$CompositeCondition.stub(_res); 136 | } 137 | 138 | const documentNodeQueryFetchShouldRender = DocumentNode(definitions: [ 139 | OperationDefinitionNode( 140 | type: OperationType.query, 141 | name: NameNode(value: 'FetchShouldRender'), 142 | variableDefinitions: [], 143 | directives: [], 144 | selectionSet: SelectionSetNode(selections: [ 145 | FieldNode( 146 | name: NameNode(value: 'shouldRender'), 147 | alias: null, 148 | arguments: [], 149 | directives: [], 150 | selectionSet: SelectionSetNode(selections: [ 151 | FragmentSpreadNode( 152 | name: NameNode(value: 'CompositeCondition'), 153 | directives: [], 154 | ), 155 | FieldNode( 156 | name: NameNode(value: '__typename'), 157 | alias: null, 158 | arguments: [], 159 | directives: [], 160 | selectionSet: null, 161 | ), 162 | ]), 163 | ), 164 | FieldNode( 165 | name: NameNode(value: '__typename'), 166 | alias: null, 167 | arguments: [], 168 | directives: [], 169 | selectionSet: null, 170 | ), 171 | ]), 172 | ), 173 | fragmentDefinitionCompositeCondition, 174 | fragmentDefinitionTimeCondition, 175 | fragmentDefinitionAndCondition, 176 | fragmentDefinitionCondition, 177 | fragmentDefinitionNonCompositeCondition, 178 | ]); 179 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/condition_example/schema.graphql: -------------------------------------------------------------------------------- 1 | interface Condition { 2 | name: String! 3 | } 4 | 5 | type AndCondition implements Condition { 6 | name: String! 7 | left: Condition! 8 | right: Condition! 9 | } 10 | 11 | type TimeCondition implements Condition { 12 | name: String! 13 | before: String! 14 | } 15 | 16 | type Query { 17 | shouldRender: Condition! 18 | } 19 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/condition_example/test.dart: -------------------------------------------------------------------------------- 1 | import 'fragments.graphql.dart'; 2 | import 'query.graphql.dart'; 3 | 4 | void printTimeCondition(Fragment$TimeCondition condition) { 5 | print("TIME"); 6 | } 7 | 8 | void printAndCondition(Fragment$AndCondition condition) { 9 | printCondition(condition.left); 10 | print("AND"); 11 | printCondition(condition.right); 12 | } 13 | 14 | void printCondition(Fragment$Condition condition) { 15 | if (condition is Fragment$TimeCondition) printTimeCondition(condition); 16 | if (condition is Fragment$AndCondition) printAndCondition(condition); 17 | } 18 | 19 | void printCompositeCondition(Fragment$CompositeCondition condition) { 20 | printCondition(condition); 21 | } 22 | 23 | void printQuery(Query$FetchShouldRender q) { 24 | printCompositeCondition(q.shouldRender); 25 | } 26 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/copy_with/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | ts: [TS] 3 | tss: [[TS]] 4 | } 5 | 6 | type TS { 7 | name: String 8 | nameEnforced: String! 9 | t: TS 10 | } 11 | 12 | query Foobar { 13 | ts { 14 | t { 15 | name 16 | } 17 | name 18 | } 19 | tss { 20 | nameEnforced 21 | } 22 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/custom_enums/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | enum Enum { 3 | FOO BAR BAZ 4 | } 5 | 6 | type Query { 7 | value: Enum 8 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/custom_enums/document_2.graphql: -------------------------------------------------------------------------------- 1 | 2 | query Q { 3 | value 4 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/custom_enums/document_2.graphql.dart: -------------------------------------------------------------------------------- 1 | import './enum.dart' as EnumImport$Enum; 2 | import 'package:gql/ast.dart'; 3 | 4 | class Query$Q { 5 | Query$Q({ 6 | this.value, 7 | this.$__typename = 'Query', 8 | }); 9 | 10 | factory Query$Q.fromJson(Map json) { 11 | final l$value = json['value']; 12 | final l$$__typename = json['__typename']; 13 | return Query$Q( 14 | value: l$value == null 15 | ? null 16 | : EnumImport$Enum.fromJson((l$value as String)), 17 | $__typename: (l$$__typename as String), 18 | ); 19 | } 20 | 21 | final EnumImport$Enum.FancyEnum? value; 22 | 23 | final String $__typename; 24 | 25 | Map toJson() { 26 | final _resultData = {}; 27 | final l$value = value; 28 | _resultData['value'] = 29 | l$value == null ? null : EnumImport$Enum.toJson(l$value); 30 | final l$$__typename = $__typename; 31 | _resultData['__typename'] = l$$__typename; 32 | return _resultData; 33 | } 34 | 35 | @override 36 | int get hashCode { 37 | final l$value = value; 38 | final l$$__typename = $__typename; 39 | return Object.hashAll([ 40 | l$value, 41 | l$$__typename, 42 | ]); 43 | } 44 | 45 | @override 46 | bool operator ==(Object other) { 47 | if (identical(this, other)) { 48 | return true; 49 | } 50 | if (other is! Query$Q || runtimeType != other.runtimeType) { 51 | return false; 52 | } 53 | final l$value = value; 54 | final lOther$value = other.value; 55 | if (l$value != lOther$value) { 56 | return false; 57 | } 58 | final l$$__typename = $__typename; 59 | final lOther$$__typename = other.$__typename; 60 | if (l$$__typename != lOther$$__typename) { 61 | return false; 62 | } 63 | return true; 64 | } 65 | } 66 | 67 | extension UtilityExtension$Query$Q on Query$Q { 68 | CopyWith$Query$Q get copyWith => CopyWith$Query$Q( 69 | this, 70 | (i) => i, 71 | ); 72 | } 73 | 74 | abstract class CopyWith$Query$Q { 75 | factory CopyWith$Query$Q( 76 | Query$Q instance, 77 | TRes Function(Query$Q) then, 78 | ) = _CopyWithImpl$Query$Q; 79 | 80 | factory CopyWith$Query$Q.stub(TRes res) = _CopyWithStubImpl$Query$Q; 81 | 82 | TRes call({ 83 | EnumImport$Enum.FancyEnum? value, 84 | String? $__typename, 85 | }); 86 | } 87 | 88 | class _CopyWithImpl$Query$Q implements CopyWith$Query$Q { 89 | _CopyWithImpl$Query$Q( 90 | this._instance, 91 | this._then, 92 | ); 93 | 94 | final Query$Q _instance; 95 | 96 | final TRes Function(Query$Q) _then; 97 | 98 | static const _undefined = {}; 99 | 100 | TRes call({ 101 | Object? value = _undefined, 102 | Object? $__typename = _undefined, 103 | }) => 104 | _then(Query$Q( 105 | value: value == _undefined 106 | ? _instance.value 107 | : (value as EnumImport$Enum.FancyEnum?), 108 | $__typename: $__typename == _undefined || $__typename == null 109 | ? _instance.$__typename 110 | : ($__typename as String), 111 | )); 112 | } 113 | 114 | class _CopyWithStubImpl$Query$Q implements CopyWith$Query$Q { 115 | _CopyWithStubImpl$Query$Q(this._res); 116 | 117 | TRes _res; 118 | 119 | call({ 120 | EnumImport$Enum.FancyEnum? value, 121 | String? $__typename, 122 | }) => 123 | _res; 124 | } 125 | 126 | const documentNodeQueryQ = DocumentNode(definitions: [ 127 | OperationDefinitionNode( 128 | type: OperationType.query, 129 | name: NameNode(value: 'Q'), 130 | variableDefinitions: [], 131 | directives: [], 132 | selectionSet: SelectionSetNode(selections: [ 133 | FieldNode( 134 | name: NameNode(value: 'value'), 135 | alias: null, 136 | arguments: [], 137 | directives: [], 138 | selectionSet: null, 139 | ), 140 | FieldNode( 141 | name: NameNode(value: '__typename'), 142 | alias: null, 143 | arguments: [], 144 | directives: [], 145 | selectionSet: null, 146 | ), 147 | ]), 148 | ), 149 | ]); 150 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/custom_enums/enum.dart: -------------------------------------------------------------------------------- 1 | enum FancyEnum { 2 | v; 3 | } 4 | 5 | FancyEnum fromJson(String v) { 6 | return FancyEnum.v; 7 | } 8 | 9 | String toJson(FancyEnum v) { 10 | return 'FOO'; 11 | } 12 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/custom_enums/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "enums": { 3 | "Enum": { 4 | "type": "FancyEnum", 5 | "import": "./enum.dart", 6 | "fromJsonFunctionName": "fromJson", 7 | "toJsonFunctionName": "toJson" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/deprecated/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | deprecatedField: E @deprecated(reason: "Please don't") 3 | } 4 | 5 | enum E { 6 | A 7 | B 8 | DEPRECATED @deprecated(reason: "Please don't") 9 | } 10 | 11 | query Q { 12 | deprecatedField 13 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/disable_copy_with/document.graphql: -------------------------------------------------------------------------------- 1 | scalar DateTime 2 | 3 | input DataQuery { 4 | time: DateTime 5 | } 6 | 7 | type Query { 8 | data(input: DataQuery): I 9 | } 10 | 11 | 12 | interface I { 13 | value: String 14 | } 15 | 16 | type A implements I { 17 | value: String 18 | } 19 | 20 | type B implements I { 21 | value: String 22 | } 23 | 24 | 25 | fragment FA on A { 26 | value 27 | } 28 | 29 | fragment FB on B { 30 | value 31 | } 32 | 33 | query FetchScalars { 34 | data { 35 | ...FA 36 | ...FB 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/disable_copy_with/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "disableCopyWithGeneration": true 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/duplicate_names/document.graphql: -------------------------------------------------------------------------------- 1 | input I { 2 | title: String 3 | } 4 | 5 | input I_ { 6 | value: Float 7 | } 8 | 9 | input i { 10 | enabled: Boolean 11 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/enum_custom_fallback/document.graphql: -------------------------------------------------------------------------------- 1 | enum MyEnum { 2 | FIRST 3 | LAST 4 | OTHER 5 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/enum_custom_fallback/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "enums": { 3 | "MyEnum": { 4 | "fallbackEnumValue": "OTHER" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/enums/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/enums/query.graphql: -------------------------------------------------------------------------------- 1 | query Foobar { 2 | field 3 | fields 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/enums/query.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | import 'schema.graphql.dart'; 3 | 4 | class Query$Foobar { 5 | Query$Foobar({ 6 | this.field, 7 | this.fields, 8 | }); 9 | 10 | factory Query$Foobar.fromJson(Map json) { 11 | final l$field = json['field']; 12 | final l$fields = json['fields']; 13 | return Query$Foobar( 14 | field: l$field == null ? null : fromJson$Enum$Enum((l$field as String)), 15 | fields: (l$fields as List?) 16 | ?.map((e) => fromJson$Enum$Enum((e as String))) 17 | .toList(), 18 | ); 19 | } 20 | 21 | final Enum$Enum? field; 22 | 23 | final List? fields; 24 | 25 | Map toJson() { 26 | final _resultData = {}; 27 | final l$field = field; 28 | _resultData['field'] = l$field == null ? null : toJson$Enum$Enum(l$field); 29 | final l$fields = fields; 30 | _resultData['fields'] = l$fields?.map((e) => toJson$Enum$Enum(e)).toList(); 31 | return _resultData; 32 | } 33 | 34 | @override 35 | int get hashCode { 36 | final l$field = field; 37 | final l$fields = fields; 38 | return Object.hashAll([ 39 | l$field, 40 | l$fields == null ? null : Object.hashAll(l$fields.map((v) => v)), 41 | ]); 42 | } 43 | 44 | @override 45 | bool operator ==(Object other) { 46 | if (identical(this, other)) { 47 | return true; 48 | } 49 | if (other is! Query$Foobar || runtimeType != other.runtimeType) { 50 | return false; 51 | } 52 | final l$field = field; 53 | final lOther$field = other.field; 54 | if (l$field != lOther$field) { 55 | return false; 56 | } 57 | final l$fields = fields; 58 | final lOther$fields = other.fields; 59 | if (l$fields != null && lOther$fields != null) { 60 | if (l$fields.length != lOther$fields.length) { 61 | return false; 62 | } 63 | for (int i = 0; i < l$fields.length; i++) { 64 | final l$fields$entry = l$fields[i]; 65 | final lOther$fields$entry = lOther$fields[i]; 66 | if (l$fields$entry != lOther$fields$entry) { 67 | return false; 68 | } 69 | } 70 | } else if (l$fields != lOther$fields) { 71 | return false; 72 | } 73 | return true; 74 | } 75 | } 76 | 77 | extension UtilityExtension$Query$Foobar on Query$Foobar { 78 | CopyWith$Query$Foobar get copyWith => CopyWith$Query$Foobar( 79 | this, 80 | (i) => i, 81 | ); 82 | } 83 | 84 | abstract class CopyWith$Query$Foobar { 85 | factory CopyWith$Query$Foobar( 86 | Query$Foobar instance, 87 | TRes Function(Query$Foobar) then, 88 | ) = _CopyWithImpl$Query$Foobar; 89 | 90 | factory CopyWith$Query$Foobar.stub(TRes res) = _CopyWithStubImpl$Query$Foobar; 91 | 92 | TRes call({ 93 | Enum$Enum? field, 94 | List? fields, 95 | }); 96 | } 97 | 98 | class _CopyWithImpl$Query$Foobar implements CopyWith$Query$Foobar { 99 | _CopyWithImpl$Query$Foobar( 100 | this._instance, 101 | this._then, 102 | ); 103 | 104 | final Query$Foobar _instance; 105 | 106 | final TRes Function(Query$Foobar) _then; 107 | 108 | static const _undefined = {}; 109 | 110 | TRes call({ 111 | Object? field = _undefined, 112 | Object? fields = _undefined, 113 | }) => 114 | _then(Query$Foobar( 115 | field: field == _undefined ? _instance.field : (field as Enum$Enum?), 116 | fields: fields == _undefined 117 | ? _instance.fields 118 | : (fields as List?), 119 | )); 120 | } 121 | 122 | class _CopyWithStubImpl$Query$Foobar 123 | implements CopyWith$Query$Foobar { 124 | _CopyWithStubImpl$Query$Foobar(this._res); 125 | 126 | TRes _res; 127 | 128 | call({ 129 | Enum$Enum? field, 130 | List? fields, 131 | }) => 132 | _res; 133 | } 134 | 135 | const documentNodeQueryFoobar = DocumentNode(definitions: [ 136 | OperationDefinitionNode( 137 | type: OperationType.query, 138 | name: NameNode(value: 'Foobar'), 139 | variableDefinitions: [], 140 | directives: [], 141 | selectionSet: SelectionSetNode(selections: [ 142 | FieldNode( 143 | name: NameNode(value: 'field'), 144 | alias: null, 145 | arguments: [], 146 | directives: [], 147 | selectionSet: null, 148 | ), 149 | FieldNode( 150 | name: NameNode(value: 'fields'), 151 | alias: null, 152 | arguments: [], 153 | directives: [], 154 | selectionSet: null, 155 | ), 156 | ]), 157 | ), 158 | ]); 159 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/enums/schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | field: Enum 3 | fields: [Enum!] 4 | } 5 | 6 | enum Enum { 7 | FOO 8 | BAR 9 | BAZ_BOB 10 | VOID 11 | } 12 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/extends/document.graphql: -------------------------------------------------------------------------------- 1 | type Q { 2 | string: String 3 | i: I 4 | } 5 | 6 | extend type Q { 7 | int: Int 8 | } 9 | 10 | interface I { 11 | string: String 12 | } 13 | 14 | extend interface I { 15 | int: Int 16 | } 17 | query Q { 18 | string 19 | int 20 | i { 21 | int 22 | } 23 | } 24 | 25 | enum E { 26 | FOO 27 | } 28 | 29 | extend enum E { 30 | BAR 31 | } 32 | 33 | 34 | input In { 35 | string: String 36 | } 37 | 38 | extend input In { 39 | int: Int 40 | } 41 | 42 | 43 | schema { 44 | query: Q 45 | } 46 | 47 | extend schema { 48 | mutation: M 49 | } 50 | 51 | type M { 52 | string: String 53 | } 54 | 55 | mutation M { 56 | string 57 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/first_test/a.graphql: -------------------------------------------------------------------------------- 1 | 2 | query FetchName { 3 | name { 4 | ...F 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/first_test/a.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'fragments.graphql.dart'; 2 | import 'package:gql/ast.dart'; 3 | 4 | class Query$FetchName { 5 | Query$FetchName({this.name}); 6 | 7 | factory Query$FetchName.fromJson(Map json) { 8 | final l$name = json['name']; 9 | return Query$FetchName( 10 | name: l$name == null 11 | ? null 12 | : Fragment$F.fromJson((l$name as Map))); 13 | } 14 | 15 | final Fragment$F? name; 16 | 17 | Map toJson() { 18 | final _resultData = {}; 19 | final l$name = name; 20 | _resultData['name'] = l$name?.toJson(); 21 | return _resultData; 22 | } 23 | 24 | @override 25 | int get hashCode { 26 | final l$name = name; 27 | return Object.hashAll([l$name]); 28 | } 29 | 30 | @override 31 | bool operator ==(Object other) { 32 | if (identical(this, other)) { 33 | return true; 34 | } 35 | if (other is! Query$FetchName || runtimeType != other.runtimeType) { 36 | return false; 37 | } 38 | final l$name = name; 39 | final lOther$name = other.name; 40 | if (l$name != lOther$name) { 41 | return false; 42 | } 43 | return true; 44 | } 45 | } 46 | 47 | extension UtilityExtension$Query$FetchName on Query$FetchName { 48 | CopyWith$Query$FetchName get copyWith => 49 | CopyWith$Query$FetchName( 50 | this, 51 | (i) => i, 52 | ); 53 | } 54 | 55 | abstract class CopyWith$Query$FetchName { 56 | factory CopyWith$Query$FetchName( 57 | Query$FetchName instance, 58 | TRes Function(Query$FetchName) then, 59 | ) = _CopyWithImpl$Query$FetchName; 60 | 61 | factory CopyWith$Query$FetchName.stub(TRes res) = 62 | _CopyWithStubImpl$Query$FetchName; 63 | 64 | TRes call({Fragment$F? name}); 65 | CopyWith$Fragment$F get name; 66 | } 67 | 68 | class _CopyWithImpl$Query$FetchName 69 | implements CopyWith$Query$FetchName { 70 | _CopyWithImpl$Query$FetchName( 71 | this._instance, 72 | this._then, 73 | ); 74 | 75 | final Query$FetchName _instance; 76 | 77 | final TRes Function(Query$FetchName) _then; 78 | 79 | static const _undefined = {}; 80 | 81 | TRes call({Object? name = _undefined}) => _then(Query$FetchName( 82 | name: name == _undefined ? _instance.name : (name as Fragment$F?))); 83 | 84 | CopyWith$Fragment$F get name { 85 | final local$name = _instance.name; 86 | return local$name == null 87 | ? CopyWith$Fragment$F.stub(_then(_instance)) 88 | : CopyWith$Fragment$F(local$name, (e) => call(name: e)); 89 | } 90 | } 91 | 92 | class _CopyWithStubImpl$Query$FetchName 93 | implements CopyWith$Query$FetchName { 94 | _CopyWithStubImpl$Query$FetchName(this._res); 95 | 96 | TRes _res; 97 | 98 | call({Fragment$F? name}) => _res; 99 | 100 | CopyWith$Fragment$F get name => CopyWith$Fragment$F.stub(_res); 101 | } 102 | 103 | const documentNodeQueryFetchName = DocumentNode(definitions: [ 104 | OperationDefinitionNode( 105 | type: OperationType.query, 106 | name: NameNode(value: 'FetchName'), 107 | variableDefinitions: [], 108 | directives: [], 109 | selectionSet: SelectionSetNode(selections: [ 110 | FieldNode( 111 | name: NameNode(value: 'name'), 112 | alias: null, 113 | arguments: [], 114 | directives: [], 115 | selectionSet: SelectionSetNode(selections: [ 116 | FragmentSpreadNode( 117 | name: NameNode(value: 'F'), 118 | directives: [], 119 | ) 120 | ]), 121 | ) 122 | ]), 123 | ), 124 | fragmentDefinitionF, 125 | ]); 126 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/first_test/fragments.graphql: -------------------------------------------------------------------------------- 1 | 2 | fragment F on T{ 3 | name 4 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/first_test/fragments.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | 3 | class Fragment$F { 4 | Fragment$F({required this.name}); 5 | 6 | factory Fragment$F.fromJson(Map json) { 7 | final l$name = json['name']; 8 | return Fragment$F(name: (l$name as String)); 9 | } 10 | 11 | final String name; 12 | 13 | Map toJson() { 14 | final _resultData = {}; 15 | final l$name = name; 16 | _resultData['name'] = l$name; 17 | return _resultData; 18 | } 19 | 20 | @override 21 | int get hashCode { 22 | final l$name = name; 23 | return Object.hashAll([l$name]); 24 | } 25 | 26 | @override 27 | bool operator ==(Object other) { 28 | if (identical(this, other)) { 29 | return true; 30 | } 31 | if (other is! Fragment$F || runtimeType != other.runtimeType) { 32 | return false; 33 | } 34 | final l$name = name; 35 | final lOther$name = other.name; 36 | if (l$name != lOther$name) { 37 | return false; 38 | } 39 | return true; 40 | } 41 | } 42 | 43 | extension UtilityExtension$Fragment$F on Fragment$F { 44 | CopyWith$Fragment$F get copyWith => CopyWith$Fragment$F( 45 | this, 46 | (i) => i, 47 | ); 48 | } 49 | 50 | abstract class CopyWith$Fragment$F { 51 | factory CopyWith$Fragment$F( 52 | Fragment$F instance, 53 | TRes Function(Fragment$F) then, 54 | ) = _CopyWithImpl$Fragment$F; 55 | 56 | factory CopyWith$Fragment$F.stub(TRes res) = _CopyWithStubImpl$Fragment$F; 57 | 58 | TRes call({String? name}); 59 | } 60 | 61 | class _CopyWithImpl$Fragment$F implements CopyWith$Fragment$F { 62 | _CopyWithImpl$Fragment$F( 63 | this._instance, 64 | this._then, 65 | ); 66 | 67 | final Fragment$F _instance; 68 | 69 | final TRes Function(Fragment$F) _then; 70 | 71 | static const _undefined = {}; 72 | 73 | TRes call({Object? name = _undefined}) => _then(Fragment$F( 74 | name: name == _undefined || name == null 75 | ? _instance.name 76 | : (name as String))); 77 | } 78 | 79 | class _CopyWithStubImpl$Fragment$F implements CopyWith$Fragment$F { 80 | _CopyWithStubImpl$Fragment$F(this._res); 81 | 82 | TRes _res; 83 | 84 | call({String? name}) => _res; 85 | } 86 | 87 | const fragmentDefinitionF = FragmentDefinitionNode( 88 | name: NameNode(value: 'F'), 89 | typeCondition: TypeConditionNode( 90 | on: NamedTypeNode( 91 | name: NameNode(value: 'T'), 92 | isNonNull: false, 93 | )), 94 | directives: [], 95 | selectionSet: SelectionSetNode(selections: [ 96 | FieldNode( 97 | name: NameNode(value: 'name'), 98 | alias: null, 99 | arguments: [], 100 | directives: [], 101 | selectionSet: null, 102 | ) 103 | ]), 104 | ); 105 | const documentNodeFragmentF = DocumentNode(definitions: [ 106 | fragmentDefinitionF, 107 | ]); 108 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/first_test/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/first_test/schema.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | name: T 4 | } 5 | 6 | type T { 7 | name: String! 8 | } 9 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_and_field/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | person: IPerson 4 | } 5 | 6 | interface IPerson { 7 | name: String 8 | } 9 | 10 | type Person implements IPerson { 11 | name: String 12 | age: Int 13 | } 14 | 15 | query Q { 16 | person { 17 | name 18 | ...FPerson 19 | } 20 | } 21 | 22 | fragment FPerson on Person { 23 | age 24 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_enum_variables/schema.graphql: -------------------------------------------------------------------------------- 1 | enum Locale { 2 | da_DK 3 | nb_NO 4 | } 5 | 6 | input I { 7 | s: String 8 | } 9 | 10 | type Node { 11 | name(locale: Locale!): String 12 | test(i: I!): String 13 | } 14 | 15 | fragment F1 on Node { 16 | ...F2 17 | n1: name(locale: $locale) 18 | } 19 | 20 | fragment F2 on Node { 21 | n2: name(locale: $locale) 22 | } 23 | 24 | fragment F3 on Node { 25 | test(i: $i) 26 | } 27 | 28 | 29 | fragment F4 on Node { 30 | n1: name(locale: $locale) 31 | n2: name(locale: $locale) 32 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_imports/document1.graphql: -------------------------------------------------------------------------------- 1 | 2 | fragment F2 on T2 { 3 | value 4 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_imports/document1.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | 3 | class Fragment$F2 { 4 | Fragment$F2({this.value}); 5 | 6 | factory Fragment$F2.fromJson(Map json) { 7 | final l$value = json['value']; 8 | return Fragment$F2(value: (l$value as int?)); 9 | } 10 | 11 | final int? value; 12 | 13 | Map toJson() { 14 | final _resultData = {}; 15 | final l$value = value; 16 | _resultData['value'] = l$value; 17 | return _resultData; 18 | } 19 | 20 | @override 21 | int get hashCode { 22 | final l$value = value; 23 | return Object.hashAll([l$value]); 24 | } 25 | 26 | @override 27 | bool operator ==(Object other) { 28 | if (identical(this, other)) { 29 | return true; 30 | } 31 | if (other is! Fragment$F2 || runtimeType != other.runtimeType) { 32 | return false; 33 | } 34 | final l$value = value; 35 | final lOther$value = other.value; 36 | if (l$value != lOther$value) { 37 | return false; 38 | } 39 | return true; 40 | } 41 | } 42 | 43 | extension UtilityExtension$Fragment$F2 on Fragment$F2 { 44 | CopyWith$Fragment$F2 get copyWith => CopyWith$Fragment$F2( 45 | this, 46 | (i) => i, 47 | ); 48 | } 49 | 50 | abstract class CopyWith$Fragment$F2 { 51 | factory CopyWith$Fragment$F2( 52 | Fragment$F2 instance, 53 | TRes Function(Fragment$F2) then, 54 | ) = _CopyWithImpl$Fragment$F2; 55 | 56 | factory CopyWith$Fragment$F2.stub(TRes res) = _CopyWithStubImpl$Fragment$F2; 57 | 58 | TRes call({int? value}); 59 | } 60 | 61 | class _CopyWithImpl$Fragment$F2 implements CopyWith$Fragment$F2 { 62 | _CopyWithImpl$Fragment$F2( 63 | this._instance, 64 | this._then, 65 | ); 66 | 67 | final Fragment$F2 _instance; 68 | 69 | final TRes Function(Fragment$F2) _then; 70 | 71 | static const _undefined = {}; 72 | 73 | TRes call({Object? value = _undefined}) => _then(Fragment$F2( 74 | value: value == _undefined ? _instance.value : (value as int?))); 75 | } 76 | 77 | class _CopyWithStubImpl$Fragment$F2 78 | implements CopyWith$Fragment$F2 { 79 | _CopyWithStubImpl$Fragment$F2(this._res); 80 | 81 | TRes _res; 82 | 83 | call({int? value}) => _res; 84 | } 85 | 86 | const fragmentDefinitionF2 = FragmentDefinitionNode( 87 | name: NameNode(value: 'F2'), 88 | typeCondition: TypeConditionNode( 89 | on: NamedTypeNode( 90 | name: NameNode(value: 'T2'), 91 | isNonNull: false, 92 | )), 93 | directives: [], 94 | selectionSet: SelectionSetNode(selections: [ 95 | FieldNode( 96 | name: NameNode(value: 'value'), 97 | alias: null, 98 | arguments: [], 99 | directives: [], 100 | selectionSet: null, 101 | ) 102 | ]), 103 | ); 104 | const documentNodeFragmentF2 = DocumentNode(definitions: [ 105 | fragmentDefinitionF2, 106 | ]); 107 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_imports/document2.graphql: -------------------------------------------------------------------------------- 1 | fragment F1 on T1 { 2 | name 3 | } 4 | 5 | 6 | query Q { 7 | t { 8 | ...F1 9 | ...F2 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_imports/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_imports/schema.graphql: -------------------------------------------------------------------------------- 1 | type T1 { 2 | name: String 3 | } 4 | 5 | type T2 { 6 | value: Int 7 | } 8 | 9 | type Query { 10 | t: T1 11 | } 12 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_override/document.graphql: -------------------------------------------------------------------------------- 1 | type T { 2 | name: String 3 | t: T 4 | } 5 | 6 | fragment T1 on T { 7 | t { 8 | name 9 | } 10 | } 11 | 12 | fragment T2 on T { 13 | t { 14 | name 15 | } 16 | name 17 | } 18 | 19 | fragment TC on T { 20 | ...T1 21 | ...T2 22 | } 23 | 24 | type Query { 25 | t: T 26 | } 27 | 28 | query Q { 29 | t { 30 | ...TC 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_override/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_variables/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | level1(name: String): Level1 3 | } 4 | 5 | type Level1 { 6 | level2 (list: [String!]!): Level2 7 | } 8 | 9 | type Level2 { 10 | level3(i: Input): Level3 11 | } 12 | 13 | type Level3 { 14 | level4: Int 15 | } 16 | 17 | input Input { 18 | inputField: Boolean 19 | } 20 | 21 | fragment F1 on Query { 22 | level1(name: $name){ 23 | level2(list: $name) { 24 | level3(i: {inputField: $i}) { 25 | level4 26 | } 27 | } 28 | } 29 | } 30 | fragment F2 on Query { 31 | level1(name: $name){ 32 | ...F21 33 | } 34 | } 35 | 36 | fragment F21 on Level1 { 37 | level2(list: "foobar") { 38 | level3(i: {inputField: $i}) { 39 | level4 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_variables_2/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": ["graphql"] 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragment_variables_2/schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | node: Node 3 | } 4 | 5 | type Node { 6 | node: Node 7 | name(setting: String!): String 8 | } 9 | 10 | fragment NameNode on Node { 11 | name(setting: $setting) 12 | } 13 | 14 | query Q($setting: String!) { 15 | node { 16 | ...NameNode 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragments_and_loose_type_requirements/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | t: T 4 | } 5 | 6 | interface I { 7 | name: String 8 | } 9 | 10 | type T implements I { 11 | name: String 12 | t: T 13 | } 14 | 15 | fragment F on I { 16 | __typename 17 | name 18 | ...on T { 19 | __typename 20 | t { 21 | name 22 | } 23 | } 24 | } 25 | 26 | 27 | query Q { 28 | t { 29 | __typename 30 | ...F 31 | } 32 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragments_and_loose_type_requirements/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragments_inheritence/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | t: Type 3 | } 4 | 5 | interface Type { 6 | name: String 7 | other: Type 8 | } 9 | 10 | type T1 implements Type { 11 | name: String 12 | other: Type 13 | b: Boolean 14 | } 15 | 16 | fragment F on Type { 17 | other { 18 | ...F2 19 | ... on T1 { 20 | b 21 | } 22 | } 23 | } 24 | 25 | fragment F2 on Type { 26 | other { 27 | name 28 | } 29 | } 30 | 31 | query Fetch { 32 | t { 33 | ...F 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragments_inheritence/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragments_nested_data/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | t: Type 3 | } 4 | 5 | interface Type { 6 | name: String 7 | other: Type 8 | } 9 | 10 | fragment F on Type { 11 | other { 12 | ...F2 13 | } 14 | } 15 | 16 | fragment F2 on Type { 17 | other { 18 | ...F3 19 | } 20 | } 21 | 22 | fragment F3 on Type { 23 | other { 24 | ...F4 25 | } 26 | } 27 | 28 | fragment F4 on Type { 29 | name 30 | } 31 | 32 | query Fetch { 33 | t { 34 | ...F 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/fragments_nested_data/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/gql_extensions/document.gql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | fetchCount: Int 4 | } 5 | 6 | 7 | query FetchCount { 8 | fetchCount 9 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_client/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | s(name: String): String 3 | s2(name: String!): String 4 | } 5 | 6 | type Mutation { 7 | s(name: String): String 8 | } 9 | 10 | fragment NoVariables on Query { 11 | s(name: "name") 12 | } 13 | 14 | fragment WithOptionalVariables on Query { 15 | s(name: $name) 16 | } 17 | 18 | fragment WithVariables on Query { 19 | s2(name: $name) 20 | } 21 | 22 | query FetchSOptional($name: String) { 23 | s(name: $name) 24 | } 25 | 26 | query FetchSRequired($name: String!) { 27 | s(name: $name) 28 | } 29 | 30 | query FetchSNoVariables { 31 | s(name: "lol") 32 | } 33 | 34 | 35 | mutation UpdateSOptional($name: String) { 36 | s(name: $name) 37 | } 38 | 39 | mutation UpdateSRequired($name: String!) { 40 | s(name: $name) 41 | } 42 | 43 | mutation UpdateSNoVariables { 44 | s(name: "lol") 45 | } 46 | 47 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_client/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql" 4 | ], 5 | "addTypename": false 6 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_client_nested_fragments/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | field: T1 3 | } 4 | 5 | type T1 { 6 | name: String 7 | field: T1 8 | } 9 | 10 | fragment F1 on T1{ 11 | name 12 | field { 13 | ...F2 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_client_nested_fragments/document2.graphql: -------------------------------------------------------------------------------- 1 | fragment F2 on T1 { 2 | name 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_client_nested_fragments/document2.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | import 'package:graphql/client.dart' as graphql; 3 | 4 | class Fragment$F2 { 5 | Fragment$F2({ 6 | this.name, 7 | this.$__typename = 'T1', 8 | }); 9 | 10 | factory Fragment$F2.fromJson(Map json) { 11 | final l$name = json['name']; 12 | final l$$__typename = json['__typename']; 13 | return Fragment$F2( 14 | name: (l$name as String?), 15 | $__typename: (l$$__typename as String), 16 | ); 17 | } 18 | 19 | final String? name; 20 | 21 | final String $__typename; 22 | 23 | Map toJson() { 24 | final _resultData = {}; 25 | final l$name = name; 26 | _resultData['name'] = l$name; 27 | final l$$__typename = $__typename; 28 | _resultData['__typename'] = l$$__typename; 29 | return _resultData; 30 | } 31 | 32 | @override 33 | int get hashCode { 34 | final l$name = name; 35 | final l$$__typename = $__typename; 36 | return Object.hashAll([ 37 | l$name, 38 | l$$__typename, 39 | ]); 40 | } 41 | 42 | @override 43 | bool operator ==(Object other) { 44 | if (identical(this, other)) { 45 | return true; 46 | } 47 | if (other is! Fragment$F2 || runtimeType != other.runtimeType) { 48 | return false; 49 | } 50 | final l$name = name; 51 | final lOther$name = other.name; 52 | if (l$name != lOther$name) { 53 | return false; 54 | } 55 | final l$$__typename = $__typename; 56 | final lOther$$__typename = other.$__typename; 57 | if (l$$__typename != lOther$$__typename) { 58 | return false; 59 | } 60 | return true; 61 | } 62 | } 63 | 64 | extension UtilityExtension$Fragment$F2 on Fragment$F2 { 65 | CopyWith$Fragment$F2 get copyWith => CopyWith$Fragment$F2( 66 | this, 67 | (i) => i, 68 | ); 69 | } 70 | 71 | abstract class CopyWith$Fragment$F2 { 72 | factory CopyWith$Fragment$F2( 73 | Fragment$F2 instance, 74 | TRes Function(Fragment$F2) then, 75 | ) = _CopyWithImpl$Fragment$F2; 76 | 77 | factory CopyWith$Fragment$F2.stub(TRes res) = _CopyWithStubImpl$Fragment$F2; 78 | 79 | TRes call({ 80 | String? name, 81 | String? $__typename, 82 | }); 83 | } 84 | 85 | class _CopyWithImpl$Fragment$F2 implements CopyWith$Fragment$F2 { 86 | _CopyWithImpl$Fragment$F2( 87 | this._instance, 88 | this._then, 89 | ); 90 | 91 | final Fragment$F2 _instance; 92 | 93 | final TRes Function(Fragment$F2) _then; 94 | 95 | static const _undefined = {}; 96 | 97 | TRes call({ 98 | Object? name = _undefined, 99 | Object? $__typename = _undefined, 100 | }) => 101 | _then(Fragment$F2( 102 | name: name == _undefined ? _instance.name : (name as String?), 103 | $__typename: $__typename == _undefined || $__typename == null 104 | ? _instance.$__typename 105 | : ($__typename as String), 106 | )); 107 | } 108 | 109 | class _CopyWithStubImpl$Fragment$F2 110 | implements CopyWith$Fragment$F2 { 111 | _CopyWithStubImpl$Fragment$F2(this._res); 112 | 113 | TRes _res; 114 | 115 | call({ 116 | String? name, 117 | String? $__typename, 118 | }) => 119 | _res; 120 | } 121 | 122 | const fragmentDefinitionF2 = FragmentDefinitionNode( 123 | name: NameNode(value: 'F2'), 124 | typeCondition: TypeConditionNode( 125 | on: NamedTypeNode( 126 | name: NameNode(value: 'T1'), 127 | isNonNull: false, 128 | )), 129 | directives: [], 130 | selectionSet: SelectionSetNode(selections: [ 131 | FieldNode( 132 | name: NameNode(value: 'name'), 133 | alias: null, 134 | arguments: [], 135 | directives: [], 136 | selectionSet: null, 137 | ), 138 | FieldNode( 139 | name: NameNode(value: '__typename'), 140 | alias: null, 141 | arguments: [], 142 | directives: [], 143 | selectionSet: null, 144 | ), 145 | ]), 146 | ); 147 | const documentNodeFragmentF2 = DocumentNode(definitions: [ 148 | fragmentDefinitionF2, 149 | ]); 150 | 151 | extension ClientExtension$Fragment$F2 on graphql.GraphQLClient { 152 | void writeFragment$F2({ 153 | required Fragment$F2 data, 154 | required Map idFields, 155 | bool broadcast = true, 156 | }) => 157 | this.writeFragment( 158 | graphql.FragmentRequest( 159 | idFields: idFields, 160 | fragment: const graphql.Fragment( 161 | fragmentName: 'F2', 162 | document: documentNodeFragmentF2, 163 | ), 164 | ), 165 | data: data.toJson(), 166 | broadcast: broadcast, 167 | ); 168 | Fragment$F2? readFragment$F2({ 169 | required Map idFields, 170 | bool optimistic = true, 171 | }) { 172 | final result = this.readFragment( 173 | graphql.FragmentRequest( 174 | idFields: idFields, 175 | fragment: const graphql.Fragment( 176 | fragmentName: 'F2', 177 | document: documentNodeFragmentF2, 178 | ), 179 | ), 180 | optimistic: optimistic, 181 | ); 182 | return result == null ? null : Fragment$F2.fromJson(result); 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_client_nested_fragments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": ["graphql"] 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_infer_graphql_client/document.graphql: -------------------------------------------------------------------------------- 1 | type Mutation { 2 | s(name: String): String 3 | } 4 | 5 | mutation UpdateSNo { 6 | s(name: "lol") 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_infer_graphql_client/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql_flutter" 4 | ], 5 | "addTypename": false 6 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_mutation_no_arguments/document.graphql: -------------------------------------------------------------------------------- 1 | type Mutation { 2 | s(name: String): String 3 | } 4 | 5 | mutation UpdateSNo { 6 | s(name: "lol") 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_mutation_no_arguments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql", 4 | "graphql_flutter" 5 | ], 6 | "addTypename": false 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_mutation_optional_arguments/document.graphql: -------------------------------------------------------------------------------- 1 | type Mutation { 2 | s(name: String): String 3 | } 4 | 5 | mutation UpdateSOptional($name: String) { 6 | s(name: $name) 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_mutation_optional_arguments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql", 4 | "graphql_flutter" 5 | ], 6 | "addTypename": false 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_mutation_required_arguments/document.graphql: -------------------------------------------------------------------------------- 1 | type Mutation { 2 | s(name: String): String 3 | } 4 | 5 | mutation UpdateSRequired($name: String!) { 6 | s(name: $name) 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_mutation_required_arguments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql", 4 | "graphql_flutter" 5 | ], 6 | "addTypename": false 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_query_no_arguments/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | s(name: String): String 3 | } 4 | 5 | query FetchSNoVariables { 6 | s(name: "lol") 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_query_no_arguments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql", 4 | "graphql_flutter" 5 | ], 6 | "addTypename": false 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_query_optional_arguments/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | s(name: String): String 3 | } 4 | 5 | query FetchSOptional($name: String) { 6 | s(name: $name) 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_query_optional_arguments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql", 4 | "graphql_flutter" 5 | ], 6 | "addTypename": false 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_query_required_arguments/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | s(name: String): String 3 | } 4 | 5 | query FetchSRequired($name: String!) { 6 | s(name: $name) 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_query_required_arguments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql", 4 | "graphql_flutter" 5 | ], 6 | "addTypename": false 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_subscription/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql", 4 | "graphql_flutter" 5 | ] 6 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_client_subscription/schema.graphql: -------------------------------------------------------------------------------- 1 | type Subscription { 2 | listenForChange(name: String): Change 3 | } 4 | 5 | type Change { 6 | name: String! 7 | } 8 | 9 | subscription NoArgs { 10 | listenForChange { 11 | name 12 | } 13 | } 14 | 15 | subscription RequiredArg($name: String!) { 16 | listenForChange(name: $name) { 17 | name 18 | } 19 | } 20 | 21 | subscription OptionalArg($name: String) { 22 | listenForChange(name: $name) { 23 | name 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_naming_config/document.graphql: -------------------------------------------------------------------------------- 1 | enum Status { 2 | Pending 3 | Successful 4 | Failure 5 | InProgress 6 | } 7 | 8 | type Query { 9 | status(i: Input): Status 10 | } 11 | 12 | 13 | query Q { 14 | status 15 | } 16 | 17 | input Input { 18 | status: Status 19 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/graphql_flutter_naming_config/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "namingSeparator": "___", 3 | "clients": [ 4 | "graphql", 5 | "graphql_flutter" 6 | ] 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/header/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "generatedFileHeader": "// Hello\n// World\n" 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/header/schema.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | foo: String 4 | } 5 | 6 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/include_if_null_input/document.graphql: -------------------------------------------------------------------------------- 1 | input Input { 2 | field: String 3 | flag: Boolean 4 | } 5 | 6 | type Query { 7 | field(input: Input): String 8 | } 9 | 10 | query Q1($input: Input) { 11 | field(input: $input) 12 | } 13 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/include_if_null_input/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "includeIfNullOnInput": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/include_skip/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | foo: Foo 3 | } 4 | 5 | type Foo { 6 | foo: String! 7 | bar: String! 8 | list: [Int!]! 9 | } 10 | 11 | query Q1 { 12 | foo { 13 | foo 14 | bar @include(if: false) 15 | list @skip(if: true) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/input/input.graphql: -------------------------------------------------------------------------------- 1 | input I1 { 2 | s: String! 3 | sMaybe: String 4 | nested_input: I1 5 | children: [I1!] 6 | children2: [[I1]] 7 | _min: Int 8 | eMaybe: E 9 | e: E! 10 | es: [E!]! 11 | i2: I2 12 | } 13 | 14 | input I2 { 15 | foobar: Foobar 16 | } 17 | 18 | enum E { 19 | FOO 20 | BAR 21 | BAZ 22 | } 23 | scalar Foobar 24 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/input/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/input_builder/input.graphql: -------------------------------------------------------------------------------- 1 | input I1 { 2 | s: String! 3 | sMaybe: String 4 | nested_input: I1 5 | children: [I1!] 6 | children2: [[I1]] 7 | _min: Int 8 | eMaybe: E 9 | e: E! 10 | es: [E!]! 11 | i2: I2 12 | } 13 | 14 | input I2 { 15 | foobar: Foobar 16 | } 17 | 18 | enum E { 19 | FOO 20 | BAR 21 | BAZ 22 | } 23 | scalar Foobar 24 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/input_builder/input_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | import 'input.graphql.dart'; 4 | 5 | void main() { 6 | group("Input builder", () { 7 | test("should not set values to null", () { 8 | expect( 9 | Input$I1( 10 | (builder) => builder( 11 | e: Enum$E.BAR, 12 | s: '', 13 | es: [Enum$E.BAR], 14 | ), 15 | ).toJson(), 16 | equals({ 17 | 'e': 'BAR', 18 | 's': '', 19 | 'es': ['BAR'], 20 | })); 21 | }); 22 | test("should set explicit null values to null", () { 23 | expect( 24 | Input$I1( 25 | (builder) => builder( 26 | e: Enum$E.BAR, 27 | s: '', 28 | es: [Enum$E.BAR], 29 | sMaybe: null, 30 | ), 31 | ).toJson(), 32 | equals({ 33 | 'e': 'BAR', 34 | 's': '', 35 | 'es': ['BAR'], 36 | 'sMaybe': null, 37 | })); 38 | }); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/input_builder/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "EXPERIMENTAL_enable_input_builders": true 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/input_oneOf/input.graphql: -------------------------------------------------------------------------------- 1 | input I1 @oneOf { 2 | v1: Int 3 | v2: Int 4 | v3: Int 5 | } 6 | 7 | input I2 @oneOf { 8 | v1: Int 9 | v2: Int 10 | v3: Int! 11 | } 12 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/input_oneOf/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/interface_and_fragments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/interface_and_fragments/query.graphql: -------------------------------------------------------------------------------- 1 | query FetchImplementations { 2 | interface { 3 | typename: __typename 4 | b 5 | self { 6 | __typename 7 | ...FragmentA 8 | ...FragmentB 9 | } 10 | ... on ImplementationA { 11 | b 12 | ...FragmentA 13 | } 14 | ... on ImplementationB { 15 | ...FragmentB 16 | } 17 | } 18 | } 19 | 20 | fragment FragmentA on ImplementationA{ 21 | s 22 | _s: s 23 | } 24 | 25 | 26 | fragment FragmentB on ImplementationB{ 27 | i 28 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/interface_and_fragments/schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | interface: Interface 3 | } 4 | 5 | interface Interface { 6 | b: Boolean 7 | self: Interface! 8 | other: Interface! 9 | } 10 | 11 | type ImplementationA implements Interface { 12 | b: Boolean 13 | self: ImplementationA! 14 | other: ImplementationB! 15 | s: String 16 | } 17 | 18 | type ImplementationB implements Interface { 19 | b: Boolean 20 | self: ImplementationB! 21 | other: ImplementationA! 22 | i: Int 23 | } 24 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/interfaces_and_concrete_types/document.graphql: -------------------------------------------------------------------------------- 1 | interface IField { 2 | name: String 3 | } 4 | 5 | type TField implements IField { 6 | name: String 7 | age: Int 8 | } 9 | 10 | interface I1 { 11 | i2: I2 12 | } 13 | 14 | type T1 implements I1 { 15 | i2: I2 16 | i2c: T2 17 | } 18 | 19 | interface I2 { 20 | field: IField 21 | } 22 | 23 | type T2 implements I2 { 24 | field: TField 25 | } 26 | 27 | type Query { 28 | i1: I1 29 | } 30 | 31 | query FetchI { 32 | i1 { 33 | i2 { 34 | field { 35 | name 36 | } 37 | } 38 | ... on T1 { 39 | i2c { 40 | field { 41 | age 42 | } 43 | } 44 | i2 { 45 | field { 46 | name 47 | } 48 | ...on T2 { 49 | field { 50 | age 51 | } 52 | } 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/introspection_schema/document.graphql: -------------------------------------------------------------------------------- 1 | query Q { 2 | hello 3 | } 4 | 5 | query Introspection { 6 | __schema { 7 | queryType { 8 | name 9 | } 10 | mutationType { 11 | name 12 | } 13 | subscriptionType { 14 | name 15 | } 16 | types { 17 | ...FullType 18 | } 19 | directives { 20 | name 21 | description 22 | locations 23 | args { 24 | ...InputValue 25 | } 26 | } 27 | } 28 | __type(name: "Query") { 29 | ...FullType 30 | } 31 | } 32 | 33 | fragment FullType on __Type { 34 | kind 35 | name 36 | description 37 | fields(includeDeprecated: true) { 38 | name 39 | description 40 | args { 41 | ...InputValue 42 | } 43 | type { 44 | ...TypeRef 45 | } 46 | isDeprecated 47 | deprecationReason 48 | } 49 | inputFields { 50 | ...InputValue 51 | } 52 | interfaces { 53 | ...TypeRef 54 | } 55 | enumValues(includeDeprecated: true) { 56 | name 57 | description 58 | isDeprecated 59 | deprecationReason 60 | } 61 | possibleTypes { 62 | ...TypeRef 63 | } 64 | } 65 | 66 | fragment TypeRef on __Type { 67 | kind 68 | name 69 | } 70 | 71 | fragment InputValue on __InputValue { 72 | name 73 | description 74 | type { 75 | ...TypeRef 76 | } 77 | defaultValue 78 | } 79 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/introspection_schema/schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | hello: String 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_158/document.graphql: -------------------------------------------------------------------------------- 1 | interface IPerson { 2 | id: ID! 3 | } 4 | 5 | type Person implements IPerson { 6 | id: ID! 7 | } 8 | 9 | 10 | type Query { 11 | person(id: ID!): Person 12 | } 13 | 14 | query GetPerson { 15 | #type Person 16 | person(id: 1) { 17 | ...PersonSummary 18 | } 19 | } 20 | 21 | fragment PersonSummary on IPerson { 22 | id 23 | } 24 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_160/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | input I1 { 3 | nested: [[I2!]!] 4 | maybe_nested: [[I2]] 5 | } 6 | 7 | input I2 { 8 | str: String 9 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_168/payload_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/expect.dart'; 2 | import 'package:test/scaffolding.dart'; 3 | 4 | import './schema.graphql.dart'; 5 | 6 | const data = { 7 | "__typename": "Query", 8 | "walletGetContent": { 9 | "__typename": "WalletGetContentPayload", 10 | "blocks": [ 11 | { 12 | "__typename": "WalletContentBlockList", 13 | "id": "1", 14 | "blockType": { 15 | "__typename": "WalletContentBlockType", 16 | "id": "horizontal-scrolling-list", 17 | }, 18 | "caption": "Featured", 19 | "items": [ 20 | { 21 | "__typename": "WalletContentItemContentPreview", 22 | "id": "1", 23 | "caption": "Remarkable Women #4740", 24 | "imageURL": 25 | "https://lh3.googleusercontent.com/1kXncBpOzPjZAC46GDNXvW4NL0zDv1e_E6vzsTtKEAOAvb0SwbWzwljDY5hulMqRA4zQytjYjV7B-a_jYtNG6zy9dKssov9RRRLu5ss=w600", 26 | "link": 27 | "https://opensea.io/assets/ethereum/0x3e69baab7a742c83499661c5db92386b2424df11/4740" 28 | }, 29 | { 30 | "__typename": "WalletContentItemContentPreview", 31 | "id": "2", 32 | "caption": "Inftspaces", 33 | "imageURL": 34 | "https://lh3.googleusercontent.com/8h6WQ4_Kxn0c6rBujSe0flZMTSKiWGWiMOSNaSTPUchakVq4TmyBOWJi4E0GU3_5b7v4jF-vIPR24uziltXMfQHgzEj3zBCkW_Tbsw=s0", 35 | "link": 36 | "https://opensea.io/assets/ethereum/0xb11288c7237765db4782dfddcc49e31bb80132b8/90" 37 | }, 38 | { 39 | "__typename": "WalletContentItemContentPreview", 40 | "id": "3", 41 | "caption": "Love on Mars", 42 | "imageURL": 43 | "https://lh3.googleusercontent.com/XoOJwf3DQ6ZWMpmmLkVqfZD3AqEM3G0xQCXNur0-u5-HAHpoMHyPJQL__5H0wpJsy2cafaaCSSxI5YPjnzCZ-4ME7hnJXrgd5292nA=s0", 44 | "link": 45 | "https://opensea.io/collection/love-on-mars-by-ruben-rojas-x-omgdrops" 46 | } 47 | ] 48 | }, 49 | { 50 | "__typename": "WalletContentBlockList", 51 | "id": "2", 52 | "blockType": { 53 | "__typename": "WalletContentBlockType", 54 | "id": "vertical-short-list" 55 | }, 56 | "caption": "New", 57 | "items": [ 58 | { 59 | "__typename": "WalletContentItemContentPreview", 60 | "id": "1", 61 | "caption": "MSO LAB Genesis #844", 62 | "imageURL": 63 | "https://lh3.googleusercontent.com/FCcSKSsYaNk9-bzks7ZWIEjFPiL8xrtb8aYnO2DG0piF9Eja1AkY55Yan-KQqtpcwISdpTWNz_W0yrmmmQM2hAHNG_AIXl7E4ATG2Q=w600", 64 | "link": 65 | "https://opensea.io/assets/ethereum/0xc2ac394984f3850027dac95fe8a62e446c5fb786/844" 66 | }, 67 | { 68 | "__typename": "WalletContentItemContentPreview", 69 | "id": "2", 70 | "caption": "The Outsiders Genesis", 71 | "imageURL": 72 | "https://lh3.googleusercontent.com/AM8EkaQl32uR8N1RIiJa5ogVG1gh2faX6u4a1TAa_NhsGkA2CRG0pFfMOOxcc09q2KFq5cQNljTFkDbbScWpUT70es83Di0RRWD7fjM=s0", 73 | "link": "https://opensea.io/collection/the-outsiders-genesis" 74 | }, 75 | { 76 | "__typename": "WalletContentItemContentPreview", 77 | "id": "3", 78 | "caption": "Bored Ape Yacht Club #6386", 79 | "imageURL": 80 | "https://img.seadn.io/files/968a4be8ada4a55b59de561d15522b4e.png?fit=max&w=600", 81 | "link": 82 | "https://opensea.io/assets/ethereum/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d/6386" 83 | } 84 | ] 85 | } 86 | ] 87 | } 88 | }; 89 | void main() { 90 | group("Issue 168", () { 91 | test("payload", () { 92 | expect(Query$WalletGetContent.fromJson(data).toJson(), equals(data)); 93 | }); 94 | }); 95 | } 96 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_168/schema.graphql: -------------------------------------------------------------------------------- 1 | union WalletContentBlock = WalletContentBlockList 2 | 3 | type WalletContentBlockList { 4 | id: ID! 5 | blockType: WalletContentBlockType! 6 | caption: String 7 | items: [WalletContentItem!] 8 | } 9 | 10 | type WalletContentBlockType { 11 | id: ID! 12 | } 13 | 14 | union WalletContentItem = WalletContentItemContentPreview 15 | 16 | type WalletContentItemContentPreview { 17 | id: ID! 18 | caption: String 19 | imageURL: String 20 | link: String 21 | } 22 | 23 | input WalletGetContentInput { 24 | id: ID 25 | } 26 | 27 | type WalletGetContentPayload { 28 | blocks: [WalletContentBlock!] 29 | } 30 | 31 | type Query { 32 | walletGetContent(input: WalletGetContentInput!): WalletGetContentPayload! 33 | } 34 | 35 | 36 | query WalletGetContent($input: WalletGetContentInput!) { 37 | walletGetContent(input: $input) { 38 | blocks { 39 | ... on WalletContentBlockList { 40 | id 41 | blockType { 42 | id 43 | } 44 | caption 45 | items { 46 | ... on WalletContentItemContentPreview { 47 | id 48 | caption 49 | imageURL 50 | link 51 | } 52 | } 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_181/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | fetch_person(id: ID!): Person 4 | } 5 | 6 | type Person { 7 | full_name: String! 8 | nickname: String 9 | website: URL 10 | date_of_birth: ISODateTime 11 | favorite_parent: Person 12 | parents: [Person!] 13 | siblings: [Person!] 14 | children: [Person!] 15 | dob: ISODateTime 16 | events: [ISODateTime] 17 | events_of_events: [[ISODateTime]] 18 | } 19 | 20 | scalar ISODateTime 21 | 22 | scalar URL 23 | 24 | type Mutation { 25 | update_person(id: ID!, full_name: String): Person 26 | update_person_advanced(input: UpdatePersonInput!): Person 27 | } 28 | 29 | type Subscription { 30 | watch_person(id: ID): Person 31 | } 32 | 33 | input UpdatePersonInput { 34 | id: ID! 35 | full_name: String 36 | nickname: String 37 | website: URL 38 | } 39 | 40 | enum QueryMode { 41 | default 42 | insensitive 43 | } 44 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_184/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Person { 3 | default: String 4 | } 5 | 6 | type Query { 7 | p: Person 8 | } 9 | 10 | fragment F on Person { 11 | default 12 | } 13 | 14 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_191/mutation.graphql: -------------------------------------------------------------------------------- 1 | mutation M { 2 | bar 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_191/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "setOperationName": true, 3 | "clients": ["graphql"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_191/query.graphql: -------------------------------------------------------------------------------- 1 | query Q { 2 | foo 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_191/schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | foo: String 3 | } 4 | 5 | type Mutation { 6 | bar: String 7 | } 8 | 9 | type Subscription { 10 | foo: String 11 | } 12 | 13 | query { 14 | foo 15 | } 16 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_191/subscription.graphql: -------------------------------------------------------------------------------- 1 | subscription S { 2 | foo 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_192/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | book: Book 4 | } 5 | 6 | interface Book { 7 | author: String 8 | } 9 | 10 | type TextBook implements Book { 11 | author: String 12 | courses: Int 13 | } 14 | 15 | 16 | query Q { 17 | book { 18 | author 19 | ... on TextBook { 20 | courses 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_192/serializer_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/expect.dart'; 2 | import 'package:test/scaffolding.dart'; 3 | 4 | import 'document.graphql.dart'; 5 | 6 | void main() { 7 | test("can serialize and deserialize", () { 8 | final json1 = { 9 | '__typename': 'Query', 10 | 'book': { 11 | '__typename': 'TextBook', 12 | 'author': 'Bob', 13 | 'courses': 4, 14 | } 15 | }; 16 | final json2 = Query$Q.fromJson(json1).toJson(); 17 | expect(json1, equals(json2)); 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_206/document.graphql: -------------------------------------------------------------------------------- 1 | schema { 2 | mutation: Mutations 3 | } 4 | 5 | type Mutations { 6 | bla: EventUnion 7 | } 8 | 9 | union EventUnion = EventPublic 10 | 11 | interface Event { 12 | subscription: EventSubscription 13 | } 14 | 15 | type EventPublic implements Event { 16 | owner: UserPublic! 17 | subscription: EventSubscription 18 | } 19 | 20 | type EventSubscription { 21 | notifyFor: String! 22 | } 23 | 24 | type UserPublic { 25 | username: String! 26 | } 27 | 28 | fragment EventFragment on Event { 29 | subscription { 30 | notifyFor 31 | } 32 | ...on EventPublic { 33 | owner { ...UserPublicFragment } 34 | } 35 | } 36 | 37 | fragment UserPublicFragment on UserPublic { 38 | username 39 | } 40 | 41 | mutation Bla { 42 | bla { ...EventFragment } 43 | } 44 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_206/options.json: -------------------------------------------------------------------------------- 1 | { 2 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_217/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | user(id: ID!): User 3 | } 4 | 5 | type Mutation { 6 | createUser( 7 | name: String 8 | email: String! 9 | authType: String! 10 | authSecret: String! 11 | ): User 12 | 13 | authUser(email: String!, authType: String!, authSecret: String!): User 14 | 15 | refreshToken: User 16 | } 17 | 18 | type User { 19 | _id: ID! 20 | name: String 21 | email: String! 22 | authType: String! 23 | plan: String! 24 | authRes: AuthRes 25 | } 26 | 27 | type AuthRes { 28 | token: String! 29 | refreshToken: String! 30 | expInSecs: Int! 31 | } 32 | 33 | mutation ($email: String!, $authType: String!, $authSecret: String!) { 34 | authUser(email: $email, authType: $authType, authSecret: $authSecret) { 35 | _id 36 | email 37 | authType 38 | plan 39 | name 40 | plan 41 | authRes { 42 | token 43 | expInSecs 44 | refreshToken 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_229/graphql/builder_options.json: -------------------------------------------------------------------------------- 1 | { 2 | "noFlatLib": true 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_229/graphql/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": 3 | ["graphql"], 4 | "assetsPath": "graphql/**", 5 | "scopes": 6 | ["graphql/schemaA/**", 7 | "graphql/schemaB/**"], 8 | "outputDirectory": "/lib/generated" 9 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_229/graphql/schemaA/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | q: String 3 | } 4 | 5 | query Q { 6 | q 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_229/graphql/schemaB/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | q: Int 3 | } 4 | 5 | query Q { 6 | q 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_239/document.graphql: -------------------------------------------------------------------------------- 1 | type HotelBooking { 2 | name: String 3 | } 4 | 5 | union Booking = HotelBooking 6 | 7 | type Query { 8 | booking: Booking 9 | hotelBooking: HotelBooking 10 | } 11 | 12 | 13 | fragment HotelBooking on HotelBooking { 14 | name 15 | } 16 | 17 | query Q { 18 | booking { 19 | ...HotelBooking 20 | } 21 | hotelBooking { 22 | ...HotelBooking 23 | } 24 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_288/document.graphql: -------------------------------------------------------------------------------- 1 | scalar Sex 2 | 3 | type User { 4 | username: String! 5 | email: String 6 | sex: Sex 7 | age: Int 8 | notifications: [Notification!] 9 | } 10 | union Notification = FriendRequestNotification | NewsNotification 11 | 12 | type FriendRequestNotification { 13 | requesterUsername: String! 14 | } 15 | 16 | type NewsNotification { 17 | newsId: String! 18 | } 19 | 20 | type Query { 21 | getUser(username: String!): User 22 | } 23 | fragment FullFriendRequestNotification on FriendRequestNotification { 24 | requesterUsername 25 | } 26 | 27 | fragment FullNewsNotification on NewsNotification { 28 | newsId 29 | } 30 | 31 | fragment FullUser on User { 32 | username 33 | email 34 | sex 35 | age 36 | notifications { 37 | ...FullFriendRequestNotification 38 | ...FullNewsNotification 39 | } 40 | } 41 | 42 | query GetUser($username: String!) { 43 | getUser(username: $username) { 44 | ...FullUser 45 | } 46 | } 47 | 48 | query GetNotifications($username: String!) { 49 | getUser(username: $username) { 50 | __typename 51 | username 52 | notifications { 53 | ...FullFriendRequestNotification 54 | ...FullNewsNotification 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_293/doc_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | import 'document.graphql.dart'; 4 | 5 | void main() { 6 | group('Variables', () { 7 | test('It should not send value non-required non-null value', () { 8 | expect( 9 | Variables$Query$Q( 10 | nonNull: false, 11 | nonNullList: [], 12 | nonNullEnum: Enum$E.V1, 13 | ).toJson(), 14 | equals({ 15 | 'nonNull': false, 16 | 'nonNullList': [], 17 | 'nonNullEnum': 'V1', 18 | }), 19 | ); 20 | }); 21 | test('It should send value non-required non-null values if provided', () { 22 | expect( 23 | Variables$Query$Q( 24 | nonNull: false, 25 | nonNullWithDefault: true, 26 | nonNullList: [], 27 | nonNullListWithDefault: [null], 28 | nonNullEnum: Enum$E.V1, 29 | nonNullEnumWithDefault: Enum$E.V1, 30 | ).toJson(), 31 | equals({ 32 | 'nonNull': false, 33 | 'nonNullWithDefault': true, 34 | 'nonNullList': [], 35 | 'nonNullListWithDefault': [null], 36 | 'nonNullEnum': 'V1', 37 | 'nonNullEnumWithDefault': 'V1', 38 | }), 39 | ); 40 | }); 41 | test( 42 | 'It should send value non-required non-null values if provided on copy', 43 | () { 44 | expect( 45 | Variables$Query$Q( 46 | nonNull: false, 47 | nonNullList: [], 48 | nonNullEnum: Enum$E.V1, 49 | ) 50 | .copyWith( 51 | nonNullWithDefault: true, 52 | nonNullListWithDefault: [null], 53 | nonNullEnumWithDefault: Enum$E.V1, 54 | ) 55 | .toJson(), 56 | equals({ 57 | 'nonNull': false, 58 | 'nonNullWithDefault': true, 59 | 'nonNullList': [], 60 | 'nonNullListWithDefault': [null], 61 | 'nonNullEnum': 'V1', 62 | 'nonNullEnumWithDefault': 'V1', 63 | }), 64 | ); 65 | }); 66 | test( 67 | 'It should not send value non-required non-null values if null provided', 68 | () { 69 | expect( 70 | Variables$Query$Q( 71 | nonNull: false, 72 | nonNullWithDefault: null, 73 | nonNullList: [], 74 | nonNullListWithDefault: null, 75 | nonNullEnum: Enum$E.V1, 76 | nonNullEnumWithDefault: null, 77 | ).toJson(), 78 | equals({ 79 | 'nonNull': false, 80 | 'nonNullList': [], 81 | 'nonNullEnum': 'V1', 82 | }), 83 | ); 84 | }); 85 | test( 86 | 'It should not send value non-required non-null values if null provided (on copy)', 87 | () { 88 | expect( 89 | Variables$Query$Q( 90 | nonNull: false, 91 | nonNullList: [], 92 | nonNullEnum: Enum$E.V1, 93 | ) 94 | .copyWith( 95 | nonNullWithDefault: null, 96 | nonNullListWithDefault: null, 97 | nonNullEnumWithDefault: null, 98 | ) 99 | .toJson(), 100 | equals({ 101 | 'nonNull': false, 102 | 'nonNullList': [], 103 | 'nonNullEnum': 'V1', 104 | }), 105 | ); 106 | }); 107 | test('Equality should work', () { 108 | expect( 109 | Variables$Query$Q( 110 | nonNull: false, 111 | nonNullWithDefault: true, 112 | nonNullList: [], 113 | nonNullListWithDefault: [null], 114 | nonNullEnum: Enum$E.V1, 115 | nonNullEnumWithDefault: Enum$E.V1, 116 | ) == 117 | Variables$Query$Q( 118 | nonNull: false, 119 | nonNullWithDefault: true, 120 | nonNullList: [], 121 | nonNullListWithDefault: [null], 122 | nonNullEnum: Enum$E.V1, 123 | nonNullEnumWithDefault: Enum$E.V1, 124 | ), 125 | equals(true), 126 | ); 127 | 128 | expect( 129 | Variables$Query$Q( 130 | nonNull: false, 131 | nonNullWithDefault: true, 132 | nonNullList: [], 133 | nonNullListWithDefault: [null], 134 | nonNullEnum: Enum$E.V1, 135 | nonNullEnumWithDefault: Enum$E.V1, 136 | ).hashCode == 137 | Variables$Query$Q( 138 | nonNull: false, 139 | nonNullWithDefault: true, 140 | nonNullList: [], 141 | nonNullListWithDefault: [null], 142 | nonNullEnum: Enum$E.V1, 143 | nonNullEnumWithDefault: Enum$E.V1, 144 | ).hashCode, 145 | equals(true), 146 | ); 147 | }); 148 | }); 149 | } 150 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_293/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | field(arg: Boolean): Int 3 | inputField(arg: I): Int 4 | enumField(arg: E): Int 5 | listField(arg: [E]): Int 6 | } 7 | 8 | enum E { 9 | V1 10 | } 11 | 12 | input I { 13 | nonNull: Boolean! 14 | nonNullWithDefault: Boolean! = false 15 | nullable: Boolean 16 | nullableWithDefault: Boolean = false 17 | } 18 | 19 | query Q( 20 | $nonNull: Boolean! 21 | $nonNullWithDefault: Boolean! = false 22 | $nullable: Boolean 23 | $nullableWithDefault: Boolean = false 24 | $nonNullEnum: E! 25 | $nonNullEnumWithDefault: E! = false 26 | $nullableEnum: E 27 | $nullableEnumWithDefault: E = false 28 | $nonNullList: [E]! 29 | $nonNullListWithDefault: [E]! = false 30 | $nullableList: [E] 31 | $nullableListWithDefault: [E] = false 32 | $i: I 33 | ) { 34 | fNonNull: field(arg: $nonNull) 35 | fNonNullWithDefault: field(arg: $nonNullWithDefault) 36 | fNullable: field(arg: $nullable) 37 | fNullableWithDefault: field(arg: $nullableWithDefault) 38 | eNonNull: enumField(arg: $nonNullEnum) 39 | eNonNullWithDefault: enumField(arg: $nonNullEnumWithDefault) 40 | eNullable: enumField(arg: $nullableEnum) 41 | eNullableWithDefault: enumField(arg: $nullableEnumWithDefault) 42 | lNonNull: listField(arg: $nonNullList) 43 | lNonNullWithDefault: listField(arg: $nonNullListWithDefault) 44 | lNullable: listField(arg: $nullableList) 45 | lNullableWithDefault: listField(arg: $nullableListWithDefault) 46 | inputField(arg: $i) 47 | } 48 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_306/document.graphqls: -------------------------------------------------------------------------------- 1 | type Query { 2 | status: String 3 | } 4 | 5 | query Q { 6 | status 7 | } 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_309/document.graphql: -------------------------------------------------------------------------------- 1 | input TemplateDisciplineTopicContentInput { 2 | howStudyIt: String! 3 | infoContentBlocks: [I1!]! 4 | taskContentBlocks: [I2!] 5 | testContentBlocks: [I3!]! = [] 6 | whyStudyIt: String! 7 | } 8 | 9 | input I1 { 10 | data: String 11 | } 12 | 13 | input I2 { 14 | data: String 15 | } 16 | 17 | input I3 { 18 | data: String 19 | } 20 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_318/builder_options.json: -------------------------------------------------------------------------------- 1 | { 2 | "noFlatLib": true 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_318/graphql/query1/q.graphql: -------------------------------------------------------------------------------- 1 | query FetchHello { 2 | hello 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_318/graphql/query2/q.graphql: -------------------------------------------------------------------------------- 1 | query FetchHello { 2 | hello 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_318/graphql/schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | hello: String 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_318/lib/query1/q.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | 3 | class Query$FetchHello { 4 | Query$FetchHello({ 5 | this.hello, 6 | this.$__typename = 'Query', 7 | }); 8 | 9 | factory Query$FetchHello.fromJson(Map json) { 10 | final l$hello = json['hello']; 11 | final l$$__typename = json['__typename']; 12 | return Query$FetchHello( 13 | hello: (l$hello as String?), 14 | $__typename: (l$$__typename as String), 15 | ); 16 | } 17 | 18 | final String? hello; 19 | 20 | final String $__typename; 21 | 22 | Map toJson() { 23 | final _resultData = {}; 24 | final l$hello = hello; 25 | _resultData['hello'] = l$hello; 26 | final l$$__typename = $__typename; 27 | _resultData['__typename'] = l$$__typename; 28 | return _resultData; 29 | } 30 | 31 | @override 32 | int get hashCode { 33 | final l$hello = hello; 34 | final l$$__typename = $__typename; 35 | return Object.hashAll([ 36 | l$hello, 37 | l$$__typename, 38 | ]); 39 | } 40 | 41 | @override 42 | bool operator ==(Object other) { 43 | if (identical(this, other)) { 44 | return true; 45 | } 46 | if (other is! Query$FetchHello || runtimeType != other.runtimeType) { 47 | return false; 48 | } 49 | final l$hello = hello; 50 | final lOther$hello = other.hello; 51 | if (l$hello != lOther$hello) { 52 | return false; 53 | } 54 | final l$$__typename = $__typename; 55 | final lOther$$__typename = other.$__typename; 56 | if (l$$__typename != lOther$$__typename) { 57 | return false; 58 | } 59 | return true; 60 | } 61 | } 62 | 63 | extension UtilityExtension$Query$FetchHello on Query$FetchHello { 64 | CopyWith$Query$FetchHello get copyWith => 65 | CopyWith$Query$FetchHello( 66 | this, 67 | (i) => i, 68 | ); 69 | } 70 | 71 | abstract class CopyWith$Query$FetchHello { 72 | factory CopyWith$Query$FetchHello( 73 | Query$FetchHello instance, 74 | TRes Function(Query$FetchHello) then, 75 | ) = _CopyWithImpl$Query$FetchHello; 76 | 77 | factory CopyWith$Query$FetchHello.stub(TRes res) = 78 | _CopyWithStubImpl$Query$FetchHello; 79 | 80 | TRes call({ 81 | String? hello, 82 | String? $__typename, 83 | }); 84 | } 85 | 86 | class _CopyWithImpl$Query$FetchHello 87 | implements CopyWith$Query$FetchHello { 88 | _CopyWithImpl$Query$FetchHello( 89 | this._instance, 90 | this._then, 91 | ); 92 | 93 | final Query$FetchHello _instance; 94 | 95 | final TRes Function(Query$FetchHello) _then; 96 | 97 | static const _undefined = {}; 98 | 99 | TRes call({ 100 | Object? hello = _undefined, 101 | Object? $__typename = _undefined, 102 | }) => 103 | _then(Query$FetchHello( 104 | hello: hello == _undefined ? _instance.hello : (hello as String?), 105 | $__typename: $__typename == _undefined || $__typename == null 106 | ? _instance.$__typename 107 | : ($__typename as String), 108 | )); 109 | } 110 | 111 | class _CopyWithStubImpl$Query$FetchHello 112 | implements CopyWith$Query$FetchHello { 113 | _CopyWithStubImpl$Query$FetchHello(this._res); 114 | 115 | TRes _res; 116 | 117 | call({ 118 | String? hello, 119 | String? $__typename, 120 | }) => 121 | _res; 122 | } 123 | 124 | const documentNodeQueryFetchHello = DocumentNode(definitions: [ 125 | OperationDefinitionNode( 126 | type: OperationType.query, 127 | name: NameNode(value: 'FetchHello'), 128 | variableDefinitions: [], 129 | directives: [], 130 | selectionSet: SelectionSetNode(selections: [ 131 | FieldNode( 132 | name: NameNode(value: 'hello'), 133 | alias: null, 134 | arguments: [], 135 | directives: [], 136 | selectionSet: null, 137 | ), 138 | FieldNode( 139 | name: NameNode(value: '__typename'), 140 | alias: null, 141 | arguments: [], 142 | directives: [], 143 | selectionSet: null, 144 | ), 145 | ]), 146 | ), 147 | ]); 148 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_318/lib/query2/q.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | 3 | class Query$FetchHello { 4 | Query$FetchHello({ 5 | this.hello, 6 | this.$__typename = 'Query', 7 | }); 8 | 9 | factory Query$FetchHello.fromJson(Map json) { 10 | final l$hello = json['hello']; 11 | final l$$__typename = json['__typename']; 12 | return Query$FetchHello( 13 | hello: (l$hello as String?), 14 | $__typename: (l$$__typename as String), 15 | ); 16 | } 17 | 18 | final String? hello; 19 | 20 | final String $__typename; 21 | 22 | Map toJson() { 23 | final _resultData = {}; 24 | final l$hello = hello; 25 | _resultData['hello'] = l$hello; 26 | final l$$__typename = $__typename; 27 | _resultData['__typename'] = l$$__typename; 28 | return _resultData; 29 | } 30 | 31 | @override 32 | int get hashCode { 33 | final l$hello = hello; 34 | final l$$__typename = $__typename; 35 | return Object.hashAll([ 36 | l$hello, 37 | l$$__typename, 38 | ]); 39 | } 40 | 41 | @override 42 | bool operator ==(Object other) { 43 | if (identical(this, other)) { 44 | return true; 45 | } 46 | if (other is! Query$FetchHello || runtimeType != other.runtimeType) { 47 | return false; 48 | } 49 | final l$hello = hello; 50 | final lOther$hello = other.hello; 51 | if (l$hello != lOther$hello) { 52 | return false; 53 | } 54 | final l$$__typename = $__typename; 55 | final lOther$$__typename = other.$__typename; 56 | if (l$$__typename != lOther$$__typename) { 57 | return false; 58 | } 59 | return true; 60 | } 61 | } 62 | 63 | extension UtilityExtension$Query$FetchHello on Query$FetchHello { 64 | CopyWith$Query$FetchHello get copyWith => 65 | CopyWith$Query$FetchHello( 66 | this, 67 | (i) => i, 68 | ); 69 | } 70 | 71 | abstract class CopyWith$Query$FetchHello { 72 | factory CopyWith$Query$FetchHello( 73 | Query$FetchHello instance, 74 | TRes Function(Query$FetchHello) then, 75 | ) = _CopyWithImpl$Query$FetchHello; 76 | 77 | factory CopyWith$Query$FetchHello.stub(TRes res) = 78 | _CopyWithStubImpl$Query$FetchHello; 79 | 80 | TRes call({ 81 | String? hello, 82 | String? $__typename, 83 | }); 84 | } 85 | 86 | class _CopyWithImpl$Query$FetchHello 87 | implements CopyWith$Query$FetchHello { 88 | _CopyWithImpl$Query$FetchHello( 89 | this._instance, 90 | this._then, 91 | ); 92 | 93 | final Query$FetchHello _instance; 94 | 95 | final TRes Function(Query$FetchHello) _then; 96 | 97 | static const _undefined = {}; 98 | 99 | TRes call({ 100 | Object? hello = _undefined, 101 | Object? $__typename = _undefined, 102 | }) => 103 | _then(Query$FetchHello( 104 | hello: hello == _undefined ? _instance.hello : (hello as String?), 105 | $__typename: $__typename == _undefined || $__typename == null 106 | ? _instance.$__typename 107 | : ($__typename as String), 108 | )); 109 | } 110 | 111 | class _CopyWithStubImpl$Query$FetchHello 112 | implements CopyWith$Query$FetchHello { 113 | _CopyWithStubImpl$Query$FetchHello(this._res); 114 | 115 | TRes _res; 116 | 117 | call({ 118 | String? hello, 119 | String? $__typename, 120 | }) => 121 | _res; 122 | } 123 | 124 | const documentNodeQueryFetchHello = DocumentNode(definitions: [ 125 | OperationDefinitionNode( 126 | type: OperationType.query, 127 | name: NameNode(value: 'FetchHello'), 128 | variableDefinitions: [], 129 | directives: [], 130 | selectionSet: SelectionSetNode(selections: [ 131 | FieldNode( 132 | name: NameNode(value: 'hello'), 133 | alias: null, 134 | arguments: [], 135 | directives: [], 136 | selectionSet: null, 137 | ), 138 | FieldNode( 139 | name: NameNode(value: '__typename'), 140 | alias: null, 141 | arguments: [], 142 | directives: [], 143 | selectionSet: null, 144 | ), 145 | ]), 146 | ), 147 | ]); 148 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_318/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "outputDirectory": "/lib", 3 | "assetsPath": "graphql/**" 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_331/document.graphql: -------------------------------------------------------------------------------- 1 | # query.graphql 2 | type Query { 3 | } 4 | 5 | # (1) 6 | extend type Query { 7 | foo: FooResponse! 8 | } 9 | 10 | type FooResponse { 11 | foo: FooCore! 12 | } 13 | 14 | type FooCore { 15 | bar: String! 16 | } 17 | 18 | query FooQuery { 19 | foo { 20 | # (2) 21 | foo { 22 | # (3) 23 | bar 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_348/document.graphql: -------------------------------------------------------------------------------- 1 | scalar DateTime 2 | 3 | type Query { 4 | time: DateTime 5 | } 6 | 7 | query FetchScalars { 8 | time 9 | } 10 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_348/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "scalars": { 3 | "DateTime": { 4 | "type": "DateTime", 5 | "fromJsonFunctionName": "customDateTimeFromJson", 6 | "toJsonFunctionName": "customDateTimeToJson", 7 | "import": "scalar_import.dart" 8 | } 9 | }, 10 | "addTypename": false 11 | } 12 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_348/scalar_import.dart: -------------------------------------------------------------------------------- 1 | DateTime? customDateTimeFromJson(dynamic dynamic) => 2 | dynamic is String ? DateTime.parse(dynamic) : null; 3 | 4 | dynamic customDateTimeToJson(DateTime date) => date.toIso8601String(); 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_370/document.graphql: -------------------------------------------------------------------------------- 1 | type Media { 2 | id: ID 3 | type: String 4 | title: MediaTitle 5 | coverImage: MediaCoverImage 6 | nextEpisode: Int 7 | } 8 | 9 | type MediaTitle { 10 | romaji: String 11 | userPreferred: String 12 | } 13 | 14 | type MediaCoverImage { 15 | large: String 16 | medium: String 17 | } 18 | 19 | type Query { 20 | Media(id: Int, search: String): Media 21 | } 22 | 23 | 24 | fragment MediaMinimalFrag on Media { 25 | id 26 | type 27 | title { 28 | romaji 29 | userPreferred 30 | } 31 | coverImage { 32 | large 33 | medium 34 | } 35 | } 36 | 37 | query MediaMinimal($id: Int, $search: String) { 38 | Media(id: $id, search: $search) { 39 | ...MediaMinimalFrag 40 | } 41 | } 42 | 43 | query MediaFull($id: Int, $search: String) { 44 | Media(id: $id, search: $search) { 45 | ...MediaMinimalFrag 46 | nextEpisode 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_370/test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | // ignore: depend_on_referenced_packages 4 | import 'package:http/http.dart' as http; 5 | 6 | import 'package:gql/language.dart'; 7 | 8 | import 'document.graphql.dart'; 9 | 10 | main() async { 11 | final url = Uri( 12 | scheme: 'http', 13 | host: 'localhost', 14 | port: 8080, 15 | path: '/graphql', 16 | ); 17 | final response = await http.post(url, body: { 18 | 'query': printNode(documentNodeQueryMediaMinimal), 19 | 'variables': Variables$Query$MediaMinimal(id: 1).toJson(), 20 | }); 21 | final responseJson = json.decode(response.body); 22 | return Query$MediaMinimal.fromJson( 23 | responseJson['data'] as Map, 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_388/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "allowMissingNullableKeysInFromJson": true 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/issue_388/schema.graphql: -------------------------------------------------------------------------------- 1 | scalar LocalDateTime 2 | scalar ResourceModification 3 | 4 | type ResourceItem { 5 | createdAt: LocalDateTime 6 | deletedAt: LocalDateTime 7 | description: String 8 | erpId: String 9 | garageNumber: String 10 | id: ID! 11 | inventoryNumber: String 12 | modification: ResourceModification 13 | registrationNumber: String 14 | updatedAt: LocalDateTime 15 | vin: String 16 | } 17 | 18 | fragment CarFragment on ResourceItem { 19 | createdAt 20 | description 21 | erpId 22 | garageNumber 23 | id 24 | inventoryNumber 25 | modification { 26 | name 27 | } 28 | registrationNumber 29 | updatedAt 30 | vin 31 | } 32 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/json_converters/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | mFloat: Float 4 | float: Float! 5 | int: Int! 6 | mInt: Int 7 | dt: DT! 8 | mDt: DT 9 | } 10 | 11 | query Q { 12 | mFloat float int mInt dt mDt 13 | } 14 | 15 | scalar DT -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/json_converters/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "scalars": { 3 | "DT": { 4 | "type": "DateTime" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/lots_of_fragments/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | field: IField 3 | } 4 | 5 | interface IField { 6 | name: String 7 | field: IField 8 | } 9 | 10 | type FieldA implements IField { 11 | name: String 12 | value: String 13 | field: IField 14 | } 15 | 16 | fragment FragmentA on FieldA { 17 | __typename 18 | value 19 | ...FragmentI 20 | } 21 | 22 | fragment FragmentI on IField { 23 | __typename 24 | name 25 | } 26 | 27 | query FetchStuff { 28 | __typename 29 | field { 30 | __typename 31 | name 32 | ...FragmentA 33 | ...on FieldA { 34 | __typename 35 | value 36 | ...on IField { 37 | __typename 38 | name 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/lots_of_fragments/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/multiple_interfaces/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | interface I3 { 3 | value: Float 4 | } 5 | 6 | interface I1 { 7 | name: String 8 | } 9 | 10 | interface I2 { 11 | size: Int 12 | } 13 | 14 | type T1 implements I1 & I2 { 15 | name: String 16 | size: Int 17 | } 18 | 19 | type Query { 20 | field: I1 21 | } 22 | 23 | fragment F0 on I1 { 24 | name01: name 25 | } 26 | 27 | fragment F1 on I2 { 28 | size2: size 29 | } 30 | fragment F2 on T1 { 31 | name2: name 32 | } 33 | 34 | fragment F3 on I3 { 35 | value 36 | } 37 | 38 | query Q { 39 | field { 40 | __typename 41 | ...on I1 { 42 | name0: name 43 | } 44 | ...F0 45 | ...on I2 { 46 | size 47 | } 48 | ...on T1 { 49 | name 50 | } 51 | ... on I3 { 52 | value 53 | } 54 | ...F1 55 | ...F2 56 | ...F3 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/multiple_interfaces/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/naming_config/document.graphql: -------------------------------------------------------------------------------- 1 | enum Status { 2 | Pending 3 | Successful 4 | Failure 5 | InProgress 6 | } 7 | 8 | type Query { 9 | status: Status 10 | } 11 | 12 | 13 | query Q { 14 | status 15 | } 16 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/naming_config/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "namingSeparator": "___" 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/nested_inline_and_fragment_spread/document.graphql: -------------------------------------------------------------------------------- 1 | type T { 2 | t: T 3 | } 4 | 5 | fragment F on T { 6 | t { 7 | t { 8 | __typename 9 | } 10 | } 11 | } 12 | 13 | type Query { 14 | t: T 15 | } 16 | 17 | 18 | query Q { 19 | t { 20 | t { 21 | t { 22 | t { 23 | __typename 24 | } 25 | } 26 | ...F 27 | } 28 | ...F 29 | } 30 | } 31 | 32 | 33 | query Q2 { 34 | t { 35 | ...F 36 | t { 37 | ...F 38 | t { 39 | t { 40 | __typename 41 | } 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/nested_inline_and_fragment_spread/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/operation_name_collision/mutation.graphql: -------------------------------------------------------------------------------- 1 | 2 | mutation Operation { 3 | setName(name: "Bob") { 4 | name 5 | } 6 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/operation_name_collision/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "clients": [ 3 | "graphql", 4 | "graphql_flutter" 5 | ], 6 | "addTypename": false 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/operation_name_collision/query.graphql: -------------------------------------------------------------------------------- 1 | 2 | query Operation { 3 | name 4 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/operation_name_collision/schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | name: String 3 | } 4 | type Mutation { 5 | setName(name: String!): Query 6 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/output_directory/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | name: String 4 | } 5 | 6 | query Q { 7 | name 8 | } 9 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/output_directory/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "outputDirectory": "__generated/folder" 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/output_directory_2/f1/schema.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | name: E 4 | } 5 | 6 | 7 | enum E { 8 | ONE TWO THREE 9 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/output_directory_2/f2/__generated__/document.graphql.dart: -------------------------------------------------------------------------------- 1 | import '../../f1/__generated__/schema.graphql.dart'; 2 | import 'package:gql/ast.dart'; 3 | 4 | class Query$Q { 5 | Query$Q({ 6 | this.name, 7 | this.$__typename = 'Query', 8 | }); 9 | 10 | factory Query$Q.fromJson(Map json) { 11 | final l$name = json['name']; 12 | final l$$__typename = json['__typename']; 13 | return Query$Q( 14 | name: l$name == null ? null : fromJson$Enum$E((l$name as String)), 15 | $__typename: (l$$__typename as String), 16 | ); 17 | } 18 | 19 | final Enum$E? name; 20 | 21 | final String $__typename; 22 | 23 | Map toJson() { 24 | final _resultData = {}; 25 | final l$name = name; 26 | _resultData['name'] = l$name == null ? null : toJson$Enum$E(l$name); 27 | final l$$__typename = $__typename; 28 | _resultData['__typename'] = l$$__typename; 29 | return _resultData; 30 | } 31 | 32 | @override 33 | int get hashCode { 34 | final l$name = name; 35 | final l$$__typename = $__typename; 36 | return Object.hashAll([ 37 | l$name, 38 | l$$__typename, 39 | ]); 40 | } 41 | 42 | @override 43 | bool operator ==(Object other) { 44 | if (identical(this, other)) { 45 | return true; 46 | } 47 | if (other is! Query$Q || runtimeType != other.runtimeType) { 48 | return false; 49 | } 50 | final l$name = name; 51 | final lOther$name = other.name; 52 | if (l$name != lOther$name) { 53 | return false; 54 | } 55 | final l$$__typename = $__typename; 56 | final lOther$$__typename = other.$__typename; 57 | if (l$$__typename != lOther$$__typename) { 58 | return false; 59 | } 60 | return true; 61 | } 62 | } 63 | 64 | extension UtilityExtension$Query$Q on Query$Q { 65 | CopyWith$Query$Q get copyWith => CopyWith$Query$Q( 66 | this, 67 | (i) => i, 68 | ); 69 | } 70 | 71 | abstract class CopyWith$Query$Q { 72 | factory CopyWith$Query$Q( 73 | Query$Q instance, 74 | TRes Function(Query$Q) then, 75 | ) = _CopyWithImpl$Query$Q; 76 | 77 | factory CopyWith$Query$Q.stub(TRes res) = _CopyWithStubImpl$Query$Q; 78 | 79 | TRes call({ 80 | Enum$E? name, 81 | String? $__typename, 82 | }); 83 | } 84 | 85 | class _CopyWithImpl$Query$Q implements CopyWith$Query$Q { 86 | _CopyWithImpl$Query$Q( 87 | this._instance, 88 | this._then, 89 | ); 90 | 91 | final Query$Q _instance; 92 | 93 | final TRes Function(Query$Q) _then; 94 | 95 | static const _undefined = {}; 96 | 97 | TRes call({ 98 | Object? name = _undefined, 99 | Object? $__typename = _undefined, 100 | }) => 101 | _then(Query$Q( 102 | name: name == _undefined ? _instance.name : (name as Enum$E?), 103 | $__typename: $__typename == _undefined || $__typename == null 104 | ? _instance.$__typename 105 | : ($__typename as String), 106 | )); 107 | } 108 | 109 | class _CopyWithStubImpl$Query$Q implements CopyWith$Query$Q { 110 | _CopyWithStubImpl$Query$Q(this._res); 111 | 112 | TRes _res; 113 | 114 | call({ 115 | Enum$E? name, 116 | String? $__typename, 117 | }) => 118 | _res; 119 | } 120 | 121 | const documentNodeQueryQ = DocumentNode(definitions: [ 122 | OperationDefinitionNode( 123 | type: OperationType.query, 124 | name: NameNode(value: 'Q'), 125 | variableDefinitions: [], 126 | directives: [], 127 | selectionSet: SelectionSetNode(selections: [ 128 | FieldNode( 129 | name: NameNode(value: 'name'), 130 | alias: null, 131 | arguments: [], 132 | directives: [], 133 | selectionSet: null, 134 | ), 135 | FieldNode( 136 | name: NameNode(value: '__typename'), 137 | alias: null, 138 | arguments: [], 139 | directives: [], 140 | selectionSet: null, 141 | ), 142 | ]), 143 | ), 144 | ]); 145 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/output_directory_2/f2/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | query Q { 3 | name 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/output_directory_2/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "outputDirectory": "__generated__" 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/possible_types_map/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/possible_types_map/schema.graphql: -------------------------------------------------------------------------------- 1 | union UnionA = InterfaceA | TypeC | TypeA 2 | 3 | union UnionB = UnionA | TypeD 4 | 5 | interface InterfaceA { 6 | name: String 7 | } 8 | 9 | type TypeA implements InterfaceA { 10 | name: String 11 | } 12 | 13 | type TypeC { 14 | age: Int 15 | } 16 | 17 | type TypeB implements InterfaceA { 18 | name: String 19 | } 20 | 21 | type TypeD { 22 | fancy: Boolean 23 | } 24 | 25 | type Query { 26 | union: UnionA 27 | } 28 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/private_enum_literals/schema.graphql: -------------------------------------------------------------------------------- 1 | enum CustomEnum { 2 | nonPrivateLiteral 3 | _privateLiteral 4 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/query_with_single_fragment/document.graphql: -------------------------------------------------------------------------------- 1 | query Q { 2 | ...F 3 | } 4 | 5 | fragment F on Query { 6 | name 7 | } 8 | 9 | 10 | type Query { 11 | name: String 12 | } 13 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_in_lib_output/builder_options.json: -------------------------------------------------------------------------------- 1 | { 2 | "noFlatLib": true 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_in_lib_output/lib/__generated__/fragments/document.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | 3 | class Fragment$F { 4 | Fragment$F({ 5 | this.name, 6 | this.$__typename = 'Query', 7 | }); 8 | 9 | factory Fragment$F.fromJson(Map json) { 10 | final l$name = json['name']; 11 | final l$$__typename = json['__typename']; 12 | return Fragment$F( 13 | name: (l$name as String?), 14 | $__typename: (l$$__typename as String), 15 | ); 16 | } 17 | 18 | final String? name; 19 | 20 | final String $__typename; 21 | 22 | Map toJson() { 23 | final _resultData = {}; 24 | final l$name = name; 25 | _resultData['name'] = l$name; 26 | final l$$__typename = $__typename; 27 | _resultData['__typename'] = l$$__typename; 28 | return _resultData; 29 | } 30 | 31 | @override 32 | int get hashCode { 33 | final l$name = name; 34 | final l$$__typename = $__typename; 35 | return Object.hashAll([ 36 | l$name, 37 | l$$__typename, 38 | ]); 39 | } 40 | 41 | @override 42 | bool operator ==(Object other) { 43 | if (identical(this, other)) { 44 | return true; 45 | } 46 | if (other is! Fragment$F || runtimeType != other.runtimeType) { 47 | return false; 48 | } 49 | final l$name = name; 50 | final lOther$name = other.name; 51 | if (l$name != lOther$name) { 52 | return false; 53 | } 54 | final l$$__typename = $__typename; 55 | final lOther$$__typename = other.$__typename; 56 | if (l$$__typename != lOther$$__typename) { 57 | return false; 58 | } 59 | return true; 60 | } 61 | } 62 | 63 | extension UtilityExtension$Fragment$F on Fragment$F { 64 | CopyWith$Fragment$F get copyWith => CopyWith$Fragment$F( 65 | this, 66 | (i) => i, 67 | ); 68 | } 69 | 70 | abstract class CopyWith$Fragment$F { 71 | factory CopyWith$Fragment$F( 72 | Fragment$F instance, 73 | TRes Function(Fragment$F) then, 74 | ) = _CopyWithImpl$Fragment$F; 75 | 76 | factory CopyWith$Fragment$F.stub(TRes res) = _CopyWithStubImpl$Fragment$F; 77 | 78 | TRes call({ 79 | String? name, 80 | String? $__typename, 81 | }); 82 | } 83 | 84 | class _CopyWithImpl$Fragment$F implements CopyWith$Fragment$F { 85 | _CopyWithImpl$Fragment$F( 86 | this._instance, 87 | this._then, 88 | ); 89 | 90 | final Fragment$F _instance; 91 | 92 | final TRes Function(Fragment$F) _then; 93 | 94 | static const _undefined = {}; 95 | 96 | TRes call({ 97 | Object? name = _undefined, 98 | Object? $__typename = _undefined, 99 | }) => 100 | _then(Fragment$F( 101 | name: name == _undefined ? _instance.name : (name as String?), 102 | $__typename: $__typename == _undefined || $__typename == null 103 | ? _instance.$__typename 104 | : ($__typename as String), 105 | )); 106 | } 107 | 108 | class _CopyWithStubImpl$Fragment$F implements CopyWith$Fragment$F { 109 | _CopyWithStubImpl$Fragment$F(this._res); 110 | 111 | TRes _res; 112 | 113 | call({ 114 | String? name, 115 | String? $__typename, 116 | }) => 117 | _res; 118 | } 119 | 120 | const fragmentDefinitionF = FragmentDefinitionNode( 121 | name: NameNode(value: 'F'), 122 | typeCondition: TypeConditionNode( 123 | on: NamedTypeNode( 124 | name: NameNode(value: 'Query'), 125 | isNonNull: false, 126 | )), 127 | directives: [], 128 | selectionSet: SelectionSetNode(selections: [ 129 | FieldNode( 130 | name: NameNode(value: 'name'), 131 | alias: null, 132 | arguments: [], 133 | directives: [], 134 | selectionSet: null, 135 | ), 136 | FieldNode( 137 | name: NameNode(value: '__typename'), 138 | alias: null, 139 | arguments: [], 140 | directives: [], 141 | selectionSet: null, 142 | ), 143 | ]), 144 | ); 145 | const documentNodeFragmentF = DocumentNode(definitions: [ 146 | fragmentDefinitionF, 147 | ]); 148 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_in_lib_output/lib/__generated__/queries/document.graphql.dart: -------------------------------------------------------------------------------- 1 | import '../fragments/document.graphql.dart'; 2 | import 'package:gql/ast.dart'; 3 | 4 | class Query$Q implements Fragment$F { 5 | Query$Q({ 6 | this.name, 7 | this.$__typename = 'Query', 8 | }); 9 | 10 | factory Query$Q.fromJson(Map json) { 11 | final l$name = json['name']; 12 | final l$$__typename = json['__typename']; 13 | return Query$Q( 14 | name: (l$name as String?), 15 | $__typename: (l$$__typename as String), 16 | ); 17 | } 18 | 19 | final String? name; 20 | 21 | final String $__typename; 22 | 23 | Map toJson() { 24 | final _resultData = {}; 25 | final l$name = name; 26 | _resultData['name'] = l$name; 27 | final l$$__typename = $__typename; 28 | _resultData['__typename'] = l$$__typename; 29 | return _resultData; 30 | } 31 | 32 | @override 33 | int get hashCode { 34 | final l$name = name; 35 | final l$$__typename = $__typename; 36 | return Object.hashAll([ 37 | l$name, 38 | l$$__typename, 39 | ]); 40 | } 41 | 42 | @override 43 | bool operator ==(Object other) { 44 | if (identical(this, other)) { 45 | return true; 46 | } 47 | if (other is! Query$Q || runtimeType != other.runtimeType) { 48 | return false; 49 | } 50 | final l$name = name; 51 | final lOther$name = other.name; 52 | if (l$name != lOther$name) { 53 | return false; 54 | } 55 | final l$$__typename = $__typename; 56 | final lOther$$__typename = other.$__typename; 57 | if (l$$__typename != lOther$$__typename) { 58 | return false; 59 | } 60 | return true; 61 | } 62 | } 63 | 64 | extension UtilityExtension$Query$Q on Query$Q { 65 | CopyWith$Query$Q get copyWith => CopyWith$Query$Q( 66 | this, 67 | (i) => i, 68 | ); 69 | } 70 | 71 | abstract class CopyWith$Query$Q { 72 | factory CopyWith$Query$Q( 73 | Query$Q instance, 74 | TRes Function(Query$Q) then, 75 | ) = _CopyWithImpl$Query$Q; 76 | 77 | factory CopyWith$Query$Q.stub(TRes res) = _CopyWithStubImpl$Query$Q; 78 | 79 | TRes call({ 80 | String? name, 81 | String? $__typename, 82 | }); 83 | } 84 | 85 | class _CopyWithImpl$Query$Q implements CopyWith$Query$Q { 86 | _CopyWithImpl$Query$Q( 87 | this._instance, 88 | this._then, 89 | ); 90 | 91 | final Query$Q _instance; 92 | 93 | final TRes Function(Query$Q) _then; 94 | 95 | static const _undefined = {}; 96 | 97 | TRes call({ 98 | Object? name = _undefined, 99 | Object? $__typename = _undefined, 100 | }) => 101 | _then(Query$Q( 102 | name: name == _undefined ? _instance.name : (name as String?), 103 | $__typename: $__typename == _undefined || $__typename == null 104 | ? _instance.$__typename 105 | : ($__typename as String), 106 | )); 107 | } 108 | 109 | class _CopyWithStubImpl$Query$Q implements CopyWith$Query$Q { 110 | _CopyWithStubImpl$Query$Q(this._res); 111 | 112 | TRes _res; 113 | 114 | call({ 115 | String? name, 116 | String? $__typename, 117 | }) => 118 | _res; 119 | } 120 | 121 | const documentNodeQueryQ = DocumentNode(definitions: [ 122 | OperationDefinitionNode( 123 | type: OperationType.query, 124 | name: NameNode(value: 'Q'), 125 | variableDefinitions: [], 126 | directives: [], 127 | selectionSet: SelectionSetNode(selections: [ 128 | FragmentSpreadNode( 129 | name: NameNode(value: 'F'), 130 | directives: [], 131 | ), 132 | FieldNode( 133 | name: NameNode(value: '__typename'), 134 | alias: null, 135 | arguments: [], 136 | directives: [], 137 | selectionSet: null, 138 | ), 139 | ]), 140 | ), 141 | fragmentDefinitionF, 142 | ]); 143 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_in_lib_output/lib/fragments/document.graphql: -------------------------------------------------------------------------------- 1 | fragment F on Query { 2 | name 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_in_lib_output/lib/queries/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | query Q { 3 | ...F 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_in_lib_output/lib/schema/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | name: String 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_in_lib_output/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "outputDirectory": "/lib/__generated__" 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_output/builder_options.json: -------------------------------------------------------------------------------- 1 | { 2 | "noFlatLib": true 3 | } 4 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_output/graphql/fragments/document.graphql: -------------------------------------------------------------------------------- 1 | fragment F on Query { 2 | name 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_output/graphql/queries/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | query Q { 3 | ...F 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_output/graphql/schema/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Query { 3 | name: String 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_output/lib/__generated__/fragments/document.graphql.dart: -------------------------------------------------------------------------------- 1 | import 'package:gql/ast.dart'; 2 | 3 | class Fragment$F { 4 | Fragment$F({ 5 | this.name, 6 | this.$__typename = 'Query', 7 | }); 8 | 9 | factory Fragment$F.fromJson(Map json) { 10 | final l$name = json['name']; 11 | final l$$__typename = json['__typename']; 12 | return Fragment$F( 13 | name: (l$name as String?), 14 | $__typename: (l$$__typename as String), 15 | ); 16 | } 17 | 18 | final String? name; 19 | 20 | final String $__typename; 21 | 22 | Map toJson() { 23 | final _resultData = {}; 24 | final l$name = name; 25 | _resultData['name'] = l$name; 26 | final l$$__typename = $__typename; 27 | _resultData['__typename'] = l$$__typename; 28 | return _resultData; 29 | } 30 | 31 | @override 32 | int get hashCode { 33 | final l$name = name; 34 | final l$$__typename = $__typename; 35 | return Object.hashAll([ 36 | l$name, 37 | l$$__typename, 38 | ]); 39 | } 40 | 41 | @override 42 | bool operator ==(Object other) { 43 | if (identical(this, other)) { 44 | return true; 45 | } 46 | if (other is! Fragment$F || runtimeType != other.runtimeType) { 47 | return false; 48 | } 49 | final l$name = name; 50 | final lOther$name = other.name; 51 | if (l$name != lOther$name) { 52 | return false; 53 | } 54 | final l$$__typename = $__typename; 55 | final lOther$$__typename = other.$__typename; 56 | if (l$$__typename != lOther$$__typename) { 57 | return false; 58 | } 59 | return true; 60 | } 61 | } 62 | 63 | extension UtilityExtension$Fragment$F on Fragment$F { 64 | CopyWith$Fragment$F get copyWith => CopyWith$Fragment$F( 65 | this, 66 | (i) => i, 67 | ); 68 | } 69 | 70 | abstract class CopyWith$Fragment$F { 71 | factory CopyWith$Fragment$F( 72 | Fragment$F instance, 73 | TRes Function(Fragment$F) then, 74 | ) = _CopyWithImpl$Fragment$F; 75 | 76 | factory CopyWith$Fragment$F.stub(TRes res) = _CopyWithStubImpl$Fragment$F; 77 | 78 | TRes call({ 79 | String? name, 80 | String? $__typename, 81 | }); 82 | } 83 | 84 | class _CopyWithImpl$Fragment$F implements CopyWith$Fragment$F { 85 | _CopyWithImpl$Fragment$F( 86 | this._instance, 87 | this._then, 88 | ); 89 | 90 | final Fragment$F _instance; 91 | 92 | final TRes Function(Fragment$F) _then; 93 | 94 | static const _undefined = {}; 95 | 96 | TRes call({ 97 | Object? name = _undefined, 98 | Object? $__typename = _undefined, 99 | }) => 100 | _then(Fragment$F( 101 | name: name == _undefined ? _instance.name : (name as String?), 102 | $__typename: $__typename == _undefined || $__typename == null 103 | ? _instance.$__typename 104 | : ($__typename as String), 105 | )); 106 | } 107 | 108 | class _CopyWithStubImpl$Fragment$F implements CopyWith$Fragment$F { 109 | _CopyWithStubImpl$Fragment$F(this._res); 110 | 111 | TRes _res; 112 | 113 | call({ 114 | String? name, 115 | String? $__typename, 116 | }) => 117 | _res; 118 | } 119 | 120 | const fragmentDefinitionF = FragmentDefinitionNode( 121 | name: NameNode(value: 'F'), 122 | typeCondition: TypeConditionNode( 123 | on: NamedTypeNode( 124 | name: NameNode(value: 'Query'), 125 | isNonNull: false, 126 | )), 127 | directives: [], 128 | selectionSet: SelectionSetNode(selections: [ 129 | FieldNode( 130 | name: NameNode(value: 'name'), 131 | alias: null, 132 | arguments: [], 133 | directives: [], 134 | selectionSet: null, 135 | ), 136 | FieldNode( 137 | name: NameNode(value: '__typename'), 138 | alias: null, 139 | arguments: [], 140 | directives: [], 141 | selectionSet: null, 142 | ), 143 | ]), 144 | ); 145 | const documentNodeFragmentF = DocumentNode(definitions: [ 146 | fragmentDefinitionF, 147 | ]); 148 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_output/lib/__generated__/queries/document.graphql.dart: -------------------------------------------------------------------------------- 1 | import '../fragments/document.graphql.dart'; 2 | import 'package:gql/ast.dart'; 3 | 4 | class Query$Q implements Fragment$F { 5 | Query$Q({ 6 | this.name, 7 | this.$__typename = 'Query', 8 | }); 9 | 10 | factory Query$Q.fromJson(Map json) { 11 | final l$name = json['name']; 12 | final l$$__typename = json['__typename']; 13 | return Query$Q( 14 | name: (l$name as String?), 15 | $__typename: (l$$__typename as String), 16 | ); 17 | } 18 | 19 | final String? name; 20 | 21 | final String $__typename; 22 | 23 | Map toJson() { 24 | final _resultData = {}; 25 | final l$name = name; 26 | _resultData['name'] = l$name; 27 | final l$$__typename = $__typename; 28 | _resultData['__typename'] = l$$__typename; 29 | return _resultData; 30 | } 31 | 32 | @override 33 | int get hashCode { 34 | final l$name = name; 35 | final l$$__typename = $__typename; 36 | return Object.hashAll([ 37 | l$name, 38 | l$$__typename, 39 | ]); 40 | } 41 | 42 | @override 43 | bool operator ==(Object other) { 44 | if (identical(this, other)) { 45 | return true; 46 | } 47 | if (other is! Query$Q || runtimeType != other.runtimeType) { 48 | return false; 49 | } 50 | final l$name = name; 51 | final lOther$name = other.name; 52 | if (l$name != lOther$name) { 53 | return false; 54 | } 55 | final l$$__typename = $__typename; 56 | final lOther$$__typename = other.$__typename; 57 | if (l$$__typename != lOther$$__typename) { 58 | return false; 59 | } 60 | return true; 61 | } 62 | } 63 | 64 | extension UtilityExtension$Query$Q on Query$Q { 65 | CopyWith$Query$Q get copyWith => CopyWith$Query$Q( 66 | this, 67 | (i) => i, 68 | ); 69 | } 70 | 71 | abstract class CopyWith$Query$Q { 72 | factory CopyWith$Query$Q( 73 | Query$Q instance, 74 | TRes Function(Query$Q) then, 75 | ) = _CopyWithImpl$Query$Q; 76 | 77 | factory CopyWith$Query$Q.stub(TRes res) = _CopyWithStubImpl$Query$Q; 78 | 79 | TRes call({ 80 | String? name, 81 | String? $__typename, 82 | }); 83 | } 84 | 85 | class _CopyWithImpl$Query$Q implements CopyWith$Query$Q { 86 | _CopyWithImpl$Query$Q( 87 | this._instance, 88 | this._then, 89 | ); 90 | 91 | final Query$Q _instance; 92 | 93 | final TRes Function(Query$Q) _then; 94 | 95 | static const _undefined = {}; 96 | 97 | TRes call({ 98 | Object? name = _undefined, 99 | Object? $__typename = _undefined, 100 | }) => 101 | _then(Query$Q( 102 | name: name == _undefined ? _instance.name : (name as String?), 103 | $__typename: $__typename == _undefined || $__typename == null 104 | ? _instance.$__typename 105 | : ($__typename as String), 106 | )); 107 | } 108 | 109 | class _CopyWithStubImpl$Query$Q implements CopyWith$Query$Q { 110 | _CopyWithStubImpl$Query$Q(this._res); 111 | 112 | TRes _res; 113 | 114 | call({ 115 | String? name, 116 | String? $__typename, 117 | }) => 118 | _res; 119 | } 120 | 121 | const documentNodeQueryQ = DocumentNode(definitions: [ 122 | OperationDefinitionNode( 123 | type: OperationType.query, 124 | name: NameNode(value: 'Q'), 125 | variableDefinitions: [], 126 | directives: [], 127 | selectionSet: SelectionSetNode(selections: [ 128 | FragmentSpreadNode( 129 | name: NameNode(value: 'F'), 130 | directives: [], 131 | ), 132 | FieldNode( 133 | name: NameNode(value: '__typename'), 134 | alias: null, 135 | arguments: [], 136 | directives: [], 137 | selectionSet: null, 138 | ), 139 | ]), 140 | ), 141 | fragmentDefinitionF, 142 | ]); 143 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/root_relative_output/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "outputDirectory": "/lib/__generated__", 3 | "assetsPath": "graphql/**.graphql" 4 | } 5 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scalars/document.graphql: -------------------------------------------------------------------------------- 1 | scalar Custom1 2 | 3 | scalar Custom2 4 | 5 | scalar Custom3 6 | 7 | type Query { 8 | i: Int 9 | id: ID 10 | s: String 11 | c1: Custom1 12 | c2: Custom2 13 | c3: Custom3 14 | c3s: [Custom3] 15 | } 16 | 17 | query FetchScalars { 18 | i 19 | id 20 | s 21 | c1 22 | c2 23 | c3 24 | c3s 25 | } 26 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scalars/fobbob.dart: -------------------------------------------------------------------------------- 1 | class Fobbob {} 2 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scalars/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "scalars": { 3 | "ID": { 4 | "type": "int" 5 | }, 6 | "Custom1": { 7 | "type": "String" 8 | }, 9 | "Custom2": { 10 | "type": "DateTime" 11 | }, 12 | "Custom3": { 13 | "type": "Fobbob", 14 | "fromJsonFunctionName": "fobbobFromJson", 15 | "toJsonFunctionName": "fobbobToJson", 16 | "import": "scalar_import.dart" 17 | } 18 | }, 19 | "addTypename": false 20 | } 21 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scalars/scalar_import.dart: -------------------------------------------------------------------------------- 1 | import 'fobbob.dart'; 2 | 3 | export 'fobbob.dart' show Fobbob; 4 | 5 | Fobbob? fobbobFromJson(dynamic) => Fobbob(); 6 | 7 | dynamic fobbobToJson(Fobbob bob) => 1337; 8 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scopes/a.query.graphql: -------------------------------------------------------------------------------- 1 | query FetchPerson { 2 | fetchPerson { 3 | name 4 | status 5 | } 6 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scopes/a.schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | fetchPerson: Person 3 | } 4 | 5 | type Person { 6 | name: String 7 | status: Status! 8 | } 9 | 10 | enum Status { 11 | COOL BEANS 12 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scopes/b.query.graphql: -------------------------------------------------------------------------------- 1 | query FetchPerson { 2 | fetchPerson { 3 | age 4 | name 5 | status 6 | } 7 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scopes/b.schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | fetchPerson: Personz 3 | } 4 | 5 | type Personz { 6 | name: String 7 | age: Int 8 | status: Status 9 | } 10 | 11 | enum Status { 12 | COOL SMEANS 13 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/scopes/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "scopes": [ 3 | "**/a.*.graphql", 4 | "**/b.*.graphql" 5 | ] 6 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/string_input_bug/document.graphql: -------------------------------------------------------------------------------- 1 | 2 | input I { 3 | String: String 4 | OtherReservedKeyword: Int 5 | } 6 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/string_input_bug/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "extraKeywords": ["String", "OtherReservedKeyword"] 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/unions/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | u: U 3 | } 4 | 5 | union U = TA | TB 6 | 7 | type TA { 8 | name: String 9 | } 10 | 11 | type TB { 12 | velocity: Int 13 | } 14 | 15 | query Q { 16 | u { 17 | __typename 18 | ...on TA { 19 | name 20 | } 21 | ...on TB { 22 | velocity 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/unions/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/unions_and_interfaces/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/unions_and_interfaces/schema.graphql: -------------------------------------------------------------------------------- 1 | 2 | union UA = T1 | T2 3 | 4 | union UB = T3 5 | 6 | interface IA { 7 | 8 | } 9 | 10 | interface IB { 11 | 12 | } 13 | 14 | type T1 implements IA & IB { 15 | 16 | } 17 | 18 | type T2 implements IA & IA { 19 | 20 | } 21 | 22 | type T3 { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/unions_and_interfaces/schema.graphql.dart: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/unions_and_interfaces/schema2.graphql: -------------------------------------------------------------------------------- 1 | 2 | type Mutation {} 3 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/variables/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "addTypename": false 3 | } -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/variables/schema.graphql: -------------------------------------------------------------------------------- 1 | input I1 { 2 | s: String! 3 | nested: I1 4 | } 5 | 6 | type Query { 7 | field(input: I1 b: Boolean!): T 8 | } 9 | 10 | type T { 11 | value: String! 12 | } 13 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/variables/variables.graphql: -------------------------------------------------------------------------------- 1 | 2 | query HiBob($i: I1!) { 3 | field(input: $i b: true) { 4 | value 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/when_extensions/document.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | u: U 3 | } 4 | 5 | union U = TA | TB 6 | 7 | type TA { 8 | name: String 9 | } 10 | 11 | type TB { 12 | velocity: Int 13 | } 14 | 15 | query Query { 16 | u { 17 | typename: __typename 18 | ... on TA { 19 | name 20 | } 21 | ... on TB { 22 | velocity 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/assets/when_extensions/when_extensions_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/expect.dart'; 2 | import 'package:test/scaffolding.dart'; 3 | 4 | import 'document.graphql.dart'; 5 | 6 | void main() { 7 | final tA = Query$Query(u: Query$Query$u$$TA(name: 'name')).u!; 8 | final tB = Query$Query(u: Query$Query$u$$TB(velocity: 1)).u!; 9 | 10 | group("when()", () { 11 | test("can call when on TAs", () { 12 | bool wasCalled = false; 13 | tA.when( 14 | tA: (a) { 15 | wasCalled = true; 16 | }, 17 | tB: (_) => fail("should not be called"), 18 | orElse: () => fail("should not be called"), 19 | ); 20 | 21 | expect(wasCalled, isTrue); 22 | }); 23 | 24 | test("can call when on TBs", () { 25 | bool wasCalled = false; 26 | tB.when( 27 | tA: (_) => fail("should not be called"), 28 | tB: (b) { 29 | wasCalled = true; 30 | }, 31 | orElse: () => fail("should not be called"), 32 | ); 33 | 34 | expect(wasCalled, isTrue); 35 | }); 36 | 37 | test("when returns result", () { 38 | final velocity = tB.when( 39 | tA: (_) => fail("should not be called"), 40 | tB: (tB) => tB.velocity, 41 | orElse: () => fail("should not be called"), 42 | ); 43 | 44 | expect(velocity, 1); 45 | }); 46 | 47 | test("unexpected typeName calls orElse", () { 48 | final animal = tA.copyWith(typename: "Animal"); 49 | 50 | bool wasCalled = false; 51 | 52 | animal.when( 53 | tA: (_) {}, 54 | tB: (_) {}, 55 | orElse: () { 56 | wasCalled = true; 57 | }, 58 | ); 59 | 60 | expect(wasCalled, isTrue); 61 | }); 62 | }); 63 | 64 | group("maybeWhen()", () { 65 | test("can call maybeWhen on TAs", () { 66 | bool wasCalled = false; 67 | tA.maybeWhen( 68 | tA: (h) { 69 | wasCalled = true; 70 | }, 71 | orElse: () => fail("should not be called"), 72 | ); 73 | 74 | expect(wasCalled, isTrue); 75 | }); 76 | 77 | test("can call maybeWhen on TBs", () { 78 | bool wasCalled = false; 79 | tB.maybeWhen( 80 | tB: (d) { 81 | wasCalled = true; 82 | }, 83 | orElse: () => fail("should not be called"), 84 | ); 85 | 86 | expect(wasCalled, isTrue); 87 | }); 88 | 89 | test("calls orElse when not matching", () { 90 | bool wasCalled = false; 91 | tB.maybeWhen(orElse: () { 92 | wasCalled = true; 93 | }); 94 | 95 | expect(wasCalled, isTrue); 96 | }); 97 | 98 | test("unexpected typeName calls orElse", () { 99 | final animal = tA.copyWith(typename: "Animal"); 100 | 101 | bool wasCalled = false; 102 | 103 | animal.maybeWhen(orElse: () { 104 | wasCalled = true; 105 | }); 106 | 107 | expect(wasCalled, isTrue); 108 | }); 109 | }); 110 | } 111 | -------------------------------------------------------------------------------- /packages/graphql_codegen/test/builder_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | 4 | import 'package:build/build.dart'; 5 | import 'package:build_test/build_test.dart'; 6 | import 'package:graphql_codegen/builder.dart'; 7 | import 'package:path/path.dart'; 8 | import 'package:path/path.dart' as path; 9 | import 'package:test/scaffolding.dart'; 10 | 11 | final p = path.Context(style: path.Style.posix); 12 | 13 | final assetsDir = Directory("test/assets"); 14 | 15 | void main() { 16 | for (final testSet in assetsDir 17 | .listSync() 18 | .whereType() 19 | .where((element) => !basename(element.path).startsWith("_"))) { 20 | group(testSet.path, () { 21 | test("works", () async { 22 | final files = Map.fromEntries( 23 | await Future.wait( 24 | testSet 25 | .listSync(recursive: true) 26 | .where((element) => !basename(element.path).startsWith("_")) 27 | .whereType() 28 | .where((file) => const { 29 | '.graphql', 30 | '.dart', 31 | '.gql', 32 | '.graphqls', 33 | '.expected', 34 | '.json' 35 | }.contains(extension(file.path))) 36 | .map( 37 | (file) async => MapEntry( 38 | file.absolute.path.replaceAll(testSet.absolute.path, ""), 39 | await file.readAsString(), 40 | ), 41 | ), 42 | ), 43 | ); 44 | final builderOptions = files.entries 45 | .where((element) => element.key.endsWith("builder_options.json")) 46 | .map((e) => jsonDecode(e.value)) 47 | .whereType?>() 48 | .firstWhere((element) => element != null, orElse: () => null); 49 | final noFlatLib = builderOptions?['noFlatLib'] == true; 50 | 51 | final assets = {}; 52 | final expectedOutputs = {}; 53 | for (final entry in files.entries) { 54 | final path = entry.key; 55 | final file = entry.value; 56 | final relativePath = p.relative(path, from: '/'); 57 | final assetPath = noFlatLib 58 | ? 'a|${relativePath}' 59 | : 'a|${p.join('lib', relativePath)}'; 60 | if (extension(path) == '.expected') { 61 | await File("${testSet.path}/${path}").delete(); 62 | } else if ({'.graphql', '.gql', '.graphqls'} 63 | .contains(extension(path))) { 64 | assets[assetPath] = file; 65 | } else if (path.endsWith(".graphql.dart") || 66 | path.endsWith('.gql.dart') || 67 | path.endsWith('.graphqls.dart')) { 68 | expectedOutputs[assetPath] = file; 69 | } 70 | } 71 | final optionsFile = 72 | files.entries.whereType?>().firstWhere( 73 | (element) => 74 | element != null && element.key.endsWith("/options.json"), 75 | orElse: () => null, 76 | ); 77 | final options = optionsFile == null 78 | ? BuilderOptions.empty 79 | : BuilderOptions( 80 | jsonDecode(optionsFile.value) as Map); 81 | final writer = InMemoryAssetWriter(); 82 | try { 83 | await testBuilder( 84 | GraphQLBuilder(options), 85 | assets, 86 | writer: writer, 87 | rootPackage: 'a', 88 | outputs: expectedOutputs, 89 | ); 90 | } catch (e) { 91 | for (final entry in writer.assets.entries) { 92 | final file = noFlatLib 93 | ? entry.key.path 94 | : entry.key.path.replaceAll(RegExp("^lib"), ""); 95 | if (utf8.decode(entry.value) != files[file]) { 96 | await (await File( 97 | "${testSet.absolute.path}/${file}.expected", 98 | // "${testSet.absolute.path}/${file}", 99 | ).create(recursive: true)) 100 | .writeAsBytes(entry.value); 101 | } 102 | } 103 | rethrow; 104 | } 105 | }); 106 | }); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: graphql_codegen_workspace 2 | 3 | environment: 4 | sdk: ">=2.12.0 <3.0.0" 5 | 6 | dev_dependencies: 7 | melos: ^6.1.0 8 | --------------------------------------------------------------------------------