artemis
artemis copied to clipboard
# imports / Document parsing middleware
I'd like to use gql's ast.transform to implement an inline imports handler similar to graphql-import or graphql-import-loader, but would need a parser middleware hook to use it with artemis.
Alternatives:
- Add import handling to
artemisnatively - Concatenate all globbed files and generate query definitions from the resulting blob instead of iterating over them. This has the pro of not limiting users to 1-to-1 mapping of files-to-operations, but might collide with some other design decision that I am unaware of.
For reference, the output of build -vvv is pretty uninformative here
flutter pub run build_runner build -vvv
[INFO] Generating build script...
[INFO] Generating build script completed, took 259ms
[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Reading cached asset graph...
[INFO] BuildDefinition:Reading cached asset graph completed, took 96ms
[INFO] BuildDefinition:Checking for updates since last build...
[INFO] BuildDefinition:Checking for updates since last build completed, took 964ms
[INFO] Build:Running build...
[SEVERE] artemis:artemis on lib/$lib$:
Bad state: No element
dart:collection ListMixin.firstWhere
package:artemis/generator.dart 291:16 _extractClasses.<fn>
dart:core Iterable.forEach
package:artemis/generator.dart 307:10 _extractClasses
package:artemis/generator.dart 321:15 _extractClasses.<fn>.<fn>
package:artemis/generator.dart 160:20 _createClassProperty
package:artemis/generator.dart 207:10 _selectionToClassProperty
package:artemis/generator.dart 309:20 _extractClasses.<fn>
dart:core Iterable.forEach
package:artemis/generator.dart 307:10 _extractClasses
package:artemis/generator.dart 321:15 _extractClasses.<fn>.<fn>
package:artemis/generator.dart 160:20 _createClassProperty
package:artemis/generator.dart 207:10 _selectionToClassProperty
package:artemis/generator.dart 309:20 _extractClasses.<fn>
dart:core Iterable.forEach
package:artemis/generator.dart 307:10 _extractClasses
package:artemis/generator.dart 99:19 generateQuery
package:artemis/generator.dart 21:21 generateLibrary.<fn>
dart:_internal ListIterable.toList
package:artemis/generator.dart 22:8 generateLibrary
package:artemis/builder.dart 75:29 GraphQLQueryBuilder.build
package:build runBuilder
package:build_runner_core/src/generate/build_impl.dart 478:19 _SingleBuild._runForInput.<fn>.<fn>.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 300:15 _NoOpBuilderActionTracker.trackStage
package:build_runner_core/src/generate/build_impl.dart 476:23 _SingleBuild._runForInput.<fn>.<fn>
package:timing/src/timing.dart 222:44 NoOpTimeTracker.track
package:build_runner_core/src/generate/build_impl.dart 434:22 _SingleBuild._runForInput.<fn>
package:pool/pool.dart 127:28 Pool.withResource
package:build_runner_core/src/generate/build_impl.dart 430:17 _SingleBuild._runForInput
package:build_runner_core/src/generate/build_impl.dart 378:38 _SingleBuild._runBuilder.<fn>
dart:async Future.wait
package:build_runner_core/src/generate/build_impl.dart 377:36 _SingleBuild._runBuilder
package:build_runner_core/src/generate/build_impl.dart 323:20 _SingleBuild._runPhases.<fn>.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 184:15 _NoOpBuildPerformanceTracker.trackBuildPhase
package:build_runner_core/src/generate/build_impl.dart 319:47 _SingleBuild._runPhases.<fn>
package:timing/src/timing.dart 222:44 NoOpTimeTracker.track
package:build_runner_core/src/generate/build_impl.dart 313:32 _SingleBuild._runPhases
package:build_runner_core/src/logging/logging.dart 25:30 logTimedAsync
package:build_runner_core/src/generate/build_impl.dart 270:26 _SingleBuild._safeBuild.<fn>
dart:async runZoned
package:build_runner_core/src/generate/build_impl.dart 265:5 _SingleBuild._safeBuild
package:build_runner_core/src/generate/build_impl.dart 212:24 _SingleBuild.run
package:build_runner_core/src/generate/build_impl.dart 97:56 BuildImpl.run
package:build_runner_core/src/generate/build_runner.dart 25:14 BuildRunner.run
package:build_runner BuildCommand.run
package:args/command_runner.dart 197:27 CommandRunner.runCommand
package:args/command_runner.dart 112:25 CommandRunner.run.<fn>
dart:async new Future.sync
package:args/command_runner.dart 112:14 CommandRunner.run
package:build_runner run
.dart_tool/build/entrypoint/build.dart 31:22 main
[INFO] Build:Running build completed, took 155ms
[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 56ms
[SEVERE] Build:
Failed after 219ms
pub finished with exit code 1
Hey @micimize!
Actually the decision to make Artemis use synthetic lib input rather than iterating over each file was done exactly for grouped files parsing, I just didn't had the time to start coding those uses yet.
What do you feel about having a configurable interceptor list on each schema_map so all the globbed files and ASTs could be transformed before the generation itself? I think it could be defined just like build's builder_factories, for example, and then we could have a builder on Artemis to generate code to be run, and then another to run this code. What do you think?
About build -vvv: yeah, it needs better output steps and logging, though I'm not sure what you are doing right now to help you debug this stacktrace.
@comigor That seems like an alright approach - I don't follow the "builder builder" part entirely, as I'm not familiar with builder_factories.
The "grouped file parsing" sounds like it's enough to solve my particular issue though. I think a builtin preprocess: concatenate configuration might make sense
Currently working on a simple concatenation option for schema map, as well as looking into #30
I have a WIP branch for processors (just pushed it), but it may take some time to land. build limits a lot what a builder can do, specially when referencing dynamic code, so I need to generate, compile and run a custom code (just like build does) to achieve a custom middleware approach.
I'm now starting to work on how to call this generated builder code from the current builder, with the needed input, output and artemis configuration parameters.
@comigor any progress on middleware?
Sorry, I didn't have time to focus on it yet.