public static ISchemaBuilder BindEnumType(
            this ISchemaBuilder builder,
            Type runtimeType,
            Action <IEnumTypeBindingDescriptor>?configure = default)
        {
            configure ??= _ => { };

            return(builder
                   .SetContextData(
                       SchemaFirstContextData.EnumTypeConfigs,
                       o =>
            {
                if (o is List <EnumTypeBindingConfiguration> configs)
                {
                    configs.Add(new EnumTypeBindingConfiguration(runtimeType, configure));
                    return o;
                }

                return new List <EnumTypeBindingConfiguration>
                {
                    new EnumTypeBindingConfiguration(runtimeType, configure)
                };
            })
                   .TryAddTypeInterceptor <SchemaFirstTypeInterceptor>()
                   .TryAddSchemaInterceptor <SchemaFirstSchemaInterceptor>());
        }
        /// <summary>
        /// Enables relay schema style.
        /// </summary>
        public static ISchemaBuilder EnableRelaySupport(
            this ISchemaBuilder schemaBuilder,
            RelayOptions options = null)
        {
            options ??= new();

            if (options.AddQueryFieldToMutationPayloads)
            {
                schemaBuilder.TryAddTypeInterceptor <QueryFieldTypeInterceptor>();
            }

            return(schemaBuilder
                   .SetContextData(IsRelaySupportEnabled, 1)
                   .SetRelayOptions(options)
                   .TryAddTypeInterceptor <NodeFieldTypeInterceptor>()
                   .AddType <NodeType>());
        }
Пример #3
0
        public static ISchemaBuilder AddRemoteExecutor(
            this ISchemaBuilder schemaBuilder,
            NameString schemaName,
            IRequestExecutor executor)
        {
            return(schemaBuilder
                   .SetContextData(
                       RemoteExecutors,
                       current =>
            {
                if (!(current is OrderedDictionary <NameString, IRequestExecutor> dict))
                {
                    dict = new OrderedDictionary <NameString, IRequestExecutor>();
                }

                dict[schemaName] = executor;
                return dict;
            }));
    public static ISchemaBuilder EnableRelaySupport(
        this ISchemaBuilder schemaBuilder,
        RelayOptions?options = null)
    {
        options ??= new();

        if (options.AddQueryFieldToMutationPayloads)
        {
            MutationPayloadOptions payloadOptions = new()
            {
                QueryFieldName           = options.QueryFieldName,
                MutationPayloadPredicate = options.MutationPayloadPredicate
            };

            schemaBuilder.AddQueryFieldToMutationPayloads(payloadOptions);
        }

        return(schemaBuilder
               .SetContextData(IsRelaySupportEnabled, 1)
               .AddGlobalObjectIdentification());
    }
 /// <summary>
 /// Enables relay schema style.
 /// </summary>
 public static ISchemaBuilder EnableRelaySupport(
     this ISchemaBuilder schemaBuilder) =>
 schemaBuilder
 .SetContextData(RelayConstants.IsRelaySupportEnabled, 1)
 .TryAddTypeInterceptor <NodeFieldTypeInterceptor>()
 .AddType <NodeType>();
 /// <summary>
 /// Defines the common interface that all errors implement.
 /// To specify the interface you can either provide a interface runtime type or a HotChocolate
 /// interface schema type.
 ///
 /// This has to be used together with <see cref="ErrorAttribute"/>  or
 /// <see cref="ErrorObjectFieldDescriptorExtensions.Error"/>
 /// </summary>
 /// <param name="schemaBuilder">
 /// The schema builder
 /// </param>
 /// <param name="type">
 /// The type that is used as the common interface
 /// </param>
 /// <returns>
 /// The schema builder
 /// </returns>
 public static ISchemaBuilder AddErrorInterfaceType(
     this ISchemaBuilder schemaBuilder,
     Type type) =>
 schemaBuilder.SetContextData(ErrorContextData.ErrorType, type);