public void AddDirectiveWithArgument()
        {
            // arrange
            var descriptor = EnumTypeDescriptor.New(Context);

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Directive("Bar",
                           new ArgumentNode("a", new StringValueNode("b")));

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Directives,
                              t =>
            {
                Assert.Equal("Bar", t.ParsedDirective.Name.Value);
                Assert.Collection(t.ParsedDirective.Arguments,
                                  x =>
                {
                    Assert.Equal("a", x.Name.Value);
                    Assert.IsType <StringValueNode>(x.Value);
                    Assert.Equal("b", ((StringValueNode)x.Value).Value);
                });
            });
        }
        private static void DeclareValues(
            IEnumTypeDescriptor typeDescriptor,
            IReadOnlyCollection <EnumValueDefinitionNode> values)
        {
            foreach (EnumValueDefinitionNode value in values)
            {
                IEnumValueDescriptor valueDescriptor =
                    typeDescriptor.Value(value.Name.Value)
                    .Description(value.Description?.Value);

                string deprecactionReason = value.DeprecationReason();
                if (!string.IsNullOrEmpty(deprecactionReason))
                {
                    valueDescriptor.Deprecated(deprecactionReason);
                }

                foreach (DirectiveNode directive in value.Directives)
                {
                    if (!directive.IsDeprecationReason())
                    {
                        valueDescriptor.Directive(directive);
                    }
                }
            }
        }
 protected override void Configure(
     IEnumTypeDescriptor <Foo> descriptor)
 {
     descriptor.BindValues(BindingBehavior.Explicit);
     descriptor.Value(Foo.Bar);
     descriptor.Value(Foo.Baz);
 }
Example #4
0
        protected override void Configure(IEnumTypeDescriptor <GeoJsonGeometryType> descriptor)
        {
            descriptor
            .Name(EnumTypeTypeName)
            .BindValuesExplicitly();

            descriptor
            .Value(Point)
            .Name(nameof(Point));

            descriptor
            .Value(MultiPoint)
            .Name(nameof(MultiPoint));

            descriptor
            .Value(LineString)
            .Name(nameof(LineString));

            descriptor
            .Value(MultiLineString)
            .Name(nameof(MultiLineString));

            descriptor
            .Value(Polygon)
            .Name(nameof(Polygon));

            descriptor
            .Value(MultiPolygon)
            .Name(nameof(MultiPolygon));

            descriptor
            .Value(GeometryCollection)
            .Name(nameof(GeometryCollection));
        }
Example #5
0
        private static void DeclareValues(
            IEnumTypeDescriptor typeDescriptor,
            IReadOnlyCollection <EnumValueDefinitionNode> values)
        {
            foreach (EnumValueDefinitionNode value in values)
            {
                IEnumValueDescriptor valueDescriptor =
                    typeDescriptor
                    .Value(value.Name.Value)
                    .Description(value.Description?.Value)
                    .Name(value.Name.Value);

                if (value.DeprecationReason() is { Length: > 0 } s)
                {
                    valueDescriptor.Deprecated(s);
                }

                foreach (DirectiveNode directive in value.Directives)
                {
                    if (!directive.IsDeprecationReason())
                    {
                        valueDescriptor.Directive(directive);
                    }
                }
            }
        }
Example #6
0
        protected override void Configure(IEnumTypeDescriptor <TypeKind> descriptor)
        {
            descriptor.Name("__TypeKind");

            descriptor.Description(TypeResources.TypeKind_Description);

            descriptor.Item(TypeKind.Scalar)
            .Description(TypeResources.TypeKind_Scalar);

            descriptor.Item(TypeKind.Object)
            .Description(TypeResources.TypeKind_Object);

            descriptor.Item(TypeKind.Interface)
            .Description(TypeResources.TypeKind_Interface);

            descriptor.Item(TypeKind.Union)
            .Description(TypeResources.TypeKind_Union);

            descriptor.Item(TypeKind.Enum)
            .Description(TypeResources.TypeKind_Enum);

            descriptor.Item(TypeKind.InputObject)
            .Name("INPUT_OBJECT")
            .Description(TypeResources.TypeKind_InputObject);

            descriptor.Item(TypeKind.List)
            .Description(TypeResources.TypeKind_List);

            descriptor.Item(TypeKind.NonNull)
            .Name("NON_NULL")
            .Description(TypeResources.TypeKind_NonNull);
        }
 protected override void Configure(IEnumTypeDescriptor <ControllerElementType> descriptor)
 {
     descriptor.Name("ControllerElementType")
     .Description("Stone-defined semantic types for Controller Elements." +
                  "Specifies the semantics of a specific element on a controller layout.")
     .BindValues(BindingBehavior.Implicit);
 }
        public void SpecifyOneValueInferTheOthers()
        {
            // arrange
            var descriptor = EnumTypeDescriptor.New(Context, typeof(FooEnum));

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Item(FooEnum.Bar1).Name("FOOBAR");

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Values,
                              t =>
            {
                Assert.Equal("FOOBAR", t.Name);
                Assert.Equal(FooEnum.Bar1, t.Value);
            },
                              t =>
            {
                Assert.Equal("BAR2", t.Name);
                Assert.Equal(FooEnum.Bar2, t.Value);
            });
        }
Example #9
0
 public override void OnConfigure(
     IDescriptorContext context,
     IEnumTypeDescriptor descriptor,
     Type type)
 {
     descriptor.Name("Abc");
 }
Example #10
0
 protected override void Configure(IEnumTypeDescriptor <ControllerElement> descriptor)
 {
     descriptor.Name("ControllerElement")
     .Description("Stone-defined semantic Controller Elements. " +
                  "A Controller Element is a semantic name given to a capability of a defined Stone controller layout.")
     .BindValues(BindingBehavior.Implicit);
 }
Example #11
0
 public EnumTypeNameDependencyDescriptor(
     IEnumTypeDescriptor descriptor,
     Func <INamedType, NameString> createName)
 {
     _descriptor = descriptor
                   ?? throw new ArgumentNullException(nameof(descriptor));
     _createName = createName
                   ?? throw new ArgumentNullException(nameof(createName));
 }
Example #12
0
 private void DeclareValues(
     IEnumTypeDescriptor typeDescriptor,
     IReadOnlyCollection <EnumValueDefinitionNode> values)
 {
     foreach (EnumValueDefinitionNode value in values)
     {
         typeDescriptor.Item(value.Name.Value);
     }
 }
Example #13
0
        protected override void Configure(IEnumTypeDescriptor <Episode> descriptor)
        {
            descriptor
            .Name("Episode")
            .Description("One of the films in the Star Wars Trilogy.");

            descriptor.Value(Episode.NEWHOPE).Description("Released in 1977.");
            descriptor.Value(Episode.EMPIRE).Description("Released in 1980.");
            descriptor.Value(Episode.JEDI).Description("Released in 1983.");
        }
Example #14
0
 public override void OnConfigure(
     IDescriptorContext context,
     IEnumTypeDescriptor descriptor,
     Type type)
 {
     if (!string.IsNullOrEmpty(Name))
     {
         descriptor.Name(Name);
     }
 }
 protected override void Configure(IEnumTypeDescriptor <EmulatorCompatibility> descriptor)
 {
     descriptor.Name("EmulatorCompatibility")
     .Description("Describes the levels of compatibility an emulator has with a given game.");
     descriptor.Value(EmulatorCompatibility.Unsupported)
     .Description("This game is not supported by this emulator.");
     descriptor.Value(EmulatorCompatibility.MissingSystemFiles)
     .Description("The system files required to run this game are not available.");
     descriptor.Value(EmulatorCompatibility.RequiresValidation)
     .Description("The game has the files required to be run, but they are not in the correct format. " +
                  "Validation should be run before launching this game.");
     descriptor.Value(EmulatorCompatibility.Ready)
     .Description("This game is supported and ready to be run, requiring no validation. ");
 }
        protected override void Configure(IEnumTypeDescriptor <GameEmulationState> descriptor)
        {
            descriptor.Name("GameEmulationState")
            .Description("Describes the state of a game emulation.");
            descriptor.Value(GameEmulationState.RequiresSetupEnvironment)
            .Description(
                @"This game emulation requires environment setup. The following mutations may occur.

* `setupEmulationEnvironment`
* `cleanupEmulation`
");
            descriptor.Value(GameEmulationState.RequiresCompileConfiguration)
            .Description(
                @"The game emulation requires configuration to be compiled. The following mutations may occur.

* `compileEmulationConfiguration`
* `cleanupEmulation`
");
            descriptor.Value(GameEmulationState.RequiresRestoreSaveGame)
            .Description(
                @"The game emulation requires the save game to be restored. The following mutations may occur.

* `restoreEmulationSave`
* `cleanupEmulation`
");
            descriptor.Value(GameEmulationState.CanStartEmulation)
            .Description(
                @"The game emulation can be started. The following mutations may occur.

* `persistEmulationSave`
* `startEmulation`
* `cleanupEmulation`
");
            descriptor.Value(GameEmulationState.CanStopEmulation)
            .Description(
                @"The game emulation is running, and can be stopped. The following mutations may occur.

* `persistEmulationSave`
* `stopEmulation`
* `cleanupEmulation` will immediately stop the emulation and cleanup.
");
            descriptor.Value(GameEmulationState.RequiresDispose)
            .Description(
                @"The game emulation has been stopped, and needs cleanup. The following mutations may occur.

* `persistEmulationSave`
* `cleanupEmulation`
");
        }
Example #17
0
        protected override void Configure(IEnumTypeDescriptor <TypeKind> descriptor)
        {
            descriptor
            .Name(Names.__TypeKind)
            .Description(TypeResources.TypeKind_Description)
            // Introspection types must always be bound explicitly so that we
            // do not get any interference with conventions.
            .BindItems(BindingBehavior.Explicit);

            descriptor
            .Item(TypeKind.Scalar)
            .Name(Names.Scalar)
            .Description(TypeResources.TypeKind_Scalar);

            descriptor
            .Item(TypeKind.Object)
            .Name(Names.Object)
            .Description(TypeResources.TypeKind_Object);

            descriptor
            .Item(TypeKind.Interface)
            .Name(Names.Interface)
            .Description(TypeResources.TypeKind_Interface);

            descriptor
            .Item(TypeKind.Union)
            .Name(Names.Union)
            .Description(TypeResources.TypeKind_Union);

            descriptor
            .Item(TypeKind.Enum)
            .Name(Names.Enum)
            .Description(TypeResources.TypeKind_Enum);

            descriptor
            .Item(TypeKind.InputObject)
            .Name(Names.InputObject)
            .Description(TypeResources.TypeKind_InputObject);

            descriptor
            .Item(TypeKind.List)
            .Name(Names.List)
            .Description(TypeResources.TypeKind_List);

            descriptor
            .Item(TypeKind.NonNull)
            .Name(Names.NonNull)
            .Description(TypeResources.TypeKind_NonNull);
        }
    protected override void Configure(
        IEnumTypeDescriptor <ApplyPolicy> descriptor)
    {
        descriptor
        .Name("ApplyPolicy")
        .BindValuesExplicitly();

        descriptor
        .Value(ApplyPolicy.BeforeResolver)
        .Name("BEFORE_RESOLVER");

        descriptor
        .Value(ApplyPolicy.AfterResolver)
        .Name("AFTER_RESOLVER");
    }
Example #19
0
        protected override void Configure(
            IEnumTypeDescriptor <ExecuteResolver> descriptor)
        {
            descriptor
            .Name("ExecuteResolver")
            .BindValuesExplicitly();

            descriptor
            .Value(ExecuteResolver.AfterPolicy)
            .Name("AFTER_POLICY");

            descriptor
            .Value(ExecuteResolver.BeforePolicy)
            .Name("BEFORE_POLICY");
        }
        public static IEnumTypeDescriptor <TEnum> UseNamesAsValues <TEnum>(this IEnumTypeDescriptor <TEnum> descriptor)
        {
            var enumType = typeof(TEnum);

            foreach (var field in typeof(TEnum).GetFields())
            {
                if (field.Name == EnumDefaultFieldName)
                {
                    continue;
                }

                descriptor.Item((TEnum)Enum.ToObject(enumType, field.GetRawConstantValue())).Name(field.Name);
            }

            return(descriptor);
        }
        private void DeclareValues(
            IEnumTypeDescriptor typeDescriptor,
            IReadOnlyCollection <EnumValueDefinitionNode> values)
        {
            foreach (EnumValueDefinitionNode value in values)
            {
                IEnumValueDescriptor valueDescriptor =
                    typeDescriptor.Item(value.Name.Value);

                string deprecactionReason = value.DeprecationReason();
                if (!string.IsNullOrEmpty(deprecactionReason))
                {
                    valueDescriptor.DeprecationReason(deprecactionReason);
                }
            }
        }
Example #22
0
        protected override void Configure(IEnumTypeDescriptor <PathType> descriptor)
        {
            descriptor.Name("PathType")
            .Description("If the option is a PATH option, the type of path the option accepts as values.");

            descriptor.Value(PathType.Either)
            .Description("A contextual path that points to either a directory or a file.");
            descriptor.Value(PathType.File)
            .Description("A contextual path that points to a file.");
            descriptor.Value(PathType.Directory)
            .Description("A contextual path that points to a directory.");
            descriptor.Value(PathType.NotPath)
            .Description("Not a path.");
            descriptor.Value(PathType.Raw)
            .Description("A raw, operating-system dependent path on the realized filesystem.");
        }
Example #23
0
        public void AddDirective()
        {
            // arrange
            var descriptor = new EnumTypeDescriptor("Foo");

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Directive("Bar");

            // assert
            EnumTypeDescription description = descriptor.CreateDescription();

            Assert.Collection(description.Directives,
                              t => Assert.Equal("Bar", t.ParsedDirective.Name.Value));
        }
        public void AddDirectiveWithDirectiveNode()
        {
            // arrange
            var descriptor = EnumTypeDescriptor.New(Context);

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Directive(new DirectiveNode("Bar"));

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Directives,
                              t => Assert.Equal("Bar", t.ParsedDirective.Name.Value));
        }
Example #25
0
        /// <summary>
        /// Ignores the given enum value for the schema creation.
        /// This enum will not be included into the GraphQL schema.
        /// </summary>
        /// <param name="descriptor">
        /// The enum type descriptor.
        /// </param>
        /// <param name="value">
        /// The enum value that shall be ignored.
        /// </param>
        /// <typeparam name="T">
        /// The enum value type.
        /// </typeparam>
        /// <returns>
        /// Returns the enum type descriptor for configuration chaining.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="descriptor"/> is <c>null</c> or
        /// <paramref name="value"/> is <c>null</c>.
        /// </exception>
        public static IEnumTypeDescriptor Ignore <T>(
            this IEnumTypeDescriptor descriptor,
            T value)
        {
            if (descriptor is null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            descriptor.Value(value).Ignore();
            return(descriptor);
        }
        public static IEnumTypeNameDependencyDescriptor <T> Name <T>(
            this IEnumTypeDescriptor <T> descriptor,
            Func <INamedType, NameString> createName)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (createName == null)
            {
                throw new ArgumentNullException(nameof(createName));
            }

            return(new EnumTypeNameDependencyDescriptor <T>(
                       descriptor, createName));
        }
        public void ExplicitValueBinding()
        {
            // arrange
            var descriptor = EnumTypeDescriptor.New(Context, typeof(FooEnum));

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Item(FooEnum.Bar1).Name("FOOBAR");
            desc.BindItems(BindingBehavior.Explicit);

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Values,
                              t =>
            {
                Assert.Equal("FOOBAR", t.Name);
                Assert.Equal(FooEnum.Bar1, t.Value);
            });
        }
Example #28
0
        protected override void Configure(IEnumTypeDescriptor <TypeKind> descriptor)
        {
            descriptor.Name("__TypeKind");

            descriptor.Description(
                "An enum describing what kind of type a given `__Type` is.");

            descriptor.Item(TypeKind.Scalar)
            .Description("Indicates this type is a scalar.");

            descriptor.Item(TypeKind.Object)
            .Description("Indicates this type is an object. " +
                         "`fields` and `interfaces` are valid fields.");

            descriptor.Item(TypeKind.Interface)
            .Description("Indicates this type is an interface. " +
                         "`fields` and `possibleTypes` are valid fields.");

            descriptor.Item(TypeKind.Union)
            .Description("Indicates this type is a union. " +
                         "`possibleTypes` is a valid field.");

            descriptor.Item(TypeKind.Enum)
            .Description("Indicates this type is an enum. " +
                         "`enumValues` is a valid field.");

            descriptor.Item(TypeKind.InputObject)
            .Name("INPUT_OBJECT")
            .Description("Indicates this type is an input object. " +
                         "`inputFields` is a valid field.");

            descriptor.Item(TypeKind.List)
            .Description("Indicates this type is a list. " +
                         "`ofType` is a valid field.");

            descriptor.Item(TypeKind.NonNull)
            .Name("NON_NULL")
            .Description("Indicates this type is a non-null. " +
                         "`ofType` is a valid field.");
        }
 protected override void Configure(IEnumTypeDescriptor <AccountTypeEnum> descriptor)
 {
     descriptor.Name("AccountTypeEnum");
     descriptor.Description("Enumeration for the account type object.");
 }
Example #30
0
 protected override void Configure(IEnumTypeDescriptor descriptor)
 {
     descriptor.Value("RED");
     descriptor.Value("BLUE");
     descriptor.Value("GREEN");
 }