Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AST constructors parametrized #307

Merged
merged 3 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test:
- src/GraphQLParser.ApiTests/**/*
- src/GraphQLParser.Tests/**/*
- src/GraphQLParser.ApiTests/**/*.cs

CI:
- .github/workflows/**/*
Expand Down
99 changes: 50 additions & 49 deletions src/GraphQLParser.ApiTests/GraphQLParser.approved.txt

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/GraphQLParser/AST/ASTListNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ namespace GraphQLParser.AST;
/// </summary>
public abstract class ASTListNode<TNode> : ASTNode, IReadOnlyList<TNode>
{
internal 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
12 changes: 12 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLArgumentsDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLArgumentsDefinition : ASTListNode<GraphQLInputValueDefinition>
{
internal 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
16 changes: 15 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLDirectiveDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLDirectiveDefinition: {Name}")]
public class GraphQLDirectiveDefinition : GraphQLTypeDefinition, IHasArgumentsDefinitionNode
{
internal 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 +43,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
12 changes: 12 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLEnumTypeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLEnumTypeDefinition: {Name}")]
public class GraphQLEnumTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode
{
internal 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
16 changes: 15 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLEnumValueDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLEnumValueDefinition: {EnumValue}")]
public class GraphQLEnumValueDefinition : GraphQLTypeDefinition, IHasDirectivesNode
{
internal 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 +30,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
12 changes: 12 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLEnumValuesDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLEnumValuesDefinition : ASTListNode<GraphQLEnumValueDefinition>
{
internal 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
15 changes: 14 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLExecutableDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@ namespace GraphQLParser.AST;
/// </summary>
public abstract class GraphQLExecutableDefinition : ASTNode, IHasSelectionSetNode, IHasDirectivesNode
{
internal 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
}
16 changes: 15 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLFieldDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLFieldDefinition: {Name}")]
public class GraphQLFieldDefinition : GraphQLTypeDefinition, IHasDirectivesNode, IHasArgumentsDefinitionNode
{
internal 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 +33,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
12 changes: 12 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLFieldsDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLFieldsDefinition : ASTListNode<GraphQLFieldDefinition>
{
internal 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
20 changes: 18 additions & 2 deletions src/GraphQLParser/AST/Definitions/GraphQLFragmentDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLFragmentDefinition: {FragmentName.Name.StringValue}")]
public class GraphQLFragmentDefinition : GraphQLExecutableDefinition
{
internal 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
12 changes: 12 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLInputFieldsDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLInputFieldsDefinition : ASTListNode<GraphQLInputValueDefinition>
{
internal 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,18 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLInputObjectTypeDefinition: {Name}")]
public class GraphQLInputObjectTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode
{
internal 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
16 changes: 15 additions & 1 deletion src/GraphQLParser/AST/Definitions/GraphQLInputValueDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ namespace GraphQLParser.AST;
/// </summary>
public class GraphQLInputValueDefinition : GraphQLTypeDefinition, IHasDirectivesNode, IHasDefaultValueNode
{
internal 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,18 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLInterfaceTypeDefinition: {Name}")]
public class GraphQLInterfaceTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode, IHasInterfacesNode, IHasFieldsDefinitionNode
{
internal 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
12 changes: 12 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLObjectTypeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLObjectTypeDefinition: {Name}")]
public class GraphQLObjectTypeDefinition : GraphQLTypeDefinition, IHasDirectivesNode, IHasInterfacesNode, IHasFieldsDefinitionNode
{
internal GraphQLObjectTypeDefinition()
{
}

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

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

Expand Down
12 changes: 12 additions & 0 deletions src/GraphQLParser/AST/Definitions/GraphQLOperationDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ namespace GraphQLParser.AST;
[DebuggerDisplay("GraphQLOperationDefinition: {Operation}")]
public class GraphQLOperationDefinition : GraphQLExecutableDefinition, INamedNode
{
internal GraphQLOperationDefinition()
{
}

/// <summary>
/// Creates a new instance of <see cref="GraphQLOperationDefinition"/>.
/// </summary>
public GraphQLOperationDefinition(GraphQLSelectionSet selectionSet)
: base(selectionSet)
{
}

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

Expand Down
Loading