public async Task Get_ActivePersistedQuery_AddQuery() { // arrange TestServer server = CreateStarWarsServer(); DocumentNode document = Utf8GraphQLParser.Parse("{ __typename }"); var hashProvider = new MD5DocumentHashProvider(); string hash = hashProvider.ComputeHash( Encoding.UTF8.GetBytes(document.ToString(false))); // act ClientQueryResult resultA = await server.GetStoreActivePersistedQueryAsync( document.ToString(false), "md5Hash", hash); ClientQueryResult resultB = await server.GetActivePersistedQueryAsync("md5Hash", hash); // assert new[] { resultA, resultB }.MatchSnapshot(); }
public string Print() { var operation = Definition.WithSelectionSet(Visit(RootSelectionSet)); var document = new DocumentNode(new[] { operation }); return(document.ToString()); }
private void LogError(EventId eventId, Exception exception, DocumentNode?document = null, IVariableValueCollection?variables = null, IObjectField?field = null) { using var scope = _logger.BeginScope(new { Resolver = field != null ? $"{field.DeclaringType.Name}.{field.Name}" : null, Document = document?.ToString().Replace("\n", Environment.NewLine), Variables = variables != null ? string.Join(Environment.NewLine, variables.Select(x => $"{x.Name}: {x.Value}")) : null }); if (field != null) { _logger.LogWarning( eventId, exception, "GraphQL exception in field {Name}", $"{field.DeclaringType.Name}.{field.Name}" ); } else { _logger.LogWarning( eventId, exception, "GraphQL exception" ); } SentrySdk.CaptureException(exception); }
public void Serialize_InterfaceTypeDefWithIndent_OutHasIndentation() { // arrange string schema = "interface Foo { bar: String baz: [Int] }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(); // assert result.MatchSnapshot(); }
public void Serialize_InputObjectTypeDefNoIndent_OutHasIndentation() { // arrange string schema = "input A { b: String c: [String!]! d: Int = 1 }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert result.MatchSnapshot(); }
public void Serialize_InputObjectTypeDefNoIndent_InOutShouldBeTheSame() { // arrange string schema = "input A { b: String c: [String!]! d: Int = 1 }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_ObjectTypeDefNoIndent_InOutShouldBeTheSame() { // arrange string schema = "type Foo { bar: String baz: [Int] }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_SchemaDefWithOpAndDirecNoIndent_OutHasIndentation() { // arrange string schema = "schema @a @b(c: 1) { query: A }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert result.MatchSnapshot(); }
public void Serialize_ScalarTypeDefWithDescIndent_OutHasIndentation() { // arrange string schema = "\"abc\" scalar A @a @b(c: 1)"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(); // assert result.MatchSnapshot(); }
public void Serialize_EnumTypeWithDirectiveDefNoIndent_OutHasIndentation() { // arrange string schema = "enum A @a @b(c: 1) { B @a @b(c: 1) C @a @b(c: 1) }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert result.MatchSnapshot(); }
public void Serialize_EnumTypeDefWithDirectiveNoIndent_InOutShouldBeTheSame() { // arrange string schema = "enum A @a @b(c: 1) { B @a @b(c: 1) C @a @b(c: 1) }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_UnionTypeWithDirectiveDefNoIndent_OutHasIndentation() { // arrange string schema = "union A @a = B | C union A @a @b = B | C"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert result.MatchSnapshot(); }
public void Serialize_UnionTypeDefWithDirectiveNoIndent_InOutShouldBeTheSame() { // arrange string schema = "union A @a = B | C union A @a @b = B | C"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_InterfaceTypeExtensionDef_InOutShouldBeTheSame() { // arrange string schema = "extend interface Foo { bar: String baz: [Int] }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_InterfaceTypeDefWithArgsNoIndent_InOutShouldBeTheSame() { // arrange string schema = "interface Foo { bar(a: Int = 1 b: Int): String }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_InputObjectTypeDefWithDescriptionNoIndentt_OutHasIndentation() { // arrange string schema = "\"abc\" input A { \"abc\" b: String }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert result.MatchSnapshot(); }
public void Serialize_ScalarTypeDefWithDescNoIndent_InOutShouldBeTheSame() { // arrange string schema = "\"abc\" scalar A @a @b(c: 1)"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_EnumTypeDefWithDescriptionNoIndent_InOutShouldBeTheSame() { // arrange string schema = "\"abc\" enum A { \"def\" B \"ghi\" C }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_SchemaDefWithOpAndDirecNoIndent_InOutShouldBeTheSame() { // arrange string schema = "schema @a @b(c: 1) { query: A }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_ObjectTypeDefWithArgsWithIndent_OutHasIndentation() { // arrange string schema = "type Foo { bar(a: Int = 1 b: Int): String }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(); // assert result.MatchSnapshot(); }
public void Serialize_SchemaTypeExtensionDef_InOutShouldBeTheSame() { // arrange string schema = "extend schema { query: A }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_EnumTypeDefWithDescriptionNoIndented_OutHasIndentation() { // arrange string schema = "\"abc\" enum A { \"def\" B \"ghi\" C }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert result.MatchSnapshot(); }
public void Serialize_InputObjectTypeDefWithDescriptionNoIndent_InOutShouldBeTheSame() { // arrange string schema = "\"abc\" input A { \"abc\" b: String }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_KitchenSinkWithIndentation_CanBeParsed() { // arrange string query = FileResource.Open("kitchen-sink.graphql"); DocumentNode queryDocument = Utf8GraphQLParser.Parse(query); // act string result = queryDocument.ToString(); // assert result.MatchSnapshot(); }
public void Serialize_ShortHandQueryWithIndentation_LineBetweenFields() { // arrange string query = "{ foo { foo bar { foo @foo @bar bar @bar baz } } }"; DocumentNode queryDocument = Utf8GraphQLParser.Parse(query); // act string result = queryDocument.ToString(); // assert result.MatchSnapshot(); }
public void Serialize_ObjectTypeImplementsXYZWithIndent_OutHasIndentation() { // arrange string schema = "type Foo implements X & Y & Z " + "{ bar: String baz: [Int] }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(); // assert result.MatchSnapshot(); }
public void Serialize_InterfaceTypeImplementsXYZ_InOutShouldBeTheSame() { // arrange string schema = "interface Foo implements X & Y & Z " + "{ bar: String baz: [Int] }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }
public void Serialize_ShortHandQueryNoIndentation_InOutShouldBeTheSame() { // arrange var query = "{ foo(s: \"String\") { bar @foo " + "{ baz @foo @bar } } }"; DocumentNode queryDocument = Utf8GraphQLParser.Parse(query); // act string result = queryDocument.ToString(false); // assert Assert.Equal(query, result); }
public void Serialize_FragmentWithVariableDefs_InOutShouldBeTheSame() { // arrange string query = "fragment Foo ($bar: [String!]!) on Bar { baz }"; DocumentNode queryDocument = Utf8GraphQLParser.Parse(query, new ParserOptions(allowFragmentVariables: true)); // act string result = queryDocument.ToString(false); // assert Assert.Equal(query, result); }
public void Serialize_InputObjectTypeDefWithDirectiveNoIndent_InOutShouldBeTheSame() { // arrange string schema = "input A @a @b(c: 1) { b: String @a @b(c: 1) " + "c: [String!]! @a @b(c: 1) d: Int = 1 @a @b(c: 1) }"; DocumentNode document = Utf8GraphQLParser.Parse(schema); // act string result = document.ToString(false); // assert Assert.Equal(schema, result); }