Beispiel #1
0
        public void prints_multiple_interfaces_with_old_implements_syntax()
        {
            var root = new ObjectGraphType {
                Name = "Query"
            };

            root.Field <BarMultipleType>("bar");

            var schema = new Schema {
                Query = root
            };

            var options = new SchemaPrinterOptions()
            {
                OldImplementsSyntax = true
            };

            AssertEqual(print(schema, options), "", @"
interface Baaz {
  int: Int
}

type Bar implements Foo, Baaz {
  str: String
}

# The `Date` scalar type represents a year, month and day in accordance with the
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
scalar Date

# The `DateTime` scalar type represents a date and time. `DateTime` expects
# timestamps to be formatted in accordance with the
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
scalar DateTime

# The `DateTimeOffset` scalar type represents a date, time and offset from UTC.
# `DateTimeOffset` expects timestamps to be formatted in accordance with the
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
scalar DateTimeOffset

scalar Decimal

# This is a Foo interface type
interface Foo {
  str: String
}

# The `Milliseconds` scalar type represents a period of time represented as the total number of milliseconds.
scalar Milliseconds

type Query {
  bar: Bar
}

# The `Seconds` scalar type represents a period of time represented as the total number of seconds.
scalar Seconds

scalar Uri
", excludeScalars: true);
        }
Beispiel #2
0
    public void PrintObject_ReturnsEmptyString_GivenQueryTypeHasOnlyFederatedFields(string definitions, string expected)
    {
        // Arrange
        var schema = FederatedSchema.For(definitions);
        SchemaPrinterOptions options = default;

        schema.Initialize();

        var query = schema.Query;
        var federatedSchemaPrinter = new FederatedSchemaPrinter(schema, options);

        // Act
        string result = federatedSchemaPrinter.PrintObject(query);

        // Assert
        Assert.Equal(expected, result);
    }
Beispiel #3
0
        public void PrintObject_ReturnsEmptyString_GivenQueryTypeHasOnlyFederatedFields()
        {
            // Arrange
            var schema = FederatedSchema.For(@"type X @key(fields: ""id"") { id: ID! }");
            SchemaPrinterOptions options = default;

            schema.Initialize();

            var query = schema.Query;
            var federatedSchemaPrinter = new FederatedSchemaPrinter(schema, options);

            // Act
            string result = federatedSchemaPrinter.PrintObject(query);

            // Assert
            Assert.Equal(string.Empty, result);
        }
        public void prints_multiple_interfaces_with_field_descriptions()
        {
            var root = new ObjectGraphType {
                Name = "Query"
            };

            root.Field <BarMultipleType>("bar");

            var schema = new Schema {
                Query = root
            };

            var options = new SchemaPrinterOptions
            {
                IncludeDescriptions = true
            };

            var result = print(schema, options);

            AssertEqual(result, "", @"
interface Baaz {
  # This is of type Integer
  int: Int
}

type Bar implements IFoo & Baaz {
  # This is of type String
  str: String
  # This is of type Integer
  int: Int
}

# This is a Foo interface type
interface IFoo {
  # This is of type String
  str: String
}

type Query {
  bar: Bar
}
", excludeScalars: true);
        }
        public void prints_object_field_with_field_descriptions_and_deprecation_reasons()
        {
            var root = new ObjectGraphType {
                Name = "Query"
            };

            root.Field <FooType>("foo");

            var schema = new Schema {
                Query = root
            };

            var options = new SchemaPrinterOptions
            {
                IncludeDescriptions       = true,
                IncludeDeprecationReasons = true
            };

            var expected = new Dictionary <string, string>
            {
                {
                    "Foo",
                    @"# This is a Foo object type
type Foo {
  # This is of type String
  str: String
  # This is of type Integer
  int: Int
}".Replace("int: Int", "int: Int @deprecated(reason: \"This field is now deprecated\")")
                },
                {
                    "Query",
                    @"type Query {
  foo: Foo
}"
                },
            };
            var result = print(schema, options);

            AssertEqual(result, expected);
        }
        public void prints_object_field_with_field_descriptions()
        {
            var root = new ObjectGraphType {
                Name = "Query"
            };

            root.Field <FooType>("foo");

            var schema = new Schema {
                Query = root
            };

            var options = new SchemaPrinterOptions
            {
                IncludeDescriptions = true
            };

            var expected = new Dictionary <string, string>
            {
                {
                    "Foo",
                    @"# This is a Foo object type
type Foo {
  # This is of type String
  str: String
  # This is of type Integer
  int: Int
}"
                },
                {
                    "Query",
                    @"type Query {
  foo: Foo
}"
                },
            };

            AssertEqual(print(schema, options), expected);
        }
Beispiel #7
0
 public GraphQLEngine BuildSchema(SchemaPrinterOptions options, params System.Type[] types)
 {
     if (_schema != null)
     {
         return(this);
     }
     if (types.Length > 0)
     {
         _schemaTypes.AddRange(types);
     }
     lock (_schemaLock)
         _schema = _constructor.Build(_schemaTypes.ToArray());
     _schemaPrinter = new SchemaPrinter(_schema, options ?? new SchemaPrinterOptions
     {
         CustomScalars = new List <string>
         {
             TypeNames.Url, TypeNames.Uri, TypeNames.TimeSpan,
             TypeNames.Guid
         },
         IncludeDescriptions       = _includeFieldDescriptions,
         IncludeDeprecationReasons = _includeFieldDeprecationReasons,
     });
     return(this);
 }
        public void prints_multiple_interfaces_with_field_descriptions()
        {
            var root = new ObjectGraphType {
                Name = "Query"
            };

            root.Field <BarMultipleType>("bar");

            var schema = new Schema {
                Query = root
            };

            var options = new SchemaPrinterOptions
            {
                IncludeDescriptions = true
            };

            var result = print(schema, options);

            AssertEqual(result, "", @"
interface Baaz {
  # This is of type Integer
  int: Int
}

type Bar implements IFoo & Baaz {
  # This is of type String
  str: String
  # This is of type Integer
  int: Int
}

scalar BigInt

scalar Byte

# The `Date` scalar type represents a year, month and day in accordance with the
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
scalar Date

# The `DateTime` scalar type represents a date and time. `DateTime` expects
# timestamps to be formatted in accordance with the
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
scalar DateTime

# The `DateTimeOffset` scalar type represents a date, time and offset from UTC.
# `DateTimeOffset` expects timestamps to be formatted in accordance with the
# [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) standard.
scalar DateTimeOffset

scalar Decimal

scalar Guid

# This is a Foo interface type
interface IFoo {
  # This is of type String
  str: String
}

scalar Long

# The `Milliseconds` scalar type represents a period of time represented as the total number of milliseconds.
scalar Milliseconds

type Query {
  bar: Bar
}

scalar SByte

# The `Seconds` scalar type represents a period of time represented as the total number of seconds.
scalar Seconds

scalar Short

scalar UInt

scalar ULong

scalar UShort

scalar Uri
", excludeScalars: true);
        }
        private string print(ISchema schema, SchemaPrinterOptions options)
        {
            var printer = new SchemaPrinter(schema, options);

            return(Environment.NewLine + printer.Print());
        }
 public FederatedSchemaPrinter(ISchema schema, SchemaPrinterOptions options = null)
     : base(schema, options)
 {
     _converter = new CoreToVanillaConverter("");
 }
Beispiel #11
0
 public FederatedSchemaPrinter(ISchema schema, SchemaPrinterOptions options = null)
     : base(schema, options)
 {
 }