Skip to content

Commit

Permalink
Make AST constructors parametrized (#307) for v8 (#328)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Maximov <[email protected]>
  • Loading branch information
Shane32 and sungam3r authored Jun 25, 2023
1 parent 51e77c1 commit 5be1a2d
Show file tree
Hide file tree
Showing 52 changed files with 777 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageReadmeFile Condition="'$(IsPackable)' == 'true'">README.md</PackageReadmeFile>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\graphql.snk</AssemblyOriginatorKeyFile>
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup Condition="'$(IsPackable)' == 'true'">
Expand Down
94 changes: 94 additions & 0 deletions src/GraphQLParser.ApiTests/GraphQLParser.approved.txt

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/GraphQLParser/AST/ASTListNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@ namespace GraphQLParser.AST;
/// </summary>
public abstract class ASTListNode<TNode> : ASTNode, IReadOnlyList<TNode>
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
protected ASTListNode()
{
Items = null!;
}

/// <summary>
/// Creates a new instance of <see cref="ASTListNode{TNode}"/>.
/// </summary>
protected ASTListNode(List<TNode> items)
{
Items = items;
}

/// <summary>
/// A list of nested AST nodes.
/// </summary>
public List<TNode> Items { get; set; } = null!;
public List<TNode> Items { get; set; }

/// <summary>
/// Get the number of AST nodes in the list.
Expand Down
14 changes: 14 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLArgumentsDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLArgumentsDefinition : ASTListNode<GraphQLInputValueDefinition>
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLArgumentsDefinition()
{
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLArgumentsDefinition"/>.
/// </summary>
public GraphQLArgumentsDefinition(List<GraphQLInputValueDefinition> items)
: base(items)
{
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.ArgumentsDefinition;
}
Expand Down
18 changes: 17 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLDirectiveDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLDirectiveDefinition: {Name}")]
public class GraphQLDirectiveDefinition : GraphQLTypeDefinition, IHasArgumentsDefinitionNode
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLDirectiveDefinition()
{
Locations = null!;
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLDirectiveDefinition"/>.
/// </summary>
public GraphQLDirectiveDefinition(GraphQLName name, GraphQLDirectiveLocations locations)
: base(name)
{
Locations = locations;
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.DirectiveDefinition;

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

internal sealed class GraphQLDirectiveDefinitionWithLocation : GraphQLDirectiveDefinition
Expand Down
14 changes: 14 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLEnumTypeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLEnumTypeDefinition: {Name}")]
public class GraphQLEnumTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLEnumTypeDefinition()
{
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLEnumTypeDefinition"/>.
/// </summary>
public GraphQLEnumTypeDefinition(GraphQLName name)
: base(name)
{
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.EnumTypeDefinition;

Expand Down
18 changes: 17 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLEnumValueDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLEnumValueDefinition: {EnumValue}")]
public class GraphQLEnumValueDefinition : GraphQLTypeDefinition, IHasDirectivesNode
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLEnumValueDefinition()
{
EnumValue = null!;
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLEnumValueDefinition"/>.
/// </summary>
public GraphQLEnumValueDefinition(GraphQLName name, GraphQLEnumValue enumValue)
: base(name)
{
EnumValue = enumValue;
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.EnumValueDefinition;

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

/// <inheritdoc/>
public GraphQLDirectives? Directives { get; set; }
Expand Down
14 changes: 14 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLEnumValuesDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLEnumValuesDefinition : ASTListNode<GraphQLEnumValueDefinition>
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLEnumValuesDefinition()
{
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLEnumValuesDefinition"/>.
/// </summary>
public GraphQLEnumValuesDefinition(List<GraphQLEnumValueDefinition> items)
: base(items)
{
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.EnumValuesDefinition;
}
Expand Down
17 changes: 16 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLExecutableDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@ namespace GraphQLParser.AST;
/// </summary>
public abstract class GraphQLExecutableDefinition : ASTNode, IHasSelectionSetNode, IHasDirectivesNode
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
protected GraphQLExecutableDefinition()
{
SelectionSet = null!;
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLExecutableDefinition"/>.
/// </summary>
protected GraphQLExecutableDefinition(GraphQLSelectionSet selectionSet)
{
SelectionSet = selectionSet;
}

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

/// <inheritdoc/>
#pragma warning disable CS8767 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
public GraphQLSelectionSet SelectionSet { get; set; } = null!;
public GraphQLSelectionSet SelectionSet { get; set; }
#pragma warning restore CS8767
}
18 changes: 17 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLFieldDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLFieldDefinition: {Name}")]
public class GraphQLFieldDefinition : GraphQLTypeDefinition, IHasDirectivesNode, IHasArgumentsDefinitionNode
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLFieldDefinition()
{
Type = null!;
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLFieldDefinition"/>.
/// </summary>
public GraphQLFieldDefinition(GraphQLName name, GraphQLType type)
: base(name)
{
Type = type;
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.FieldDefinition;

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

/// <inheritdoc/>
public GraphQLDirectives? Directives { get; set; }
Expand Down
14 changes: 14 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLFieldsDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLFieldsDefinition : ASTListNode<GraphQLFieldDefinition>
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLFieldsDefinition()
{
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLFieldsDefinition"/>.
/// </summary>
public GraphQLFieldsDefinition(List<GraphQLFieldDefinition> items)
: base(items)
{
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.FieldsDefinition;
}
Expand Down
22 changes: 20 additions & 2 deletions src/GraphQLParser/AST/Definitions/GraphQLFragmentDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,36 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLFragmentDefinition: {FragmentName.Name.StringValue}")]
public class GraphQLFragmentDefinition : GraphQLExecutableDefinition
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLFragmentDefinition()
{
FragmentName = null!;
TypeCondition = null!;
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLFragmentDefinition"/>.
/// </summary>
public GraphQLFragmentDefinition(GraphQLFragmentName name, GraphQLTypeCondition typeCondition, GraphQLSelectionSet selectionSet)
: base(selectionSet)
{
FragmentName = name;
TypeCondition = typeCondition;
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.FragmentDefinition;

/// <summary>
/// Fragment name represented as a nested AST node.
/// </summary>
public GraphQLFragmentName FragmentName { get; set; } = null!;
public GraphQLFragmentName FragmentName { get; set; }

/// <summary>
/// Nested <see cref="GraphQLTypeCondition"/> AST node with type condition of this fragment.
/// </summary>
public GraphQLTypeCondition TypeCondition { get; set; } = null!;
public GraphQLTypeCondition TypeCondition { get; set; }
}

internal sealed class GraphQLFragmentDefinitionWithLocation : GraphQLFragmentDefinition
Expand Down
14 changes: 14 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLInputFieldsDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLInputFieldsDefinition : ASTListNode<GraphQLInputValueDefinition>
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLInputFieldsDefinition()
{
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLInputFieldsDefinition"/>.
/// </summary>
public GraphQLInputFieldsDefinition(List<GraphQLInputValueDefinition> items)
: base(items)
{
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.InputFieldsDefinition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLInputObjectTypeDefinition: {Name}")]
public class GraphQLInputObjectTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLInputObjectTypeDefinition()
{
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLInputObjectTypeDefinition"/>.
/// </summary>
public GraphQLInputObjectTypeDefinition(GraphQLName name)
: base(name)
{
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.InputObjectTypeDefinition;

Expand Down
18 changes: 17 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLInputValueDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLInputValueDefinition : GraphQLTypeDefinition, IHasDirectivesNode, IHasDefaultValueNode
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLInputValueDefinition()
{
Type = null!;
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLInputValueDefinition"/>.
/// </summary>
public GraphQLInputValueDefinition(GraphQLName name, GraphQLType type)
: base(name)
{
Type = type;
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.InputValueDefinition;

/// <summary>
/// Nested <see cref="GraphQLType"/> AST node with input value type.
/// </summary>
public GraphQLType Type { get; set; } = null!;
public GraphQLType Type { get; set; }

/// <inheritdoc />
public GraphQLValue? DefaultValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLInterfaceTypeDefinition: {Name}")]
public class GraphQLInterfaceTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode, IHasInterfacesNode, IHasFieldsDefinitionNode
{
/// <summary>Initializes a new instance.</summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLInterfaceTypeDefinition()
{
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLInterfaceTypeDefinition"/>.
/// </summary>
public GraphQLInterfaceTypeDefinition(GraphQLName name)
: base(name)
{
}

/// <inheritdoc/>
public override ASTNodeKind Kind => ASTNodeKind.InterfaceTypeDefinition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GraphQLObjectTypeDefinition : GraphQLTypeDefinition, IHasDirectives
/// <summary>
/// Creates a new instance of <see cref="GraphQLObjectTypeDefinition"/>.
/// </summary>
[Obsolete("This constructor will be removed in v9.")]
public GraphQLObjectTypeDefinition()
{
}
Expand Down
Loading

0 comments on commit 5be1a2d

Please sign in to comment.