Exemplo n.º 1
0
        /// <summary>
        /// Instantiates the graph field according to the data provided.
        /// </summary>
        /// <param name="formatter">The formatter.</param>
        /// <param name="template">The template.</param>
        /// <param name="securityGroups">The security groups.</param>
        /// <returns>MethodGraphField.</returns>
        protected virtual MethodGraphField InstantiateField(
            GraphNameFormatter formatter,
            IGraphTypeFieldTemplate template,
            List <FieldSecurityGroup> securityGroups)
        {
            switch (template.FieldSource)
            {
            case GraphFieldTemplateSource.Method:
            case GraphFieldTemplateSource.Action:
                return(new MethodGraphField(
                           formatter.FormatFieldName(template.Name),
                           template.TypeExpression.CloneTo(formatter.FormatGraphTypeName(template.TypeExpression.TypeName)),
                           template.Route,
                           template.Mode,
                           template.CreateResolver(),
                           securityGroups));

            case GraphFieldTemplateSource.Property:
                return(new PropertyGraphField(
                           formatter.FormatFieldName(template.Name),
                           template.TypeExpression.CloneTo(formatter.FormatGraphTypeName(template.TypeExpression.TypeName)),
                           template.Route,
                           template.DeclaredReturnType,
                           template.DeclaredName,
                           template.Mode,
                           template.CreateResolver(),
                           securityGroups));

            default:
                throw new ArgumentOutOfRangeException($"Template field source of {template.FieldSource.ToString()} is not supported by {this.GetType().FriendlyName()}.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultResponseWriter{TSchema}" /> class.
        /// </summary>
        /// <param name="schema">The schema from which repsonse settings should be drawn.</param>
        public DefaultResponseWriter(TSchema schema)
        {
            Validation.ThrowIfNull(schema, nameof(schema));
            _minSeverityLevel = schema.Configuration.ResponseOptions.MessageSeverityLevel;
            _timeLocalizer    = schema.Configuration.ResponseOptions.TimeStampLocalizer;
            _nameFormatter    = schema.Configuration.DeclarationOptions.GraphNamingFormatter;
            _writerOptions    = new JsonWriterOptions()
            {
                Indented = schema.Configuration.ResponseOptions.IndentDocument,
            };

            _serializerSettings         = new JsonSerializerOptions();
            _serializerSettings.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
        }
        /// <summary>
        /// Instantiates the graph field according to the data provided.
        /// </summary>
        /// <param name="formatter">The formatter.</param>
        /// <param name="template">The template.</param>
        /// <param name="securityGroups">The security groups.</param>
        /// <returns>MethodGraphField.</returns>
        protected override MethodGraphField InstantiateField(
            GraphNameFormatter formatter,
            IGraphTypeFieldTemplate template,
            List <FieldSecurityGroup> securityGroups)
        {
            var subTemplate = template as ControllerSubscriptionActionGraphFieldTemplate;

            if (subTemplate != null &&
                subTemplate.FieldSource == GraphFieldTemplateSource.Action &&
                subTemplate.Route.RootCollection == GraphCollection.Subscription)
            {
                return(new SubscriptionMethodGraphField(
                           formatter.FormatFieldName(template.Name),
                           template.TypeExpression.CloneTo(formatter.FormatGraphTypeName(template.TypeExpression.TypeName)),
                           template.Route,
                           template.Mode,
                           template.CreateResolver(),
                           securityGroups,
                           subTemplate.EventName));
            }

            return(base.InstantiateField(formatter, template, securityGroups));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphSchemaManager" /> class.
 /// </summary>
 /// <param name="schema">The schema.</param>
 public GraphSchemaManager(ISchema schema)
 {
     this.Schema = Validation.ThrowIfNullOrReturn(schema, nameof(schema));
     _formatter  = this.Schema.Configuration.DeclarationOptions.GraphNamingFormatter;
     this.EnsureGraphOperationType(GraphCollection.Query);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphQLJsonEnumNamingPolicy"/> class.
 /// </summary>
 /// <param name="namingFormatter">The naming formatter.</param>
 public GraphQLJsonEnumNamingPolicy(GraphNameFormatter namingFormatter)
 {
     _namingFormatter = Validation.ThrowIfNullOrReturn(namingFormatter, nameof(namingFormatter));
 }