artemis icon indicating copy to clipboard operation
artemis copied to clipboard

@include in graphql-schema not working

Open Nealsoni00 opened this issue 3 years ago • 4 comments

Bug description

I have an @include (if: $detailed) in my fragment. When that $detailed is set to false, and the schema is returned without the property, parsing the response with the generated type file does not work.

The fragment is included using fragment_glob in build.yml

image

fragment propertyFields on Property {
    id
    optionallyIncludedProperty(first: $number, after: $cursor) @include(if: $detailed) {
        ...someConnectionFields
    }
}

line that errors:

SomeMixin$Property _$SomeMixin$PropertyFromJson(
    Map<String, dynamic> json) {
  return SomeMixin$Property()
    ..id = json['id'] as String
    ..optionallyIncludedProperty = SomeMixin$SomeConnection.fromJson(
        json['optionallyIncludedProperty'] as Map<String, dynamic>) \\<----
}

Specs

artemis: ^7.0.0-beta.3

build.yaml:
targets:
  $default:
    sources:
      - lib/**
    builders:
      artemis:
        options:
          fragments_glob: lib/graphql/operations/fragments/*.graphql
          schema_mapping:
            - schema: lib/graphql/schema.graphql
              queries_glob: lib/graphql/operations/api.graphql
              output: lib/graphql/api.dart
          scalar_mapping:
            - graphql_type: JSON
              dart_type: Map<String, dynamic>
            - graphql_type: ISO8601DateTime
              dart_type: DateTime
Artemis output:
builds successfully

Nealsoni00 avatar Jul 16 '21 21:07 Nealsoni00

I ran into the same issue with artemis: 7.8.0-beta. In my case the graph query executes correctly but conditionally some data isn't return,...hence the parsing error. Same thing for @skip.

kmcgill88 avatar Jul 21 '22 02:07 kmcgill88

Yeah this seems to be related to the model builder, @include will work just fine if the Schema says field could be nullable, but if it's something that reports back as not nullable then includes will fail, such as a connection or node.

cfsbhawkins avatar Oct 06 '22 15:10 cfsbhawkins

Any updates? We have the same problem? This ticket is open over one year?

sarp86 avatar Nov 18 '22 22:11 sarp86

@comigor As a solution for this issue, could this be an acceptable behavior to generate a Dart nullable field if a non-nullable GraphQL field marked with the @include directive ?

pdegand avatar Mar 15 '23 10:03 pdegand