Skip to content

Commit

Permalink
Add test for deprecations on args and input fields (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored Apr 9, 2023
1 parent 594a0e2 commit 83b4306
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/GraphQLParser.Tests/Files/DeprecatedOnArgAndInputField.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Query {
persons(filter: PersonFilter @deprecated(reason: "Do not use this arg")): [Person]
}

input PersonFilter {
namePattern: String @deprecated(reason: "Do not use this field")
}

type Person {
name: String
}
22 changes: 22 additions & 0 deletions src/GraphQLParser.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,4 +1679,26 @@ directive @TestDirective (
if (parseComments)
directiveDef.Arguments[0].Comment.Value.ShouldBe(" comment 29");
}

// https://github.com/graphql/graphql-spec/pull/805
[Fact]
public void Should_Parse_Deprecations_On_Arg_And_InputField()
{
string text = "DeprecatedOnArgAndInputField".ReadGraphQLFile();
var document = text.Parse();

var queryDef = document.Definitions.First(x => x is GraphQLObjectTypeDefinition) as GraphQLObjectTypeDefinition;
queryDef.Name.Value.ShouldBe("Query");
var arg = queryDef.Fields[0].Arguments[0];
var dir1 = arg.Directives.ShouldNotBeNull()[0];
dir1.Name.Value.ShouldBe("deprecated");
dir1.Arguments.ShouldNotBeNull()[0].Value.ShouldBeAssignableTo<GraphQLStringValue>().Value.ShouldBe("Do not use this arg");

var inputDef = document.Definitions.First(x => x is GraphQLInputObjectTypeDefinition) as GraphQLInputObjectTypeDefinition;
inputDef.Name.Value.ShouldBe("PersonFilter");
var field = inputDef.Fields[0].ShouldNotBeNull();
var dir2 = field.Directives.ShouldNotBeNull()[0];
dir2.Name.Value.ShouldBe("deprecated");
dir2.Arguments.ShouldNotBeNull()[0].Value.ShouldBeAssignableTo<GraphQLStringValue>().Value.ShouldBe("Do not use this field");
}
}

0 comments on commit 83b4306

Please sign in to comment.