Beispiel #1
0
        protected override void Configure(IDirectiveTypeDescriptor <AuthorizeDirective> descriptor)
        {
            descriptor
            .Name("authorize")
            .Location(DirectiveLocation.Schema)
            .Location(DirectiveLocation.Object)
            .Location(DirectiveLocation.FieldDefinition)
            .Repeatable();

            descriptor.Argument(t => t.Policy)
            .Description(
                "The name of the authorization policy that determines " +
                "access to the annotated resource.")
            .Type <StringType>();

            descriptor.Argument(t => t.Roles)
            .Description(
                "Roles that are allowed to access the " +
                "annotated resource.")
            .Type <ListType <NonNullType <StringType> > >();

            descriptor.Argument(t => t.Apply)
            .Description(
                "Defines when when the resolver shall be executed." +
                "By default the resolver is executed after the policy " +
                "has determined that the current user is allowed to access " +
                "the field.")
            .Type <NonNullType <ApplyPolicyType> >()
            .DefaultValue(ApplyPolicy.BeforeResolver);

            descriptor.Use <AuthorizeMiddleware>();
        }
Beispiel #2
0
        protected override void Configure(
            IDirectiveTypeDescriptor <SourceDirective> descriptor)
        {
            descriptor.Name(DirectiveNames.Source)
            .Description(StitchingResources
                         .SourceDirectiveType_Description);

            descriptor.Location(DirectiveLocation.Enum)
            .Location(DirectiveLocation.Object)
            .Location(DirectiveLocation.Interface)
            .Location(DirectiveLocation.Union)
            .Location(DirectiveLocation.InputObject)
            .Location(DirectiveLocation.FieldDefinition)
            .Location(DirectiveLocation.InputFieldDefinition)
            .Location(DirectiveLocation.ArgumentDefinition)
            .Location(DirectiveLocation.EnumValue);

            descriptor.Repeatable();

            descriptor.Argument(t => t.Name)
            .Name(DirectiveFieldNames.Source_Name)
            .Type <NonNullType <NameType> >()
            .Description(StitchingResources
                         .SourceDirectiveType_Name_Description);

            descriptor.Argument(t => t.Schema)
            .Name(DirectiveFieldNames.Source_Schema)
            .Type <NonNullType <NameType> >()
            .Description(StitchingResources
                         .SourceDirectiveType_Schema_Description);
        }
    protected override void Configure(IDirectiveTypeDescriptor <StreamDirective> descriptor)
    {
        descriptor
        .Name(Names.Stream)
        .Description(TypeResources.StreamDirectiveType_Description)
        .Location(DirectiveLocation.Field);

        descriptor
        .Argument(t => t.Label)
        .Name(Names.Label)
        .Description(TypeResources.StreamDirectiveType_Label_Description)
        .Type <StringType>();

        descriptor
        .Argument(t => t.InitialCount)
        .Name(Names.InitialCount)
        .Description(TypeResources.StreamDirectiveType_InitialCount_Description)
        .Type <NonNullType <IntType> >()
        .DefaultValue(0);

        descriptor
        .Argument(t => t.If)
        .Name(Names.If)
        .Description(TypeResources.StreamDirectiveType_If_Description)
        .Type <BooleanType>();
    }
        protected override void Configure(IDirectiveTypeDescriptor <CostDirective> descriptor)
        {
            descriptor
            .Name("cost")
            .Description(
                "The cost directives is used to express the complexity " +
                "of a field.")
            .Location(DirectiveLocation.FieldDefinition);

            descriptor
            .Argument(t => t.Complexity)
            .Name("complexity")
            .Description("Defines the complexity of the field.")
            .Type <NonNullType <IntType> >()
            .DefaultValue(1);

            descriptor
            .Argument(t => t.Multipliers)
            .Name("multipliers")
            .Description(
                "Defines field arguments that act as " +
                "complexity multipliers.")
            .Type <ListType <NonNullType <MultiplierPathType> > >();

            descriptor
            .Argument(t => t.DefaultMultiplier)
            .Name("defaultMultiplier")
            .Type <IntType>();
        }
        protected override void Configure(
            IDirectiveTypeDescriptor <AuthorizeDirective> descriptor)
        {
            descriptor.Name("authorize");

            descriptor.Location(DirectiveLocation.Object)
            .Location(DirectiveLocation.FieldDefinition);

#if !ASPNETCLASSIC
            // TODO :resources
            descriptor.Argument(t => t.Policy)
            .Description(
                "The name of the authorzation policy that determines " +
                "access to the annotated resource.")
            .Type <StringType>();
#endif

            // TODO :resources
            descriptor.Argument(t => t.Roles)
            .Description(
                "Roles that are allowed to access to the " +
                "annotated resource.")
            .Type <ListType <NonNullType <StringType> > >();

            descriptor.Repeatable();

            descriptor.Use <AuthorizeMiddleware>();
        }
        protected override void Configure(IDirectiveTypeDescriptor <PagingDirective> descriptor)
        {
            descriptor
            .Name("paging")
            .Location(DirectiveLocation.Object | DirectiveLocation.Schema);

            descriptor
            .Argument(t => t.Kind)
            .Type <PagingKindType>();

            descriptor
            .Argument(t => t.DefaultPageSize)
            .Type <IntType>()
            .DefaultValue(10);

            descriptor
            .Argument(t => t.MaxPageSize)
            .Type <IntType>()
            .DefaultValue(50);

            descriptor
            .Argument(t => t.IncludeTotalCount)
            .Type <BooleanType>()
            .DefaultValue(false);
        }
 protected override void Configure(
     IDirectiveTypeDescriptor <RuntimeTypeDirective> descriptor)
 {
     descriptor.Name("runtimeType");
     descriptor.Argument(t => t.Name).Type <NonNullType <StringType> >();
     descriptor.Argument(t => t.ValueType).Type <BooleanType>();
     descriptor.Location(DirectiveLocation.Scalar);
 }
 protected override void Configure(
     IDirectiveTypeDescriptor <SerializationDirective> descriptor)
 {
     descriptor.Name("serialization");
     descriptor.Argument(t => t.ClrType).Type <NonNullType <StringType> >();
     descriptor.Argument(t => t.SerializationType).Type <NonNullType <StringType> >();
     descriptor.Location(DirectiveLocation.Field);
 }
        protected override void Configure(IDirectiveTypeDescriptor <TypeNameDirective> descriptor)
        {
            descriptor
            .Name("typeName")
            .Location(DirectiveLocation.Object);

            descriptor
            .Argument(t => t.Name)
            .Type <NonNullType <StringType> >();

            descriptor
            .Argument(t => t.PluralName)
            .Type <StringType>();
        }
Beispiel #10
0
        protected override void Configure(IDirectiveTypeDescriptor <RelationshipDirective> descriptor)
        {
            descriptor
            .Name("relationship")
            .Location(DirectiveLocation.FieldDefinition);

            descriptor
            .Argument(t => t.Name)
            .Type <NonNullType <StringType> >();

            descriptor
            .Argument(t => t.Direction)
            .Type <NonNullType <RelationshipDirectionType> >()
            .DefaultValue(RelationshipDirection.Out);
        }
        protected override void Configure(
            IDirectiveTypeDescriptor descriptor)
        {
            descriptor.Repeatable();

            descriptor.Name("complex");

            descriptor.Location(HotChocolate.Types.DirectiveLocation.Field);

            descriptor.Argument("anyArg")
            .Type <AnyType>();

            descriptor.Argument("stringArg")
            .Type <StringType>();
        }
 protected override void Configure(
     IDirectiveTypeDescriptor descriptor)
 {
     descriptor.Name("dummy_arg");
     descriptor.Argument("a").Type <StringType>();
     descriptor.Location(DirectiveLocation.Union);
 }
Beispiel #13
0
 protected override void Configure(
     IDirectiveTypeDescriptor descriptor)
 {
     descriptor.Name("appendStringMethodAsync");
     descriptor.Location(DirectiveLocation.Field);
     descriptor.Argument("s").Type <NonNullType <StringType> >();
     descriptor.Middleware <AppendDirectiveMiddleware>(
         t => t.AppendStringAsync(default, default));
        protected override void Configure(
            IDirectiveTypeDescriptor <DelegateDirective> descriptor)
        {
            descriptor.Name(DirectiveNames.Delegate);

            descriptor.Location(DirectiveLocation.FieldDefinition);

            descriptor.Argument(t => t.Path)
            .Name(DirectiveFieldNames.Delegate_Path)
            .Type <StringType>();

            descriptor.Argument(t => t.Schema)
            .Name(DirectiveFieldNames.Delegate_Schema)
            .Type <NonNullType <NameType> >()
            .Description(StitchingResources
                         .DelegateDirectiveType_Description);
        }
        protected override void Configure(IDirectiveTypeDescriptor <LanguageDirective> descriptor)
        {
            descriptor.Name("language");
            descriptor.Location(DirectiveLocation.Object);
            descriptor.Location(DirectiveLocation.Query);
            descriptor.Argument(x => x.Name);

            descriptor.Use <LanguageDirectiveMiddleware>();
        }
Beispiel #16
0
        public static IDirectiveTypeDescriptor FieldsArgument(
            this IDirectiveTypeDescriptor descriptor)
        {
            descriptor
            .Argument(Fields)
            .Type <NonNullType <FieldSetType> >();

            return(descriptor);
        }
        protected override void Configure(IDirectiveTypeDescriptor <OperationDirective> descriptor)
        {
            descriptor
            .Name("operation")
            .Location(DirectiveLocation.Object | DirectiveLocation.Schema);

            descriptor
            .Argument(t => t.Operations)
            .Type <ListType <NonNullType <OperationKindType> > >();
        }
 protected override void Configure(IDirectiveTypeDescriptor <RenameDirective> descriptor)
 {
     descriptor.Name("rename");
     descriptor.Argument(t => t.Name).Type <NonNullType <StringType> >();
     descriptor.Location(
         DirectiveLocation.InputFieldDefinition |
         DirectiveLocation.InputObject |
         DirectiveLocation.Enum |
         DirectiveLocation.EnumValue);
 }
Beispiel #19
0
        protected override void Configure(
            IDirectiveTypeDescriptor descriptor)
        {
            descriptor.Repeatable();

            descriptor.Name(_name);

            descriptor.Location(DirectiveLocation.Field);

            descriptor.Argument("arg")
            .Type <StringType>();
            descriptor.Argument("arg1")
            .Type <StringType>();
            descriptor.Argument("arg2")
            .Type <StringType>();
            descriptor.Argument("arg3")
            .Type <StringType>();
            descriptor.Argument("arg4")
            .Type <StringType>();
        }
 protected override void Configure(IDirectiveTypeDescriptor descriptor)
 {
     descriptor.Name("custom");
     descriptor.Location(DirectiveLocation.Field);
     descriptor.Argument("d").Type <DateTimeType>();
     descriptor.Use(next => ctx =>
     {
         ctx.Result = ctx.Directive.GetArgument <DateTime>("d")
                      .ToUniversalTime();
         return(next.Invoke(ctx));
     });
 }
Beispiel #21
0
        protected override void Configure(IDirectiveTypeDescriptor <FilterableDirective> descriptor)
        {
            descriptor
            .Name("filterable")
            .Location(DirectiveLocation.FieldDefinition |
                      DirectiveLocation.Schema |
                      DirectiveLocation.Scalar);

            descriptor
            .Argument(t => t.Operations)
            .Type <ListType <NonNullType <FilterOperationType> > >();
        }
        protected override void Configure(IDirectiveTypeDescriptor<SortableDirective> descriptor)
        {
            descriptor
                .Name("sortable")
                .Location(DirectiveLocation.FieldDefinition |
                    DirectiveLocation.Schema |
                    DirectiveLocation.Scalar);

            descriptor
                .Argument(t => t.Direction)
                .Type<SortDirectionType>();
        }
        protected override void Configure(
            IDirectiveTypeDescriptor <ComputedDirective> descriptor)
        {
            descriptor.Name(DirectiveNames.Computed);

            descriptor.Location(DirectiveLocation.FieldDefinition);

            descriptor.Argument(t => t.DependantOn)
            .Name(DirectiveFieldNames.Computed_DependantOn)
            .Type <ListType <NonNullType <NameType> > >()
            .Description(StitchingResources.ComputedDirectiveType_Description);
        }
        protected override void Configure(
            IDirectiveTypeDescriptor <DeferDirective> descriptor)
        {
            descriptor
            .Name(Names.Defer)
            .Description(TypeResources.DeferDirectiveType_Description)
            .Location(DirectiveLocation.FragmentSpread)
            .Location(DirectiveLocation.InlineFragment);

            descriptor
            .Argument(t => t.Label)
            .Name(Names.Label)
            .Description(TypeResources.DeferDirectiveType_Label_Description)
            .Type <StringType>();

            descriptor
            .Argument(t => t.If)
            .Name(Names.If)
            .Description(TypeResources.DeferDirectiveType_If_Description)
            .Type <BooleanType>();
        }
        public void MethodsAreNotAllowedAsArguments()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor <CustomDirective>();

            // act
            IDirectiveTypeDescriptor <CustomDirective> desc = descriptor;
            Action action = () => desc.Argument(t => t.Foo()).Ignore();

            // assert
            Assert.Throws <ArgumentException>(action);
        }
Beispiel #26
0
 protected override void Configure(
     IDirectiveTypeDescriptor descriptor)
 {
     descriptor.Name("appendString");
     descriptor.Location(DirectiveLocation.Field);
     descriptor.Argument("s").Type <NonNullType <StringType> >();
     descriptor.Middleware(next => context =>
     {
         context.Result = context.Result +
                          context.Directive.GetArgument <string>("s");
         return(next.Invoke(context));
     });
 }
Beispiel #27
0
        private static void DeclareArguments(
            IDirectiveTypeDescriptor typeDescriptor,
            DirectiveDefinitionNode node)
        {
            foreach (InputValueDefinitionNode inputField in node.Arguments)
            {
                IDirectiveArgumentDescriptor descriptor = typeDescriptor
                                                          .Argument(inputField.Name.Value)
                                                          .Description(inputField.Description?.Value)
                                                          .Type(inputField.Type)
                                                          .SyntaxNode(inputField);

                if (inputField.DefaultValue is { })
Beispiel #28
0
    protected override void Configure(IDirectiveTypeDescriptor descriptor)
    {
        descriptor
        .Name(WellKnownDirectives.Skip)
        .Description(TypeResources.SkipDirectiveType_TypeDescription)
        .Location(DirectiveLocation.Field)
        .Location(DirectiveLocation.FragmentSpread)
        .Location(DirectiveLocation.InlineFragment);

        descriptor
        .Argument(WellKnownDirectives.IfArgument)
        .Description(TypeResources.SkipDirectiveType_IfDescription)
        .Type <NonNullType <BooleanType> >();
    }
Beispiel #29
0
        protected override void Configure(
            IDirectiveTypeDescriptor <SpecifiedByDirective> descriptor)
        {
            descriptor
            .Name(Names.SpecifiedBy)
            .Description(TypeResources.SpecifiedByDirectiveType_TypeDescription)
            .Location(DirectiveLocation.Scalar);

            descriptor
            .Argument(t => t.Url)
            .Name(Names.Url)
            .Description(TypeResources.SpecifiedByDirectiveType_UrlDescription)
            .Type <NonNullType <StringType> >();
        }
        protected override void Configure(
            IDirectiveTypeDescriptor <ExportDirective> descriptor)
        {
            descriptor.Name(ExportDirectiveHelper.Name);
            descriptor.Location(DirectiveLocation.Field);

            descriptor.Argument(t => t.As).Type <StringType>();

            descriptor.Use(next => async context =>
            {
                await next(context).ConfigureAwait(false);
                context.ExportValueAsVariable();
            });
        }