Skip to content

Should mutation constructors require a $__typename parameter to be provided manually? #235

Description

@jeroldalbertson-wf

I didn't know if this was intended, but generated Mutation operation classes require a $__typename parameter to be provided in their constructors. Is it normal for consumers to deviate from the type name declared in the source schema? How feasible would it be for $__typename to be removed from the constructor, or made optional with a reasonable default value?

mutation Update($id: ID!) {
    update(id: $id) {
        id
    }
}

generates the following dart code

class Mutation$Update {
  Mutation$Update({
    required this.update,
    required this.$__typename,
  });

  final Mutation$Update$update update;

  final String $__typename;
  // ...
}

// consumer writes:

final mutation = Mutation$Update(
    update: Mutation$Update$update(
      id: myId,
      $__typename: 'update',
    ),
    $__typename: 'Update',
  );

while the following would be more convenient

class Mutation$Update {
  Mutation$Update({
    required this.update,
  });

  final Mutation$Update$update update;

  const String $__typename = 'Update';
  // ...
}

// consumer writes:

final mutation = Mutation$Update(
    update: Mutation$Update$update(
      id: myId,
    ),
  );

Thanks again for all your work on this library. It's been a pleasure to work with. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions