Skip to content

Commit 8483d95

Browse files
authored
Make AST constructors parametrized (#307)
1 parent 568ed79 commit 8483d95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+727
-82
lines changed

.github/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test:
2-
- src/GraphQLParser.ApiTests/**/*
32
- src/GraphQLParser.Tests/**/*
3+
- src/GraphQLParser.ApiTests/**/*.cs
44

55
CI:
66
- .github/workflows/**/*

src/GraphQLParser.ApiTests/GraphQLParser.approved.txt

Lines changed: 50 additions & 49 deletions
Large diffs are not rendered by default.

src/GraphQLParser/AST/ASTListNode.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,23 @@ namespace GraphQLParser.AST;
77
/// </summary>
88
public abstract class ASTListNode<TNode> : ASTNode, IReadOnlyList<TNode>
99
{
10+
internal ASTListNode()
11+
{
12+
Items = null!;
13+
}
14+
15+
/// <summary>
16+
/// Creates a new instance of <see cref="ASTListNode{TNode}"/>.
17+
/// </summary>
18+
protected ASTListNode(List<TNode> items)
19+
{
20+
Items = items;
21+
}
22+
1023
/// <summary>
1124
/// A list of nested AST nodes.
1225
/// </summary>
13-
public List<TNode> Items { get; set; } = null!;
26+
public List<TNode> Items { get; set; }
1427

1528
/// <summary>
1629
/// Get the number of AST nodes in the list.

src/GraphQLParser/AST/Definitions/GraphQLArgumentsDefinition.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ namespace GraphQLParser.AST;
55
/// </summary>
66
public class GraphQLArgumentsDefinition : ASTListNode<GraphQLInputValueDefinition>
77
{
8+
internal GraphQLArgumentsDefinition()
9+
{
10+
}
11+
12+
/// <summary>
13+
/// Creates a new instance of <see cref="GraphQLArgumentsDefinition"/>.
14+
/// </summary>
15+
public GraphQLArgumentsDefinition(List<GraphQLInputValueDefinition> items)
16+
: base(items)
17+
{
18+
}
19+
820
/// <inheritdoc/>
921
public override ASTNodeKind Kind => ASTNodeKind.ArgumentsDefinition;
1022
}

src/GraphQLParser/AST/Definitions/GraphQLDirectiveDefinition.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
88
[DebuggerDisplay("GraphQLDirectiveDefinition: {Name}")]
99
public class GraphQLDirectiveDefinition : GraphQLTypeDefinition, IHasArgumentsDefinitionNode
1010
{
11+
internal GraphQLDirectiveDefinition()
12+
{
13+
Locations = null!;
14+
}
15+
16+
/// <summary>
17+
/// Creates a new instance of <see cref="GraphQLDirectiveDefinition"/>.
18+
/// </summary>
19+
public GraphQLDirectiveDefinition(GraphQLName name, GraphQLDirectiveLocations locations)
20+
: base(name)
21+
{
22+
Locations = locations;
23+
}
24+
1125
/// <inheritdoc/>
1226
public override ASTNodeKind Kind => ASTNodeKind.DirectiveDefinition;
1327

@@ -29,7 +43,7 @@ public class GraphQLDirectiveDefinition : GraphQLTypeDefinition, IHasArgumentsDe
2943
/// <summary>
3044
/// Returns a node with a list of locations representing the valid locations this directive may be placed.
3145
/// </summary>
32-
public GraphQLDirectiveLocations Locations { get; set; } = null!;
46+
public GraphQLDirectiveLocations Locations { get; set; }
3347
}
3448

3549
internal sealed class GraphQLDirectiveDefinitionWithLocation : GraphQLDirectiveDefinition

src/GraphQLParser/AST/Definitions/GraphQLEnumTypeDefinition.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ namespace GraphQLParser.AST;
88
[DebuggerDisplay("GraphQLEnumTypeDefinition: {Name}")]
99
public class GraphQLEnumTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode
1010
{
11+
internal GraphQLEnumTypeDefinition()
12+
{
13+
}
14+
15+
/// <summary>
16+
/// Creates a new instance of <see cref="GraphQLEnumTypeDefinition"/>.
17+
/// </summary>
18+
public GraphQLEnumTypeDefinition(GraphQLName name)
19+
: base(name)
20+
{
21+
}
22+
1123
/// <inheritdoc/>
1224
public override ASTNodeKind Kind => ASTNodeKind.EnumTypeDefinition;
1325

src/GraphQLParser/AST/Definitions/GraphQLEnumValueDefinition.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
88
[DebuggerDisplay("GraphQLEnumValueDefinition: {EnumValue}")]
99
public class GraphQLEnumValueDefinition : GraphQLTypeDefinition, IHasDirectivesNode
1010
{
11+
internal GraphQLEnumValueDefinition()
12+
{
13+
EnumValue = null!;
14+
}
15+
16+
/// <summary>
17+
/// Creates a new instance of <see cref="GraphQLEnumValueDefinition"/>.
18+
/// </summary>
19+
public GraphQLEnumValueDefinition(GraphQLName name, GraphQLEnumValue enumValue)
20+
: base(name)
21+
{
22+
EnumValue = enumValue;
23+
}
24+
1125
/// <inheritdoc/>
1226
public override ASTNodeKind Kind => ASTNodeKind.EnumValueDefinition;
1327

@@ -16,7 +30,7 @@ public class GraphQLEnumValueDefinition : GraphQLTypeDefinition, IHasDirectivesN
1630
/// <see cref="GraphQLTypeDefinition.Name"/> property holds almost
1731
/// the same data and should be set as well.
1832
/// </summary>
19-
public GraphQLEnumValue EnumValue { get; set; } = null!;
33+
public GraphQLEnumValue EnumValue { get; set; }
2034

2135
/// <inheritdoc/>
2236
public GraphQLDirectives? Directives { get; set; }

src/GraphQLParser/AST/Definitions/GraphQLEnumValuesDefinition.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ namespace GraphQLParser.AST;
55
/// </summary>
66
public class GraphQLEnumValuesDefinition : ASTListNode<GraphQLEnumValueDefinition>
77
{
8+
internal GraphQLEnumValuesDefinition()
9+
{
10+
}
11+
12+
/// <summary>
13+
/// Creates a new instance of <see cref="GraphQLEnumValuesDefinition"/>.
14+
/// </summary>
15+
public GraphQLEnumValuesDefinition(List<GraphQLEnumValueDefinition> items)
16+
: base(items)
17+
{
18+
}
19+
820
/// <inheritdoc/>
921
public override ASTNodeKind Kind => ASTNodeKind.EnumValuesDefinition;
1022
}

src/GraphQLParser/AST/Definitions/GraphQLExecutableDefinition.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@ namespace GraphQLParser.AST;
77
/// </summary>
88
public abstract class GraphQLExecutableDefinition : ASTNode, IHasSelectionSetNode, IHasDirectivesNode
99
{
10+
internal GraphQLExecutableDefinition()
11+
{
12+
SelectionSet = null!;
13+
}
14+
15+
/// <summary>
16+
/// Creates a new instance of <see cref="GraphQLExecutableDefinition"/>.
17+
/// </summary>
18+
protected GraphQLExecutableDefinition(GraphQLSelectionSet selectionSet)
19+
{
20+
SelectionSet = selectionSet;
21+
}
22+
1023
/// <inheritdoc/>
1124
public GraphQLDirectives? Directives { get; set; }
1225

1326
/// <inheritdoc/>
1427
#pragma warning disable CS8767 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
15-
public GraphQLSelectionSet SelectionSet { get; set; } = null!;
28+
public GraphQLSelectionSet SelectionSet { get; set; }
1629
#pragma warning restore CS8767
1730
}

src/GraphQLParser/AST/Definitions/GraphQLFieldDefinition.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
88
[DebuggerDisplay("GraphQLFieldDefinition: {Name}")]
99
public class GraphQLFieldDefinition : GraphQLTypeDefinition, IHasDirectivesNode, IHasArgumentsDefinitionNode
1010
{
11+
internal GraphQLFieldDefinition()
12+
{
13+
Type = null!;
14+
}
15+
16+
/// <summary>
17+
/// Creates a new instance of <see cref="GraphQLFieldDefinition"/>.
18+
/// </summary>
19+
public GraphQLFieldDefinition(GraphQLName name, GraphQLType type)
20+
: base(name)
21+
{
22+
Type = type;
23+
}
24+
1125
/// <inheritdoc/>
1226
public override ASTNodeKind Kind => ASTNodeKind.FieldDefinition;
1327

@@ -19,7 +33,7 @@ public class GraphQLFieldDefinition : GraphQLTypeDefinition, IHasDirectivesNode,
1933
/// <summary>
2034
/// Nested <see cref="GraphQLType"/> AST node with field type.
2135
/// </summary>
22-
public GraphQLType Type { get; set; } = null!;
36+
public GraphQLType Type { get; set; }
2337

2438
/// <inheritdoc/>
2539
public GraphQLDirectives? Directives { get; set; }

0 commit comments

Comments
 (0)