Skip to content

Commit 5be1a2d

Browse files
Shane32sungam3r
andauthored
Make AST constructors parametrized (#307) for v8 (#328)
Co-authored-by: Ivan Maximov <[email protected]>
1 parent 51e77c1 commit 5be1a2d

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

+777
-26
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<PackageReadmeFile Condition="'$(IsPackable)' == 'true'">README.md</PackageReadmeFile>
2525
<SignAssembly>true</SignAssembly>
2626
<AssemblyOriginatorKeyFile>..\graphql.snk</AssemblyOriginatorKeyFile>
27+
<NoWarn>$(NoWarn);CS0618</NoWarn>
2728
</PropertyGroup>
2829

2930
<ItemGroup Condition="'$(IsPackable)' == 'true'">

src/GraphQLParser.ApiTests/GraphQLParser.approved.txt

Lines changed: 94 additions & 0 deletions
Large diffs are not rendered by default.

src/GraphQLParser/AST/ASTListNode.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,25 @@ namespace GraphQLParser.AST;
77
/// </summary>
88
public abstract class ASTListNode<TNode> : ASTNode, IReadOnlyList<TNode>
99
{
10+
/// <summary>Initializes a new instance.</summary>
11+
[Obsolete("This constructor will be removed in v9.")]
12+
protected ASTListNode()
13+
{
14+
Items = null!;
15+
}
16+
17+
/// <summary>
18+
/// Creates a new instance of <see cref="ASTListNode{TNode}"/>.
19+
/// </summary>
20+
protected ASTListNode(List<TNode> items)
21+
{
22+
Items = items;
23+
}
24+
1025
/// <summary>
1126
/// A list of nested AST nodes.
1227
/// </summary>
13-
public List<TNode> Items { get; set; } = null!;
28+
public List<TNode> Items { get; set; }
1429

1530
/// <summary>
1631
/// Get the number of AST nodes in the list.

src/GraphQLParser/AST/Definitions/GraphQLArgumentsDefinition.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ namespace GraphQLParser.AST;
55
/// </summary>
66
public class GraphQLArgumentsDefinition : ASTListNode<GraphQLInputValueDefinition>
77
{
8+
/// <summary>Initializes a new instance.</summary>
9+
[Obsolete("This constructor will be removed in v9.")]
10+
public GraphQLArgumentsDefinition()
11+
{
12+
}
13+
14+
/// <summary>
15+
/// Creates a new instance of <see cref="GraphQLArgumentsDefinition"/>.
16+
/// </summary>
17+
public GraphQLArgumentsDefinition(List<GraphQLInputValueDefinition> items)
18+
: base(items)
19+
{
20+
}
21+
822
/// <inheritdoc/>
923
public override ASTNodeKind Kind => ASTNodeKind.ArgumentsDefinition;
1024
}

src/GraphQLParser/AST/Definitions/GraphQLDirectiveDefinition.cs

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

@@ -29,7 +45,7 @@ public class GraphQLDirectiveDefinition : GraphQLTypeDefinition, IHasArgumentsDe
2945
/// <summary>
3046
/// Returns a node with a list of locations representing the valid locations this directive may be placed.
3147
/// </summary>
32-
public GraphQLDirectiveLocations Locations { get; set; } = null!;
48+
public GraphQLDirectiveLocations Locations { get; set; }
3349
}
3450

3551
internal sealed class GraphQLDirectiveDefinitionWithLocation : GraphQLDirectiveDefinition

src/GraphQLParser/AST/Definitions/GraphQLEnumTypeDefinition.cs

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

src/GraphQLParser/AST/Definitions/GraphQLEnumValueDefinition.cs

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

@@ -16,7 +32,7 @@ public class GraphQLEnumValueDefinition : GraphQLTypeDefinition, IHasDirectivesN
1632
/// <see cref="GraphQLTypeDefinition.Name"/> property holds almost
1733
/// the same data and should be set as well.
1834
/// </summary>
19-
public GraphQLEnumValue EnumValue { get; set; } = null!;
35+
public GraphQLEnumValue EnumValue { get; set; }
2036

2137
/// <inheritdoc/>
2238
public GraphQLDirectives? Directives { get; set; }

src/GraphQLParser/AST/Definitions/GraphQLEnumValuesDefinition.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ namespace GraphQLParser.AST;
55
/// </summary>
66
public class GraphQLEnumValuesDefinition : ASTListNode<GraphQLEnumValueDefinition>
77
{
8+
/// <summary>Initializes a new instance.</summary>
9+
[Obsolete("This constructor will be removed in v9.")]
10+
public GraphQLEnumValuesDefinition()
11+
{
12+
}
13+
14+
/// <summary>
15+
/// Creates a new instance of <see cref="GraphQLEnumValuesDefinition"/>.
16+
/// </summary>
17+
public GraphQLEnumValuesDefinition(List<GraphQLEnumValueDefinition> items)
18+
: base(items)
19+
{
20+
}
21+
822
/// <inheritdoc/>
923
public override ASTNodeKind Kind => ASTNodeKind.EnumValuesDefinition;
1024
}

src/GraphQLParser/AST/Definitions/GraphQLExecutableDefinition.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@ namespace GraphQLParser.AST;
77
/// </summary>
88
public abstract class GraphQLExecutableDefinition : ASTNode, IHasSelectionSetNode, IHasDirectivesNode
99
{
10+
/// <summary>Initializes a new instance.</summary>
11+
[Obsolete("This constructor will be removed in v9.")]
12+
protected GraphQLExecutableDefinition()
13+
{
14+
SelectionSet = null!;
15+
}
16+
17+
/// <summary>
18+
/// Creates a new instance of <see cref="GraphQLExecutableDefinition"/>.
19+
/// </summary>
20+
protected GraphQLExecutableDefinition(GraphQLSelectionSet selectionSet)
21+
{
22+
SelectionSet = selectionSet;
23+
}
24+
1025
/// <inheritdoc/>
1126
public GraphQLDirectives? Directives { get; set; }
1227

1328
/// <inheritdoc/>
1429
#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!;
30+
public GraphQLSelectionSet SelectionSet { get; set; }
1631
#pragma warning restore CS8767
1732
}

src/GraphQLParser/AST/Definitions/GraphQLFieldDefinition.cs

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

@@ -19,7 +35,7 @@ public class GraphQLFieldDefinition : GraphQLTypeDefinition, IHasDirectivesNode,
1935
/// <summary>
2036
/// Nested <see cref="GraphQLType"/> AST node with field type.
2137
/// </summary>
22-
public GraphQLType Type { get; set; } = null!;
38+
public GraphQLType Type { get; set; }
2339

2440
/// <inheritdoc/>
2541
public GraphQLDirectives? Directives { get; set; }

0 commit comments

Comments
 (0)