Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #224 from comigor/input-underscore-bugfix
Browse files Browse the repository at this point in the history
input underscore bugfix
  • Loading branch information
vasilich6107 authored Oct 7, 2020
2 parents 23210ff + 777689a commit 7efe903
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 6.13.1-beta.1
- input underscore bugfix https://github.com/comigor/artemis/issues/223

## 6.12.3-beta.2
- Subscription test added

Expand Down
8 changes: 7 additions & 1 deletion lib/visitor/generator_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ class GeneratorVisitor extends RecursiveVisitor {
}
}

final inputName = QueryInputName(name: node.variable.name.value);

if (inputName.namePrintable != inputName.name) {
jsonKeyAnnotation['name'] = '\'${inputName.name}\'';
}

var annotations = <String>[];

if (jsonKeyAnnotation.isNotEmpty) {
Expand All @@ -199,7 +205,7 @@ class GeneratorVisitor extends RecursiveVisitor {

context.inputsClasses.add(QueryInput(
type: dartTypeName,
name: QueryInputName(name: node.variable.name.value),
name: inputName,
isNonNull: node.type.isNonNull,
annotations: annotations,
));
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: artemis
version: 6.12.3-beta.2
version: 6.13.1-beta.1

description: Build dart types from GraphQL schemas and queries (using Introspection Query).
homepage: https://github.com/comigor/artemis
Expand Down
52 changes: 27 additions & 25 deletions test/query_generator/enums/input_enum_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {
}
type QueryRoot {
q(input: Input!, o: OtherEnum!): QueryResponse
q(_id: ID!, input: Input!, o: OtherEnum!): QueryResponse
}
type QueryResponse {
Expand Down Expand Up @@ -50,8 +50,8 @@ void main() {
}

const query = r'''
query custom($input: Input!, $o: OtherEnum!) {
q(input: $input, o: $o) {
query custom($_id: ID!, $input: Input!, $o: OtherEnum!) {
q(_id: $_id, input: $input, o: $o) {
s
my
other
Expand All @@ -66,28 +66,14 @@ final LibraryDefinition libraryDefinition =
operationName: r'custom',
classes: [
EnumDefinition(name: EnumName(name: r'MyEnum'), values: [
EnumValueDefinition(
name: EnumValueName(name: r'A'),
),
EnumValueDefinition(
name: EnumValueName(name: r'B'),
),
EnumValueDefinition(
name: EnumValueName(
name: r'ARTEMIS_UNKNOWN',
))
EnumValueDefinition(name: EnumValueName(name: r'A')),
EnumValueDefinition(name: EnumValueName(name: r'B')),
EnumValueDefinition(name: EnumValueName(name: r'ARTEMIS_UNKNOWN'))
]),
EnumDefinition(name: EnumName(name: r'OtherEnum'), values: [
EnumValueDefinition(
name: EnumValueName(name: r'O1'),
),
EnumValueDefinition(
name: EnumValueName(name: r'O2'),
),
EnumValueDefinition(
name: EnumValueName(
name: r'ARTEMIS_UNKNOWN',
))
EnumValueDefinition(name: EnumValueName(name: r'O1')),
EnumValueDefinition(name: EnumValueName(name: r'O2')),
EnumValueDefinition(name: EnumValueName(name: r'ARTEMIS_UNKNOWN'))
]),
ClassDefinition(
name: ClassName(name: r'Custom$_QueryRoot$_QueryResponse'),
Expand Down Expand Up @@ -146,6 +132,11 @@ final LibraryDefinition libraryDefinition =
isInput: true)
],
inputs: [
QueryInput(
type: TypeName(name: r'String'),
name: QueryInputName(name: r'_id'),
isNonNull: true,
annotations: [r'''JsonKey(name: '_id')''']),
QueryInput(
type: TypeName(name: r'Input'),
name: QueryInputName(name: r'input'),
Expand Down Expand Up @@ -238,19 +229,22 @@ enum OtherEnum {
@JsonSerializable(explicitToJson: true)
class CustomArguments extends JsonSerializable with EquatableMixin {
CustomArguments({@required this.input, @required this.o});
CustomArguments({@required this.$id, @required this.input, @required this.o});
@override
factory CustomArguments.fromJson(Map<String, dynamic> json) =>
_$CustomArgumentsFromJson(json);
@JsonKey(name: '_id')
final String $id;
final Input input;
@JsonKey(unknownEnumValue: OtherEnum.artemisUnknown)
final OtherEnum o;
@override
List<Object> get props => [input, o];
List<Object> get props => [$id, input, o];
@override
Map<String, dynamic> toJson() => _$CustomArgumentsToJson(this);
}
Expand All @@ -264,6 +258,11 @@ class CustomQuery extends GraphQLQuery<Custom$QueryRoot, CustomArguments> {
type: OperationType.query,
name: NameNode(value: 'custom'),
variableDefinitions: [
VariableDefinitionNode(
variable: VariableNode(name: NameNode(value: '_id')),
type: NamedTypeNode(name: NameNode(value: 'ID'), isNonNull: true),
defaultValue: DefaultValueNode(value: null),
directives: []),
VariableDefinitionNode(
variable: VariableNode(name: NameNode(value: 'input')),
type: NamedTypeNode(
Expand All @@ -283,6 +282,9 @@ class CustomQuery extends GraphQLQuery<Custom$QueryRoot, CustomArguments> {
name: NameNode(value: 'q'),
alias: null,
arguments: [
ArgumentNode(
name: NameNode(value: '_id'),
value: VariableNode(name: NameNode(value: '_id'))),
ArgumentNode(
name: NameNode(value: 'input'),
value: VariableNode(name: NameNode(value: 'input'))),
Expand Down

0 comments on commit 7efe903

Please sign in to comment.